用到的sklearn代码集锦:
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(ages_train , net_worths_train)
#这里的predict中27的状态需要看测试特征是几维的,比方说这里的作业是二维的
#就应该是reg.predict([[27]]),这里也可以用预测的特征来代替。
print "Katie's net worth prediction: ", reg.predict([27])
print "slope:", reg.coef_
print "intercept:", reg.intercept_
print "\n ############ stats on test dataset ############\n"
print "r-squared score:", reg.score(ages_test, net_worths_test)
print "\n ############ stats on training dataset ############\n"
print "r-squared score:", reg.score(ages_train, net_worths_train)