Regression

Linear Regression

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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值