我想预测一家餐厅的销售情况,并习惯于以下代码:
my_model = str('sales + competition + population + income')
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
my_model_fit = smf.OLS(y_train, X_train)
df['predict_sales'] = results.fittedvalues
print('\nProportion of Test Set Variance Accounted for: ',\
round(np.power(df['sales'].corr(df['predict_sales']), 2), 3))
sites_data = {'sales': [0,0,0],
'competition': [2, 3, 5],
'population': [50000, 200000, 220000],
'income': [25000, 220000, 190000]}
sites = pd.DataFrame(sites_data)
sites['sales_pred'] = results.predict(sites)
print('\nNew sites with predicted sales', sites, '\n')
但是在最后一个代码之后,我收到了一个错误:
ValueError: shapes (3,4) and (3,) not aligned: 4 (dim 1) != 3 (dim 0)
有人可以帮忙吗?我现在真的很绝望。