节目:
import pandas as pd
ds=pd.read_csv('Animals.csv')
x=ds.iloc[:,1].values
y=ds.iloc[:,2].values
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)
x_train = x_train.reshape(-1, 1)
y_train = y_train.reshape(-1,1)
from sklearn.linear_model import LinearRegression as lr
reg=lr()
reg.fit(x_train,y_train)
y_pred=reg.predict(x_test)y_pred = array([[433.34494686],
[433.20384407],
[418.6791427 ],
[433.34789435],
[407.49640802],
[432.25311216]])
y_test = array([[ 119.5],
[ 157. ],
[5712. ],
[ 56. ],
[ 50. ],
[ 680. ]])为什么预言不完美?数据集有什么问题吗?我是新来的机器学习,谢谢
发布于 2018-11-23 16:33:26
这真的取决于你想要预测什么,以及你所拥有的特征是否是很好的预测指标。因此,即使您只是在尝试一个LR,如果您的目标变量可以通过这些特性来解释,那么您应该得到一些合理的精度度量。
查看您的y_test,您应该考虑删除异常值,这可能会提高模型的准确性。
您还可能希望尝试一些更有效的回归器,例如RandomForestRegressor或SupportVectorRegressor。
https://stackoverflow.com/questions/53449468
复制相似问题