将缩放器,PCA和随机森林管道应用于3D阵列
我有一个用于x_train和x_test的3D数组。是否可以使用sualer
,pca
和随机森林
管道到3D数组?但是,我尝试使用以下代码,但是,我会收到错误:
valueerror:dim 3。标准标准预期< = 2。
,
如果可能,我如何正确使用下面的管道来正确地使用下面的管道3D阵列?
这是我的代码:
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
pipe = Pipeline([('scaler', StandardScaler()),
('pca', PCA(n_components=15)),
('clf', RandomForestClassifier())])
# Declare a hyperparameter grid
parameter_space = {
'clf__n_estimators': [10,50,100],
'clf__criterion': ['gini', 'entropy'],
'clf__max_depth': np.linspace(10,50,11),
}
clf = GridSearchCV(pipe, parameter_space, cv = 5, scoring = "accuracy", verbose = True) # model
pipe.fit(X_train,y_train)
I have a 3D array for X_train and X_test. Is it possible to use a scaler
, PCA
and Random Forest
pipeline to the 3D array? I tried using the code below, however, I get the error:
ValueError: Found array with dim 3. StandardScaler expected <= 2.
If possible, how do I go about correctly using the pipeline below for the 3D array?
Here is my code:
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
pipe = Pipeline([('scaler', StandardScaler()),
('pca', PCA(n_components=15)),
('clf', RandomForestClassifier())])
# Declare a hyperparameter grid
parameter_space = {
'clf__n_estimators': [10,50,100],
'clf__criterion': ['gini', 'entropy'],
'clf__max_depth': np.linspace(10,50,11),
}
clf = GridSearchCV(pipe, parameter_space, cv = 5, scoring = "accuracy", verbose = True) # model
pipe.fit(X_train,y_train)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论