Reputation: 61
I am trying to construct a stacking classifier for predicting each class, at the same time I need the probability for each elemnt to be in the predicted class. I tried using the predict_proba() method but I seem to run to the same error "'StackingClassifier' object has no attribute 'pedict_proba'". Please help!
hgbm = HistGradientBoostingClassifier(l2_regularization=3, learning_rate=0.5, random_state=42, class_weight="balanced")
bbc = BalancedBaggingClassifier(
estimator = hgbm,
n_estimators = 10,
random_state = 42,
n_jobs = -1,
)
brf = BalancedRandomForestClassifier(n_estimators = 200, random_state = 42, n_jobs = -1)
CLF = RidgeClassifier(random_state = 42, alpha = 0.8, max_iter = 200, class_weight = 'balanced')
Class_st = StackingClassifier(estimators=[("BalancedBaggingClassifier", bbc),
("BalancedRandomForestClassifier", brf)],
final_estimator = CLF, stack_method='predict_proba', cv = 5, n_jobs = -1)
Class_st.fit(X_train, y_train)
prob = Class_st.pedict_proba(X_test)
The error:
'StackingClassifier' object has no attribute 'pedict_proba'
Upvotes: 1
Views: 469
Reputation: 4658
There is a typo in your code you have predict_proba()
, but you typed pedict_proba()
. so this should be prob = Class_st.predict_proba(X_test)
Also RidgeClassifier
used as your final estimator does not have the predict_proba()
method by default
Use it like this instead:
from sklearn.linear_model import RidgeClassifierCV
CLF = RidgeClassifierCV(cv=5, alphas=[0.8], class_weight='balanced')
Upvotes: 1