首页 > 学院 > 开发设计 > 正文

Regression

2019-11-11 05:22:53
字体:
来源:转载
供稿:网友

Linear Regression

from sklearn import linear_modelregr = 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 LRmodel = LR()model.fit(X,y)model.predict(X)model.predict_proba(X)

select factor

from sklearn.linear_model import RandomizedLogisticRegression as RLRrlr.fit(X, y)rlr.get_support()#[False, True, False]rlr.scores_

example

from sklearn.linear_model import RandomizedLogisticRegression as RLRfrom sklearn.linear_model import LogisticRegression as LRfrom sklearn.cross_validation import train_test_splitX = user_od.iloc[:,1:5]y = user_od.tagx_train, x_test, y_train, y_test = train_test_split(X, y)#select factorrlr = RLR()rlr.fit(X, y)#which column is factorsrlr.get_support()rlr.scores_#use factors to regressionprint('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 probabilitiesp = lr.predict_proba(B)[:,0]
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表