Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'LogisticRegression' object has no attribute 'encode_features' #148

Open
anindya5 opened this issue Oct 29, 2020 · 1 comment

Comments

@anindya5
Copy link

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

@gaugup
Copy link

gaugup commented Nov 25, 2020

Hi @anindya5,

I think you need to change the code "explainer = ClassicalTextExplainer(model1)" to "explainer = ClassicalTextExplainer(model=model1)". Can you give this a try?

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants