반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

sklearn.feature_extraction.text.TfidfTransformer.LogisticRegression적용 본문

[AI]/python.sklearn

sklearn.feature_extraction.text.TfidfTransformer.LogisticRegression적용

givemebro 2020. 4. 28. 12:54
반응형
from sklearn.feature_extraction.text import TfidfVectorizer

vect=TfidfVectorizer(min_df=5)
vect.fit(text_train)
X_train=vect.transform(text_train)

from sklearn.linear_model import LogisticRegression
model=LogisticRegression()
model.fit(X_train,y_train)

X_test=vect.transform(text_test)

display(model.score(X_test,y_test),model.coef_)

w=model.coef_[0]

index_small=np.argsort(w)[:20]
index_big=np.argsort(w)[-20:]
index_merge=np.r_[index_small,index_big]

fn=np.array(vect.get_feature_names())
merge_name=fn[index_merge]

plt.figure(figsize=[10,10])
plt.bar(range(40),w[index_merge])
plt.xticks(range(40),merge_name,rotation=90)
pass

 

반응형
Comments