shankarpandala / lazypredict

Lazy Predict help build a lot of basic models without much code and helps understand which models works better without any parameter tuning
MIT License
2.76k stars 317 forks source link

GammaRegressor model failed to execute #405

Open nosacapital opened 1 year ago

nosacapital commented 1 year ago

I finally got Lazypredict to work on the M1 Mac but have encountered another problem. Without too much emphasis on the whole file, here is the last bit of code I am running:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=123)

from lazypredict.Supervised import LazyRegressor
reg = LazyRegressor(verbose=0, ignore_warnings=False, custom_metric=None)
models, predictions = reg.fit(X_train, X_test, y_train.values.ravel(), y_test)

All seems well until I get to 24% when I get the following message: GammaRegressor model failed to execute Some value(s) of y are out of the valid range of the loss 'HalfGammaLoss'.

Before using the ravel function, I got suggestions to use the function, hence, the code above. Any suggestions would be quite appreciated.

Thanks

shpatrickguo commented 1 year ago

Have you tried removing the GammaRegressor model from the list of regressors.

In lazypredict/Supervised.py, by default regressor = "all"

    def __init__(
        self,
        verbose=0,
        ignore_warnings=True,
        custom_metric=None,
        predictions=False,
        random_state=42,
        regressors="all",
    )

Instead you could put in an list of models:

            if self.regressors == "all":
            self.regressors = REGRESSORS
        else:
            try:
                temp_list = []
                for regressor in self.regressors:
                    full_name = (regressor.__name__, regressor)
                    temp_list.append(full_name)
                self.regressors = temp_list
            except Exception as exception:
                print(exception)
                print("Invalid Regressor(s)")

So your code could be like this:

from sklearn.linear_model import LinearRegression, Ridge, Lasso
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.svm import SVR
from lazypredict.Supervised import LazyRegressor

REGRESSORS = [LinearRegression, Ridge, Lasso, DecisionTreeRegressor, RandomForestRegressor, GradientBoostingRegressor, KNeighborsRegressor, SVR]
reg = LazyRegressor(verbose=0, ignore_warnings=False, custom_metric=None, regressors=REGRESSORS)
models, predictions = reg.fit(X_train, X_test, y_train.values.ravel(), y_test)