线性回归

时间:2018-11-23 15:38:46

标签: python pandas machine-learning

程序:

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. ]])

为什么预测不完美? 数据集有什么问题吗? 我是机器学习的新手 预先感谢

1 个答案:

答案 0 :(得分:1)

嗯,这实际上取决于您要预测的内容以及您所拥有的功能是否是好的预测指标。因此,即使您只是尝试使用LR,如果目标变量可由功能解释,您也应该获得一些合理的准确性指标。

查看您的y_test,您应该考虑删除异常值,这可能会提高模型的准确性。

您可能还想尝试一些更高效的回归变量,例如RandomForestRegressorSupportVectorRegressor