Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

estimator compatibility issues with sklearn #324

Open
NeroHin opened this issue Apr 5, 2023 · 2 comments · May be fixed by #325
Open

estimator compatibility issues with sklearn #324

NeroHin opened this issue Apr 5, 2023 · 2 comments · May be fixed by #325

Comments

@NeroHin
Copy link

NeroHin commented Apr 5, 2023

Hello, I've used the NGboost with sklearn ensemble voting to be a base estimator,
But it's showing ValueError: The estimator NGBClassifier should be a classifier..

At the same time, I used Xgboost and LightGBM to be the base estimators.

When I checked their type of class and saw the API name are <class 'xgboost.sklearn.XGBClassifier'> and <class 'lightgbm.sklearn.LGBMClassifier'>

But NGboost show <class 'ngboost.api.NGBClassifier'>. Could anyone modify the API class with compatibility with the sklearn estimator and test it?

The test code is:

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
import lightgbm as lgb
from ngboost import NGBClassifier

from sklearn.metrics import accuracy_score
from sklearn.ensemble import VotingClassifier


X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)


xgb = XGBClassifier()
lgb = lgb.LGBMClassifier()
ngb = NGBClassifier()

voting_clf = VotingClassifier(
    estimators=[('xgb', xgb), ('lgb', lgb), ('ngb', ngb)],
    voting='soft').fit(X_train, y_train)

y_pred_voting = voting_clf.predict(X_test)
print(accuracy_score(y_test, y_pred_voting))

Reference:

Thanks !

@NeroHin
Copy link
Author

NeroHin commented Apr 5, 2023

  • The same problem into sklearn ensemble stacking model, such as ValueError: 'final_estimator' parameter should be a classifier. Got NGBClassifier(random_state=RandomState(MT19937) at 0x7F007D5E8840)

@NeroHin
Copy link
Author

NeroHin commented Apr 5, 2023

Hello, I've used the NGboost with sklearn ensemble voting to be a base estimator, But it's showing ValueError: The estimator NGBClassifier should be a classifier..

At the same time, I used Xgboost and LightGBM to be the base estimators.

When I checked their type of class and saw the API name are <class 'xgboost.sklearn.XGBClassifier'> and <class 'lightgbm.sklearn.LGBMClassifier'>

But NGboost show <class 'ngboost.api.NGBClassifier'>. Could anyone modify the API class with compatibility with the sklearn estimator and test it?

The test code is:

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
import lightgbm as lgb
from ngboost import NGBClassifier

from sklearn.metrics import accuracy_score
from sklearn.ensemble import VotingClassifier


X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)


xgb = XGBClassifier()
lgb = lgb.LGBMClassifier()
ngb = NGBClassifier()

voting_clf = VotingClassifier(
    estimators=[('xgb', xgb), ('lgb', lgb), ('ngb', ngb)],
    voting='soft').fit(X_train, y_train)

y_pred_voting = voting_clf.predict(X_test)
print(accuracy_score(y_test, y_pred_voting))

Reference:

Thanks !

With Sklearn ensemble voting classifier, it can use model._estimator_type = "classifier" to fix the type error, I'll try to add this type into a new pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant