简体   繁体   English

线性回归拟合

[英]Linear Regression fitting

I have first done a train/test split then fitted that data to a LinearRegression model shown below我首先进行了训练/测试拆分,然后将该数据拟合到如下所示的 LinearRegression model

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.4, random_state = 101)

Log_m = LinearRegression()

Log_m.fit(X_train,y_train)

predictions = Log_m.predict(X_test)

I have been given another test data frame and wanted to fit that to the Log_m model which has been created.我已经获得了另一个测试数据框,并希望将其与已创建的 Log_m model 相匹配。 So I did所以我做了

predictions_t = Log_m.predict(fin_df1_t)

But I get the error message:但我收到错误消息:

ValueError: shapes (1450,262) and (282,) not aligned: 262 (dim 1) != 282 (dim 0)

These are the shapes of dataframes这些是数据框的形状

fin_df1_t (1450,262)

X_test (556,282)

X_train (834,282)

y_test (556,)

y_train (834,)

The feature columns of new test data (262) are not equal to feature columns of Xtrain and Xtest (282), so it will always give an error.新测试数据的特征列(262)不等于Xtrain和Xtest的特征列(282),所以总会报错。 Both should have the same feature columns.两者都应该具有相同的特征列。 For example, Xtrain and Xtest have the same columns (282), so there is no error at that step.例如,Xtrain 和 Xtest 具有相同的列 (282),因此该步骤没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM