error on preprocessing machine learning

我在尝试对训练数据进行预处理,并且还尝试了reshape函数,但那没有奏效,我得到了以下错误:

ValueError: Found input variables with inconsistent numbers of samples: [34, 12700]

这是我的代码:

import pandas as pdimport numpy as npfrom sklearn import preprocessing,neighborsfrom sklearn.model_selection import train_test_splitfrom sklearn.ensemble import RandomForestRegressordf=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 = preprocessing.StandardScaler().fit(X)X=X.mean_

在这之后,你的X将只包含每列的均值。

要转换数据,请使用以下代码:

from sklearn.preprocessing import StandardScalerscaler = StandardScaler()scaler.fit(X)X = scaler.transform(X)

更多详情请参考 scikit-doc

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注