from sklearn import linear_model
regr = linear_model.LinearRegression()
regr.fit(X, y)
p = regr.predict(X)
c = regr.intercept_
b = regr.coef_
Logistic Regression
LR
from sklearn.linear_model import LogisticRegression as LR
model = LR()
model.fit(X,y)
model.predict(X)
model.predict_proba(X)
select factor
from sklearn.linear_model import RandomizedLogisticRegression as RLR
rlr.fit(X, y)
rlr.get_support()
#[False, True, False]
rlr.scores_
example
from sklearn.linear_model import RandomizedLogisticRegression as RLR
from sklearn.linear_model import LogisticRegression as LR
from sklearn.cross_validation import train_test_split
X = user_od.iloc[:,1:5]
y = user_od.tag
x_train, x_test, y_train, y_test = train_test_split(X, y)
#select factor
rlr = RLR()
rlr.fit(X, y)
#which column is factors
rlr.get_support()
rlr.scores_
#use factors to regression
print('the factor of user_info is ',x_train.columns[rlr.get_support()])
A = x_train.loc[:,x_train.columns[rlr.get_support()]]
B = x_test.loc[:,x_test.columns[rlr.get_support()]]
lr = LR()
lr.fit(A, y_train)
lr.score(B, y_test)
#get probabilities
p = lr.predict_proba(B)[:,0]