I just tried the baseline tutorial, keeping only 2 categories of classes, instead of 4.
When I render my explain_weights result, I only get weights for one class, as you see below.
My code looks like this:
from sklearn.datasets import fetch_20newsgroups
categories = ['alt.atheism', 'soc.religion.christian']
# 'comp.graphics', 'sci.med']
twenty_train = fetch_20newsgroups(
subset='train',
categories=categories,
shuffle=True,
random_state=42
)
twenty_test = fetch_20newsgroups(
subset='test',
categories=categories,
shuffle=True,
random_state=42
)
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
vec = CountVectorizer()
clf = LogisticRegression()
pipe = make_pipeline(vec, clf)
pipe.fit(twenty_train.data, twenty_train.target)
import eli5
weights_explanation = eli5.explain_weights(clf, top=30,
target_names=twenty_test.target_names)
# Save to disk
with open('linear_weights.html', 'w') as file:
file.write(eli5.format_as_html(weights_explanation))
I am using scikit-learn==0.21.3 and eli5==0.10.1 version.
I have the same problem when running this with another dataset too. Any ideas?
Edit: Does it maybe just mean that the green weights are contributing more to class y=1 and the red weights don't contribute so much to y=1, thus, they contribute to y=0?
I just tried the baseline tutorial, keeping only 2 categories of classes, instead of 4.
When I render my
explain_weights
result, I only get weights for one class, as you see below.My code looks like this:
I am using
scikit-learn==0.21.3
andeli5==0.10.1
version.I have the same problem when running this with another dataset too. Any ideas?
Edit: Does it maybe just mean that the green weights are contributing more to class
y=1
and the red weights don't contribute so much toy=1
, thus, they contribute toy=0
?