Getting the ValueError: Found input variables with inconsistent numbers of samples: [248, 1239] while trying to run Adjt. R Squared and RMSE
Getting the ValueError: Found input variables with inconsistent numbers of samples: [248, 1239] while trying to run Adjt. R Squared and RMSE
我是数据科学和随机森林的新手,当然,我一直在尝试寻找 Adjusted R squared 和 RMSE 在 (1239, 29) 的数据集上应用随机森林之后。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error, mean_squared_log_error, mean_absolute_error
from sklearn.model_selection import train_test_split
X = df.loc[:, df.columns != 'PRODUCTMONTHLYREVENUE_LINE']
y = df.loc[:,['PRODUCTMONTHLYREVENUE_LINE']].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1)
我在对数据集应用随机森林之前应用了测试训练。
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import roc_auc_score
model = RandomForestRegressor(oob_score=True)
model.fit(X_train, y_train)
y_predict=model.predict(X_test)
现在,当我尝试 运行 RMSE 时,我遇到了在 OLS 模型中没有遇到的错误。
RMSE= np.sqrt(mean_squared_error(y_predict,y))
RMSE
出现以下错误
ValueError Traceback(最后一次调用)
在 ()
----> 1 RMSE= np.sqrt(mean_squared_error(y_predict,y))
2 均方根误差
2帧
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py 在 check_consistent_length(*arrays)
210 如果 len(uniques) > 1:
211 raise ValueError("发现输入变量的数量不一致"
--> 212 " samples: %r" % [int(l) for l in lengths])
213
214
ValueError:发现样本数量不一致的输入变量:[248, 1239]
您需要使用以下命令:
RMSE= np.sqrt(mean_squared_error(y_predict,y_test))
RMSE
y
变量是指整个标签数据。您以 20% 的比率拆分,您应该使用该测试数据。不是整个测试数据标签
我是数据科学和随机森林的新手,当然,我一直在尝试寻找 Adjusted R squared 和 RMSE 在 (1239, 29) 的数据集上应用随机森林之后。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error, mean_squared_log_error, mean_absolute_error
from sklearn.model_selection import train_test_split
X = df.loc[:, df.columns != 'PRODUCTMONTHLYREVENUE_LINE']
y = df.loc[:,['PRODUCTMONTHLYREVENUE_LINE']].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1)
我在对数据集应用随机森林之前应用了测试训练。
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import roc_auc_score
model = RandomForestRegressor(oob_score=True)
model.fit(X_train, y_train)
y_predict=model.predict(X_test)
现在,当我尝试 运行 RMSE 时,我遇到了在 OLS 模型中没有遇到的错误。
RMSE= np.sqrt(mean_squared_error(y_predict,y))
RMSE
出现以下错误 ValueError Traceback(最后一次调用) 在 () ----> 1 RMSE= np.sqrt(mean_squared_error(y_predict,y)) 2 均方根误差
2帧 /usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py 在 check_consistent_length(*arrays) 210 如果 len(uniques) > 1: 211 raise ValueError("发现输入变量的数量不一致" --> 212 " samples: %r" % [int(l) for l in lengths]) 213 214
ValueError:发现样本数量不一致的输入变量:[248, 1239]
您需要使用以下命令:
RMSE= np.sqrt(mean_squared_error(y_predict,y_test))
RMSE
y
变量是指整个标签数据。您以 20% 的比率拆分,您应该使用该测试数据。不是整个测试数据标签