【问题标题】:AttributeError: 'RandomForestClassifier' object has no attribute 'fit_transform'AttributeError:“RandomForestClassifier”对象没有属性“fit_transform”
【发布时间】:2018-08-30 05:21:54
【问题描述】:

我遇到了一个错误

AttributeError: 'RandomForestClassifier' 对象没有属性 'fit_transform'

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

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。好像你没有安装那个版本。

标签: python scikit-learn random-forest


【解决方案1】:

scikit-learn API documentation

中没有这样的方法

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

rf = RandomForestClassifier()

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

# get predictions
predictions = rf.predict(X_test)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2021-04-19
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多