crflynn / skgrf

scikit-learn compatible Python bindings for grf (generalized random forests) C++ random forest library
https://skgrf.readthedocs.io/en/stable/
GNU General Public License v3.0
30 stars 6 forks source link

AttributeError: 'GRFForestRegressor' object has no attribute '_validate_data' #69

Closed ilemhadri closed 3 years ago

ilemhadri commented 3 years ago

Trying to reproduce the example from the README:

from skgrf.ensemble import GRFForestCausalRegressor

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from skgrf.ensemble import GRFForestRegressor

X, y = load_boston(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y)

forest = GRFForestRegressor()
forest.fit(X_train, y_train)

predictions = forest.predict(X_test)
print(predictions)

This gives the error

---------------------------------------------------------------
AttributeError                Traceback (most recent call last)
<ipython-input-8-897d3385e0c1> in <module>
      7 
      8 forest = GRFForestRegressor()
----> 9 forest.fit(X_train, y_train)
     10 
     11 predictions = forest.predict(X_test)

~/anaconda3/lib/python3.7/site-packages/skgrf/ensemble/regressor.py in fit(self, X, y, sample_weight, cluster, compute_oob_predictions)
    116         :param array1d cluster: optional cluster assignments for input samples
    117         """
--> 118         X, y = self._validate_data(X, y)
    119         self._check_num_samples(X)
    120         self._check_n_features(X, reset=True)

AttributeError: 'GRFForestRegressor' object has no attribute '_validate_data'
crflynn commented 3 years ago

Can you share the version of scikit-learn and skgrf you are using? I believe _validate_data is part of sklearn 0.23.0+. If you are on an old version you should try to upgrade. Looks like we should be pinning sklearn >= 0.23.0 here as well.

ilemhadri commented 3 years ago

Indeed! I was using 0.22. Just updated scikit learn and this solved the problem. Thanks