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
The document mentioned that we can pass any linear or tree model to ClassicTreeExplainer. All code works smoothly if we use the classifier from interpret-text, however, if we train a logistic regression on the outside, and try to pass it to classic explainer, it gives the above error.
Now, the question is, do the explainers actually support any outside model or it has to be fitted from classifiers inside interpret-text package?
~/anaconda3/envs/fairlearn/lib/python3.6/site-packages/interpret_text/experimental/classical.py in explain_local(self, X, y, name)
143 X = _validate_X(X)
144
--> 145 [encoded_text, _] = self.preprocessor.encode_features(
146 X, needs_fit=False
147 )
AttributeError: 'LogisticRegression' object has no attribute 'encode_features'
X_test is the actual texts in the test data, X_test.iloc[0] is actually "Thank you for correcting my typo in Thomas Pooley. I am the world's worst proofreader!"
Just want to find an answer
The text was updated successfully, but these errors were encountered:
I think you need to change the code "explainer = ClassicalTextExplainer(model1)" to "explainer = ClassicalTextExplainer(model=model1)". Can you give this a try?
The document mentioned that we can pass any linear or tree model to ClassicTreeExplainer. All code works smoothly if we use the classifier from interpret-text, however, if we train a logistic regression on the outside, and try to pass it to classic explainer, it gives the above error.
Now, the question is, do the explainers actually support any outside model or it has to be fitted from classifiers inside interpret-text package?
My code:
n = X_train.shape[0]
vec = TfidfVectorizer(ngram_range=(1,2), tokenizer=tokenize, min_df=3, max_df=0.9, strip_accents='unicode', use_idf=1, smooth_idf=1, sublinear_tf=1 )
trn_term_doc = vec.fit_transform(X_train)
test_term_doc = vec.transform(X_test)
m = LogisticRegression()
model1=m.fit(x,y_train)
predicted_label = model1.predict(test_x)
explainer = ClassicalTextExplainer(model1)
local_explanation = explainer.explain_local(X_test.iloc[0], predicted_label[0])
The last line results in the error
AttributeError Traceback (most recent call last)
in
----> 1 local_explanation = explainer.explain_local(X_test.iloc[0], predicted_label[0])
~/anaconda3/envs/fairlearn/lib/python3.6/site-packages/interpret_text/experimental/classical.py in explain_local(self, X, y, name)
143 X = _validate_X(X)
144
--> 145 [encoded_text, _] = self.preprocessor.encode_features(
146 X, needs_fit=False
147 )
AttributeError: 'LogisticRegression' object has no attribute 'encode_features'
X_test is the actual texts in the test data, X_test.iloc[0] is actually "Thank you for correcting my typo in Thomas Pooley. I am the world's worst proofreader!"
Just want to find an answer
The text was updated successfully, but these errors were encountered: