Reputation: 1
I've started learning Lime. When I use LimeTabular form Interpret, I face a problem that I according to the standard complete the function but it doesn't work. The error is TypeError: init() missing 1 required positional argument: 'model'
# %% Imports
from utils import DataLoader
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import f1_score, accuracy_score
from interpret.blackbox import LimeTabular
from interpret import show
# %% Load and preprocess data
data_loader = DataLoader()
data_loader.load_dataset()
data_loader.preprocess_data()
# Split the data for evaluation
X_train, X_test, y_train, y_test = data_loader.get_data_split()
# Oversample the train data
X_train, y_train = data_loader.oversample(X_train, y_train)
print(X_train.shape)
print(X_test.shape)
# %% Fit blackbox model
rf = RandomForestClassifier()
rf.fit(X_train, y_train)
y_pred = rf.predict(X_test)
print(f"F1 Score {f1_score(y_test, y_pred, average='macro')}")
print(f"Accuracy {accuracy_score(y_test, y_pred)}")
# %% Apply lime
# Initilize Lime for Tabular data
lime = LimeTabular(predict_fn=rf.predict_proba,
data=X_train,
random_state=1)
# Get local explanations
lime_local = lime.explain_local(X_test[-20:],
y_test[-20:],
name='LIME')
show(lime_local)
# %%
Upvotes: -1
Views: 70
Reputation: 85
In the code you are using:
lime = LimeTabular(*predict_fn*=rf.predict_proba,
data=X_train,
random_state=1)
predict_fn parameter is deprecated, so you need to pass the model itself. make it like this
lime = LimeTabular(rf,
data=X_train,
random_state=1)
If you are using conda, you might get an error with lime not recognized as a model, then you need to do conda install lime
Upvotes: 0
Reputation: 1
The error is TypeError: init() missing 1 required positional argument: 'model' **In this problem you are calling constructor in line "data_loader = DataLoader()" and it takes one argument that name is model so you have to pass it
another thing you can do it you can use default argument like this class DataLoader: def init(self,model=helper): instead of helper you can use your model if it require somewhere or otherwise it can be None.. hope you will get it have a great day!!!
Upvotes: -1