'GRFTree' object has no attribute 'n_features_in_'
@kbattocchi is already working on this.
Since Feb 13, 2022.
- Dominant language
- Jupyter Notebook
- Stars
- 4.8k
- Forks
- 827
- PR merge metrics
- No merged PRs in 30d
Description
Hi.
I just installed 'EconML' and I have problems in calculating heterogeneous effects for each individual of my test-set database.
This is not a problem with my PC but with the library in general, as I am finding the sample problem testing the code in Google Colab and even after reinstalling all Anaconda:
CODE:
causal_forest_model = CausalForestDML(discrete_treatment=True, model_t = RandomForestClassifier(random_state = 1234), model_y= RandomForestRegressor(random_state=1234, max_features = "sqrt", n_estimators = 1800,max_depth = 10, min_samples_leaf = 55), n_estimators = 1000)
causal_forest_model.tune(y_train, t_train2, X=X_train_scaled)
causal_forest_model.fit(y_train, t_train2, X=X_train_scaled)
df_predict_random1['Control'] = pd.Series(causal_forest_model.effect(X_test_scaled, T1 = 0))
ATTRIBUTE ERROR:
----> 5 df_predict_random1['Control'] = pd.Series(causal_forest_model.effect(X_test_scaled, T1 = 0))
C:\ProgramData\Anaconda3\lib\site-packages\econml_cate_estimator.py in effect(self, X, T0, T1)
860 def effect(self, X=None, *, T0=0, T1=1):
861 # NOTE: don't explicitly expand treatments here, because it's done in the super call
--> 862 return super().effect(X, T0=T0, T1=T1)
863 effect.doc = BaseCateEstimator.effect.doc
864
C:\ProgramData\Anaconda3\lib\site-packages\econml_cate_estimator.py in effect(self, X, T0, T1)
588 # TODO: what if input is sparse? - there's no equivalent to einsum,
589 # but tensordot can't be applied to this problem because we don't sum over m
--> 590 eff = self.const_marginal_effect(X)
591 # if X is None then the shape of const_marginal_effect will be wrong because the number
592 # of rows of T was not taken into account
C:\ProgramData\Anaconda3\lib\site-packages\econml_ortho_learner.py in const_marginal_effect(self, X)
790 return self._ortho_learner_model_final.predict()
791 else:
--> 792 return self._ortho_learner_model_final.predict(X)
793 const_marginal_effect.doc = LinearCateEstimator.const_marginal_effect.doc
794
C:\ProgramData\Anaconda3\lib\site-packages\econml\dml_rlearner.py in predict(self, X)
100
101 def predict(self, X=None):
--> 102 return self._model_final.predict(X)
103
104 def score(self, Y, T, X=None, W=None, Z=None, nuisances=None, sample_weight=None, groups=None):
C:\ProgramData\Anaconda3\lib\site-packages\econml\dml\causal_forest.py in predict(self, X)
93
94 def predict(self, X):
---> 95 return self._model.predict(self._combine(X, fitting=False)).reshape((-1,) + self._d_y + self._d_t)
96
97 @property
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf\classes.py in predict(self, X, interval, alpha)
44 return np.moveaxis(np.array(pred), 0, 1), np.moveaxis(np.array(lb), 0, 1), np.moveaxis(np.array(ub), 0, 1)
45 else:
---> 46 pred = [estimator.predict(X, interval=interval, alpha=alpha) for estimator in self.estimators_]
47 return np.moveaxis(np.array(pred), 0, 1)
48
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf\classes.py in (.0)
44 return np.moveaxis(np.array(pred), 0, 1), np.moveaxis(np.array(lb), 0, 1), np.moveaxis(np.array(ub), 0, 1)
45 else:
---> 46 pred = [estimator.predict(X, interval=interval, alpha=alpha) for estimator in self.estimators_]
47 return np.moveaxis(np.array(pred), 0, 1)
48
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf_base_grf.py in predict(self, X, interval, alpha)
836 lb[:, :self.n_relevant_outputs_], ub[:, :self.n_relevant_outputs_])
837 else:
--> 838 y_hat = self.predict_full(X, interval=False)
839 if self.n_relevant_outputs_ == self.n_outputs_:
840 return y_hat
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf_base_grf.py in predict_full(self, X, interval, alpha)
804 ub[:, t] = pred_dist.ppf(1 - (alpha / 2))
805 return point, lb, ub
--> 806 return self._predict_point_and_var(X, full=True, point=True, var=False)
807
808 def predict(self, X, interval=False, alpha=0.05):
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf_base_grf.py in _predict_point_and_var(self, X, full, point, var, project, projector)
685 """
686
--> 687 alpha, jac = self.predict_alpha_and_jac(X)
688 invjac = np.linalg.pinv(jac)
689 parameter = np.einsum('ijk,ik->ij', invjac, alpha)
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf_base_grf.py in predict_alpha_and_jac(self, X, slice, parallel)
621 check_is_fitted(self)
622 # Check data
--> 623 X = self._validate_X_predict(X)
624
625 # Assign chunk of trees to jobs
C:\ProgramData\Anaconda3\lib\site-packages\econml\grf_base_grf.py in validate_X_predict(self, X)
461 check_is_fitted(self)
462
--> 463 return self.estimators[0]._validate_X_predict(X, check_input=True)
464
465 def predict_tree_average_full(self, X):
C:\ProgramData\Anaconda3\lib\site-packages\econml\tree_tree_classes.py in validate_X_predict(self, X, check_input)
284
285 n_features = X.shape[1]
--> 286 if self.n_features_in != n_features:
287 raise ValueError("Number of features of the model must "
288 "match the input. Model n_features is %s and "
AttributeError: 'GRFTree' object has no attribute 'n_features_in_'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.