In [1]: from sklearn.datasets import load_boston
...: from sklearn import linear_model
...: from sklearn.cross_validation import train_test_split
...: from string import ascii_uppercase
...: import warnings
...: warnings.filterwarnings('ignore')
...: L = list(filter(lambda x: x.startswith(tuple(ascii_uppercase)), dir(linear_model)))
In [2]: boston = load_boston()
In [3]: x2, y2 = boston.data, boston.target
In [4]: xTrain, yTrain, xtest, ytest = train_test_split(x2, y2)
In [5]: for model in L:
...: try:
...: model2 = getattr(linear_model, model)()
...: model2.fit(xTrain, xtest)
...: print ('{:>30} : score : {:<20}'.format(model, model2.score(yTrain, ytest)))
...: except:pass
...:
ARDRegression : score : 0.7088646320904151
BayesianRidge : score : 0.7045141566856377
ElasticNet : score : 0.6603516140711009
ElasticNetCV : score : 0.6465871598904319
HuberRegressor : score : 0.5565922777934672
Lars : score : 0.7080364004790854
LarsCV : score : 0.7045934873727482
Lasso : score : 0.6573343838206422
LassoCV : score : 0.6772188189534654
LassoLars : score : -0.000989139814329132
LassoLarsCV : score : 0.7230538108571827
LassoLarsIC : score : 0.7119005222385881
LinearRegression : score : 0.7089655189671733
OrthogonalMatchingPursuit : score : 0.504333961343415
OrthogonalMatchingPursuitCV : score : 0.6890447027265303
PassiveAggressiveRegressor : score : 0.20510044622867962
RANSACRegressor : score : 0.6737791511350468
Ridge : score : 0.712458967028207
RidgeCV : score : 0.7101637255944955
SGDRegressor : score : -5.380985022454105e+25
TheilSenRegressor : score : 0.6965646966699823
scikit-learn 线性回归算法库小结
最新推荐文章于 2024-07-24 22:53:22 发布