【发布时间】:2018-02-15 06:09:56
【问题描述】:
我正在尝试对训练数据进行预处理,我也尝试了 rehsape 函数,但没有成功,我收到以下错误:
ValueError: Found input variables with inconsistent numbers of samples: [34, 12700]
这是我的代码:
import pandas as pd
import numpy as np
from sklearn import preprocessing,neighbors
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
df=pd.read_csv('train.csv')
df.drop(['ID'],1,inplace=True)
X=np.array(df.drop(['label'],1))
y=np.array(df['label'])
print(X.shape)
X = preprocessing.StandardScaler().fit(X)
X=X.mean_
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
clf = RandomForestRegressor(n_estimators=1900,max_features='log2',max_depth=25)
clf.fit(X_train,y_train)
accuracy=clf.score(X_test,y_test)
print(accuracy)
【问题讨论】:
-
X.shape和 `y.shape' 的输出是什么? -
train_test_split 或 clf.fit() 期间是否抛出此错误?
-
@VivekKumar 错误发生在 clf.fit() 期间
-
@AkshayNevrekar (12700,34)
-
请查看@AkshayNevrekar 的答案。他正确地指出了错误。
标签: python-3.x numpy machine-learning scikit-learn