#建模预测
x=data4.iloc[:,2].values.astype(float)
y=data4.iloc[:,3:6].values.astype(float)
from sklearn import model_selection
x_train,x_test,y_train,y_test=model_selection.train_test_split(x,y,test_size=0.35,random_state=1)
x_train=np.array(x).reshape(-1,1)
x_test=np.array(x_train).reshape(-1,1)
y_train=np.array(x).reshape(-1,1)
from sklearn.linear_model import LinearRegression
linregTr=LinearRegression()
linregTr.fit(x_train,y_train)
print('线性回归模型的回归系数:',linregTr.coef_)
print('线性回归模型的截距:',linregTr.intercept_)
from sklearn import metrics
y_train_pred=linregTr.predict(x_train)
y_test_pred=linregTr.predict(x_test)
train_err=metrics.mean_squared_error(y_train,y_train_pred)
test_err=metrics.mean_squared_error(y_test,y_test_pred)
print('在训练集上的均方根误差是:',train_err)
print('在测试集上的均方根误差是:',test_err)
到这里之后就显示错误
ValueError: Found input variables with inconsistent numbers of samples: [119, 338]
网络上找出来的那个问题都是没有分割训练集,但我这个也分割了,也不知道为什么有问题