此RandomForestClassifier实例尚未拟合。调用fit'在使用此估算器之前,请有适当的论点
我有我的编码行,例如:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LogisticRegress
以及RandomForestClassifier
是类,LR_Classifier和RF_Classifier是这些类的对象。您需要以与对象SC相似的方式调用拟合方法,例如
lr_classifier.fit(x_train_std,y_train)
,而不仅仅是fit
。我建议阅读sklearn 入门指南以更好地了解如何使用库。
LogisticRegression
as well asRandomForestClassifier
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 justfit
.I would recommend reading the sklearn Getting Started guide to better understand how to use the library.