【发布时间】:2021-04-04 01:19:33
【问题描述】:
我遇到了一个非常奇怪的问题。下面,我展示我的代码。
代码:
#The df here is a data with 208 samples, 60 feature(0-59th) The 60th column is the label "R" OR "M" which I m turning it to 1 and 0.
df[60] = [1 if x == 'R' else 0 for x in df[60]]
X = df.loc[:,[x for x in range(60)]]
y = df[60]
print(X.shape) #(208, 60)
print(y.shape) #(208,)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=123)
#.... this is where causes the error message. Where I have to calculate the r2 score after using linear regression.
print(r2_score(y_test,acc))
#....
Error message:
ValueError: Found input variables with inconsistent numbers of samples: [42, 60]
*********************
print(y_test.shape) #### (42,)
print(acc.shape) #### (60,60) -> this is the predicted after running linear regression on the data.
有人可以帮我吗?非常感谢。
【问题讨论】:
-
acc不能是多维数组。它必须是形状为(42,)的一维。你能发布你的适合和预测代码吗?
标签: python scikit-learn linear-regression valueerror