interpretml / DiCE

Generate Diverse Counterfactual Explanations for any machine learning model.
https://interpretml.github.io/DiCE/
MIT License
1.37k stars 188 forks source link

Dice Object Initialization Error #429

Open ntheol opened 9 months ago

ntheol commented 9 months ago

Hello!

I have trained an ML pipeline for a pytorch model by using the skorch wrapper like this:

nn = NeuralNetBinaryClassifier(nn_model,criterion=nn.BCELoss(),optimizer=torch.optim.AdamW, max_epochs=10, batch_size=32,verbose=False)

numerical_transformer = Pipeline([ ('scaler', StandardScaler()) ])

label_encoded_transformer = Pipeline([ ('label_encoder', OrdinalEncoder()) ])

one_hot_encoded_transformer = Pipeline([ ('one_hot_encoder', OneHotEncoder()) ])

preprocessor = ColumnTransformer( transformers=[ ('num', numerical_transformer,numeric_columns),

('label',label_encoded_transformer,label_encoded_features),

    ('one_hot', one_hot_encoded_transformer, cat_columns)
])

params = { "Modellr": [0.001, 0.01, 0.1], "Modelbatch_size": (16,64), # Different batch sizes "Modeloptimizer": [AdamW, Adam,SGD], # Different optimizers "preprocessornum__scaler": [StandardScaler(), MinMaxScaler(),RobustScaler()] }

ml_pipeline = Pipeline([("preprocessor", preprocessor), ('float32', FunctionTransformer(func=convert_to_float32)), ("Model", nn)])

optimizer = GridSearchCV(ml_pipeline,param_grid=params,optimization_algorithm='grid_search') opt = optimizer.fit(train,train_labels)

Does DiCE support this kind of model? When trying to initialize it in this way : d = dice_ml.Data(dataframe=train, continuous_features=numeric_cols.tolist(), outcome_name='label')

m = dice_ml.Model(model=opt.bestestimator, backend="sklearn")

Initializing DiCE object

exp = dice_ml.Dice(d, m, method="random")

I get the below error: error

Is it because DiCE does not support the skorch wrapper? Thank you!