diff --git a/econml/inference.py b/econml/inference.py index 01e20e65c..58dcdd44e 100644 --- a/econml/inference.py +++ b/econml/inference.py @@ -237,7 +237,7 @@ def coef__inference(self): if coef.size == 0: # X is None raise AttributeError("X is None, please call intercept_inference to learn the constant!") - if callable(self._est.cate_feature_names): + if hasattr(self._est, 'cate_feature_names') and callable(self._est.cate_feature_names): def fname_transformer(x): return self._est.cate_feature_names(x) else: @@ -356,13 +356,13 @@ def fit(self, estimator, *args, **kwargs): def const_marginal_effect_interval(self, X, *, alpha=0.1): if (X is not None) and (self.featurizer is not None): - X = self.featurizer.transform(X) + X = self.featurizer.fit_transform(X) preds = np.array([mdl.predict_interval(X, alpha=alpha) for mdl in self.fitted_models_final]) return tuple(np.moveaxis(preds, [0, 1], [-1, 0])) # send treatment to the end, pull bounds to the front def const_marginal_effect_inference(self, X): if (X is not None) and (self.featurizer is not None): - X = self.featurizer.transform(X) + X = self.featurizer.fit_transform(X) pred = np.array([mdl.predict(X) for mdl in self.fitted_models_final]) if not hasattr(self.fitted_models_final[0], 'prediction_stderr'): raise AttributeError("Final model doesn't support prediction standard eror, " @@ -426,7 +426,7 @@ def coef__inference(self, T): coef_stderr = self.fitted_models_final[ind].coef_stderr_ if coef.size == 0: # X is None raise AttributeError("X is None, please call intercept_inference to learn the constant!") - if callable(self._est.cate_feature_names): + if hasattr(self._est, 'cate_feature_names') and callable(self._est.cate_feature_names): def fname_transformer(x): return self._est.cate_feature_names(x) else: @@ -692,7 +692,7 @@ def summary_frame(self, alpha=0.1, value=0, decimals=3, feat_name=None): if self.d_y == 1: res.index = res.index.droplevel(1) if self.inf_type == 'coefficient': - if feat_name and self.fname_transformer: + if feat_name is not None and self.fname_transformer: ind = self.fname_transformer(feat_name) else: ct = res.shape[0] // self.d_y