问题
原代码
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(x_train, y_train)
pre_test = lr.predict(x_test)
pre_test = lr.predict(x_train)
报错
ValueError: Found input variables with inconsistent numbers of samples: [404, 102]
值错误:发现输入参数变量与样本数不一致: [404, 102]。
输出参数变量的形状查看
发现的确不一致,找问题的根源!
原代码
x_train, y_train, x_test, y_test = train_test_split(x, y, random_state = 33, test_size = 0.2)
改为
x_train, x_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)
成功!!哦耶!!