gpt4 book ai didi

python - 属性错误 : 'RandomForestClassifier' object has no attribute 'fit_transform'

转载 作者:行者123 更新时间:2023-12-03 18:58:35 26 4
gpt4 key购买 nike

我遇到了一个错误

AttributeError: 'RandomForestClassifier' object has no attribute 'fit_transform'

但是,sklearn.ensemble.RandomForestClassifier 中有一个名为 fit_transform(X,y) 的方法。 This can be seen here我不明白为什么会收到此错误以及如何解决它。这是代码片段-

from sklearn.ensemble import RandomForestClassifier
import pickle
import sys
import numpy as np

X1=np.array(pickle.load(open('X2g_train.p','rb')))
X2=np.array(pickle.load(open('X3g_train.p','rb')))
X3=np.array(pickle.load(open('X4g_train.p','rb')))
X4=np.array(pickle.load(open('Xhead_train.p','rb')))

X=np.hstack((X2,X1,X3,X4))
y = np.array(pickle.load(open('y.p','rb')))
rf=RandomForestClassifier(n_estimators=200)
Xr=rf.fit_transform(X,y)

最佳答案

scikit-learn API documentation 中没有这样的方法

要训练您的模型并获得预测,您需要这样做

rf = RandomForestClassifier()

# train the model
rf.fit(X_train, y_train)

# get predictions
predictions = rf.predict(X_test)

关于python - 属性错误 : 'RandomForestClassifier' object has no attribute 'fit_transform' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49400413/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com