pyton(随机森林分类器)

问题描述 投票:0回答:1

如何coplite代码? 创建“随机森林分类器”

    r_forest = RandomForestClassifier(n_estimators = 45,
    max_depth = 8,
    min_samples_leaf = 30,
    max_features = 30)

创建“AUC-ROC”

    r_forest_f = r_forest.fit
    y_pred_proba = r_forest_f.predict_proba (r_forest)[:,1]  //ERROR
    fpr, tpr, treshold = metrics. roc_curve (y_train, y_pred_proba)
    auc = metrics. roc_auc_score (y_train, y_pred_proba)
    plt.plot (fpr,tpr,label="name mofel= "+str(auc))

我们需要建立一个时间表AUC-ROC,但它给出了这样的错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-82-15f0a74b94a3> in <cell line: 2>()
      1 r_forest_f = r_forest.fit
----> 2 y_pred_proba = r_forest_f.predict(r_forest)[:,1]
      3 fpr, tpr, treshold = metrics. roc_curve (y_train, y_pred_proba)
      4 auc = metrics. roc_auc_score (y_train, y_pred_proba)
      5 plt.plot (fpr,tpr,label=" название модели= "+str(auc))

AttributeError: 'function' object has no attribute 'predict'
python random-forest
1个回答
0
投票

问题出自这一行:

r_forest_f = r_forest.fit

您正在将

fit
RandomForestClassifier
方法分配给
r_forest_f
。纠正一下:

r_forest_f = r_forest.fit(X, y)

其中

X
y
是您的训练数据。

查看文档了解更多

© www.soinside.com 2019 - 2024. All rights reserved.