dswah / pyGAM

[HELP REQUESTED] Generalized Additive Models in Python
https://pygam.readthedocs.io
Apache License 2.0
862 stars 159 forks source link

Use of gridsearch with only one feature #245

Open TimZaragori opened 5 years ago

TimZaragori commented 5 years ago

I'm using pyGAM as curve fitting to compare it to function fitted with non-linear least squares method. Thus my data set is composed of only one feature. It seems that gam = GAM().gridsearch(X,y) doesn't work if X has only one feature and only if the GAM was not previously fitted. The error raise is : ValueError: not enough values to unpack (expected 2, got 1) coming from self._validate_data_dep_params(X) because of n_samples, m_features = X.shape (line 273 of pygam.py). Considering X has only one feature, so something like X = array([x1, x2, ..., xN]), X.shape returns (len(X),) and therefore only one value to unpack.

There is no error if we use gam = GAM().fit(X,y) before gam.gridsearch(X,y) because there is no need to validate the parameters first. It is still a bit strange because there is also the call of self._validate_data_dep_params(X) in the GAM().fit(X,y) fuction and it's working. Is it due to this part of code just before the call? # validate data y = check_y(y, self.link, self.distribution, verbose=self.verbose) X = check_X(X, verbose=self.verbose) check_X_y(X, y)

Feel free to ask for more information if needed.

dswah commented 5 years ago

@TimZaragori ahh good catch, that is annoying! I'm not sure why gridsearch() is more picky than fit() about the dimensionality of X.

For now, you can add another dimension to X.

GAM().gridsearch(X[:,None], y)