mlinsights icon indicating copy to clipboard operation
mlinsights copied to clipboard

Error for some of the regression models

Open Mojzaar opened this issue 2 years ago • 1 comments

I was going to use PiecewiseRegressor with ARDRegression estimator, and in general an estimator build with a pipeline or Gridsearch model but I am getting this error: Traceback (most recent call last): File "<ipython-input-37-ef69b6e34e02>", line 1, in <module> model.fit(sf.X_train,sf.y_train) File "/usr/local/lib/python3.8/dist-packages/mlinsights/mlmodel/piecewise_estimator.py", line 250, in fit self.mean_estimator_ = clone(self.estimator).fit(X, y, sample_weight) TypeError: fit() takes 3 positional arguments but 4 were given

While PiecewiseRegressor works fine with other models like Ridge, Lasso and LinearRegression. Any idea what is going wrong here?

P.S: It appears some regression models and GS models do not accept the "sample_weight" parameter, so giving it to the estimator throws this error. So, in piecewise_estimator code, if one checks weather the estimator's fit function has "sample_weight" parameter by: self.mean_estimator_ = clone(self.estimator).fit(X, y, sample_weight) if 'sample_weight' in list(self.estimator.fit.__code__.co_varnames) else clone(self.estimator).fit(X, y) the problem is solved!

Mojzaar avatar Mar 22 '23 17:03 Mojzaar

I'm sorry. I don't actively work on this package. Do you have an example I could use to replicate the error?

sdpython avatar Sep 07 '24 15:09 sdpython