此RandomForestClassifier实例尚未拟合。调用fit'在使用此估算器之前,请有适当的论点

发布于 2025-02-11 03:33:02 字数 1181 浏览 5 评论 0原文

我有我的编码行,例如:

import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import accuracy_score
from sklearn.metrics import roc_curve, roc_auc_score

X = dataset_df
Y = dataset_df

'X_train, X_test, y_train, y_test\
= train_test_split(X, y, test_size = 0.3, random_state=1)'

X_train, X_validation, y_train, y_validation\
= train_test_split(X_train, y_train, test_size = 0.3, random_state=1)

sc = StandardScaler()
sc.fit(X_train)
X_train_Std = sc.transform(X_train)

lr_classifier = LogisticRegression(C = 1000, random_state= 1)
rf_classifier = RandomForestClassifier(max_depth=5, random_state= 1)
from sklearn.ensemble import RandomForestClassifier
fit 

rf_classifier.predict_proba(sc.transform(X_validation))

,在那里,我会出现一个错误,说RandomforestClassifier不合适。此RandomForestClassifier实例尚未拟合。在使用此估计器之前,请使用适当的参数调用“适合”。 有人会知道如何帮助我吗?

I have my coding lines such as :

import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import accuracy_score
from sklearn.metrics import roc_curve, roc_auc_score

X = dataset_df
Y = dataset_df

'X_train, X_test, y_train, y_test\
= train_test_split(X, y, test_size = 0.3, random_state=1)'

X_train, X_validation, y_train, y_validation\
= train_test_split(X_train, y_train, test_size = 0.3, random_state=1)

sc = StandardScaler()
sc.fit(X_train)
X_train_Std = sc.transform(X_train)

lr_classifier = LogisticRegression(C = 1000, random_state= 1)
rf_classifier = RandomForestClassifier(max_depth=5, random_state= 1)
from sklearn.ensemble import RandomForestClassifier
fit 

rf_classifier.predict_proba(sc.transform(X_validation))

And there, I get an error saying that the RandomForestClassifier isn't fitted. This RandomForestClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
Would someone know how to help me on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫弦 2025-02-18 03:33:03

LogisticRegress以及RandomForestClassifier是类,LR_Classifier和RF_Classifier是这些类的对象。

您需要以与对象SC相似的方式调用拟合方法,例如lr_classifier.fit(x_train_std,y_train),而不仅仅是fit

我建议阅读sklearn 入门指南以更好地了解如何使用库。

LogisticRegression as well as RandomForestClassifier are both classes and lr_classifier and rf_classifier are objects of the these classes.

You need to call the fit method in a similar way as you did with the object sc, something like lr_classifier.fit(X_train_Std, y_train) and not just fit.

I would recommend reading the sklearn Getting Started guide to better understand how to use the library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文