Skip to content

Commit

Permalink
rename remaining references to properties features_in_ and features_o…
Browse files Browse the repository at this point in the history
…ut_ (#72)
  • Loading branch information
j-ittner authored Sep 23, 2020
1 parent 5bb0da9 commit f43fb9f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion notebooks/Classification_with_Facet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
"\n",
"# run feature selection using Boruta and report those selected\n",
"boruta_pipeline.fit(X=prediab.features, y=prediab.target)\n",
"selected = boruta_pipeline.features_out.to_list()\n",
"selected = boruta_pipeline.features_original_.unique()\n",
"selected"
]
},
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Predictive_Maintenance_Regression_with_Facet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
"source": [
"# fit pipeline and print selected features\n",
"selection_pipeline.fit(X=sample.features, y=sample.target)\n",
"print(f\"Selected features: {selection_pipeline.features_out.tolist()}\")"
"print(f\"Selected features: {selection_pipeline.features_out_.tolist()}\")"
]
},
{
Expand All @@ -578,7 +578,7 @@
"outputs": [],
"source": [
"# update FACET sample object to only those features Boruta identified as useful\n",
"sample_selected = sample.keep(features=selection_pipeline.features_out)"
"sample_selected = sample.keep(features=selection_pipeline.features_out_)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Regression_Water_Drilling_Simulation_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@
"\n",
"preprocessing_pipeline.fit(X=sample.features, y=sample.target)\n",
"\n",
"print(f\"Selected features: {list(preprocessing_pipeline.features_out)}\")\n",
"sample_selected = sample.keep(preprocessing_pipeline.features_out)"
"print(f\"Selected features: {list(preprocessing_pipeline.features_out_)}\")\n",
"sample_selected = sample.keep(preprocessing_pipeline.features_out_)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion sphinx/source/tutorial/Classification_with_Facet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
"\n",
"# run feature selection using Boruta and report those selected\n",
"boruta_pipeline.fit(X=prediab.features, y=prediab.target)\n",
"selected = boruta_pipeline.features_out.to_list()\n",
"selected = boruta_pipeline.features_original_.unique()\n",
"selected"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
"source": [
"# fit pipeline and print selected features\n",
"selection_pipeline.fit(X=sample.features, y=sample.target)\n",
"print(f\"Selected features: {selection_pipeline.features_out.tolist()}\")"
"print(f\"Selected features: {selection_pipeline.features_out_.tolist()}\")"
]
},
{
Expand All @@ -685,7 +685,7 @@
"outputs": [],
"source": [
"# update FACET sample object to only those features Boruta identified as useful\n",
"sample_selected = sample.keep(features=selection_pipeline.features_out)"
"sample_selected = sample.keep(features=selection_pipeline.features_out_)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@
"\n",
"preprocessing_pipeline.fit(X=sample.features, y=sample.target)\n",
"\n",
"print(f\"Selected features: {list(preprocessing_pipeline.features_out)}\")\n",
"sample_selected = sample.keep(preprocessing_pipeline.features_out)"
"print(f\"Selected features: {list(preprocessing_pipeline.features_out_)}\")\n",
"sample_selected = sample.keep(preprocessing_pipeline.features_out_)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/facet/crossfit/_crossfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _fit_score(
# generate parameter objects for fitting and/or scoring each split

def _generate_parameters() -> Iterator[_FitScoreParameters]:
learner_features = pipeline.features_out
learner_features = pipeline.features_out_
n_learner_features = len(learner_features)
test_scores = do_score and not _train_scores
models = iter(lambda: None, 0) if do_fit else self.models()
Expand Down
4 changes: 2 additions & 2 deletions src/facet/inspection/_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def features(self) -> List[str]:
The names of the features used to fit the learner pipeline explained by this
inspector.
"""
return self.crossfit.pipeline.features_out.to_list()
return self.crossfit.pipeline.features_out_.to_list()

def shap_values(self, consolidate: Optional[str] = "mean") -> pd.DataFrame:
"""
Expand Down Expand Up @@ -689,7 +689,7 @@ def _feature_matrix_to_df(self, matrix: np.ndarray) -> pd.DataFrame:
matrix_df = pd.DataFrame(
data=matrix_2d,
columns=self.shap_values().columns,
index=self.crossfit.pipeline.features_out.rename(Sample.IDX_FEATURE),
index=self.crossfit.pipeline.features_out_.rename(Sample.IDX_FEATURE),
)

assert matrix_df.shape == (n_features, n_outputs * n_features)
Expand Down
6 changes: 3 additions & 3 deletions src/facet/inspection/_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def fit(self: T, crossfit: LearnerCrossfit[T_LearnerPipelineDF], **fit_params) -
self.shap_ = None

training_sample = crossfit.sample
self.feature_index_ = crossfit.pipeline.features_out.rename(Sample.IDX_FEATURE)
self.feature_index_ = crossfit.pipeline.features_out_.rename(Sample.IDX_FEATURE)
self.output_names_ = self._output_names(crossfit=crossfit)
self.sample_ = training_sample

Expand Down Expand Up @@ -230,7 +230,7 @@ def _shap_all_splits(
None
if background_dataset is None
else background_dataset.reindex(
columns=model.final_estimator.features_in, copy=False
columns=model.final_estimator.features_in_, copy=False
)
),
),
Expand Down Expand Up @@ -361,7 +361,7 @@ def _preprocessed_features(
x = model.preprocessing.transform(x)

# re-index the features to fit the sequence that was used to fit the learner
return x.reindex(columns=model.final_estimator.features_in, copy=False)
return x.reindex(columns=model.final_estimator.features_in_, copy=False)

@staticmethod
@abstractmethod
Expand Down
3 changes: 2 additions & 1 deletion test/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def feature_names(best_lgbm_crossfit: LearnerCrossfit[RegressorPipelineDF]) -> S
all unique features across the models in the crossfit, after preprocessing
"""
return functools.reduce(
operator.or_, (set(model.features_out) for model in best_lgbm_crossfit.models())
operator.or_,
(set(model.features_out_) for model in best_lgbm_crossfit.models()),
)


Expand Down

0 comments on commit f43fb9f

Please sign in to comment.