You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inside the fit method of the FACTS detector, the function calc_costs is called to calculate the costs of the recourses. But the params argument (which includes the feature_weights) is not passed. As a result, the default parameters are always used, which assign weight equal to 1 to all features.
Example to reproduce:
fromsklearn.model_selectionimporttrain_test_splitfromsklearn.linear_modelimportLogisticRegressionfromsklearn.composeimportColumnTransformerfromsklearn.pipelineimportPipelinefromsklearn.preprocessingimportOneHotEncoderfromaif360.sklearn.datasets.openml_datasetsimportfetch_adultfromaif360.sklearn.detectors.facts.cleanimportclean_datasetfromaif360.sklearn.detectors.factsimportFACTSfromaif360.sklearn.detectors.facts.predicateimportPredicateimportpandasaspdrandom_seed=131313# to produce the expected if-then clause# load the adult dataset and perform some simple preprocessing steps# See output for a glimpse of the final dataset's characteristicsX, y, sample_weight=fetch_adult()
data=clean_dataset(X.assign(income=y), "adult")
# split into train-test datay=data['income']
X=data.drop('income', axis=1)
X_train, X_test, y_train, y_test=train_test_split(X, y, train_size=0.7, random_state=random_seed, stratify=y)
#### here, we incrementally build the example model. It consists of one preprocessing step,#### which is to turn categorical features into the respective one-hot encodings, and#### a simple scikit-learn logistic regressor.categorical_features=X.select_dtypes(include=["object", "category"]).columns.to_list()
categorical_features_onehot_transformer=ColumnTransformer(
transformers=[
("one-hot-encoder", OneHotEncoder(), categorical_features)
],
remainder="passthrough"
)
model=Pipeline([
("one-hot-encoder", categorical_features_onehot_transformer),
("clf", LogisticRegression(max_iter=1500))
])
#### train the modelmodel=model.fit(X_train, y_train)
detector=FACTS(
clf=model,
prot_attr="sex",
freq_itemset_min_supp=0.08,
feature_weights={f: 10forfinX.columns},
feats_not_allowed_to_change=[]
)
detector=detector.fit(X_test)
print(detector.rules_by_if[Predicate.from_dict({"age": pd.Interval(26., 34.), "hours-per-week": "FullTime"})]["Female"][1][0])
The output of the final command is (Predicate(features=['age', 'hours-per-week'], values=[Interval(41.0, 50.0, closed='right'), 'OverTime']), 0.07728337236533955, 2.0), which shows that the action of changing the features "age" and "hours-per-week" (which are categorical) is counted as having cost equal to 2.0. The correct value, however, would be 20.0, since we have assigned weight equal to 10 to all features.
The text was updated successfully, but these errors were encountered:
Inside the
fit
method of theFACTS
detector, the functioncalc_costs
is called to calculate the costs of the recourses. But theparams
argument (which includes thefeature_weights
) is not passed. As a result, the default parameters are always used, which assign weight equal to 1 to all features.Example to reproduce:
The output of the final command is
(Predicate(features=['age', 'hours-per-week'], values=[Interval(41.0, 50.0, closed='right'), 'OverTime']), 0.07728337236533955, 2.0)
, which shows that the action of changing the features "age" and "hours-per-week" (which are categorical) is counted as having cost equal to2.0
. The correct value, however, would be20.0
, since we have assigned weight equal to10
to all features.The text was updated successfully, but these errors were encountered: