logistics regression 进行 emotion_analysis

import numpy as np
import pandas as pd
data = pd.read_csv('./ISEAR.csv',header=None)
data.head()
012
0joyOn days when I feel close to my partner and ot...NaN
1fearEvery time I imagine that someone I love or I ...NaN
2angerWhen I had been obviously unjustly treated and...NaN
3sadnessWhen I think about the short time that we live...NaN
4disgustAt a gathering I found myself involuntarily si...NaN
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer

X_data = data[1].values.tolist()
Y_data = data[0].values.tolist()
vectorizer = TfidfVectorizer()
X_data = vectorizer.fit_transform(X_data)
x_train, x_test, y_train, y_test = train_test_split(X_data, Y_data, train_size = 0.8, random_state = 42)

{'anger', 'disgust', 'fear', 'guilt', 'joy', 'sadness', 'shame'}
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
lr = LogisticRegression()
lr.fit(x_train, y_train).score(x_test, y_test)

parameters = {'C':[0.005,0.01, 0.1, 0.5,1.5, 2,2.5, 3.5]}
clf = GridSearchCV(lr, parameters, cv=5 )
clf.fit(x_train, y_train)
print(clf.score(x_test, y_test))
print(clf.best_params_)
0.5791223404255319
{'C': 2}
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, clf.predict(x_test))
array([[ 98,  35,  17,  29,  14,  17,  17],
       [ 25, 123,  13,  18,   9,   3,  13],
       [ 13,   7, 137,  12,  13,  11,   7],
       [ 24,  12,  11, 110,  12,  15,  25],
       [  7,   7,   8,   8, 182,  12,   9],
       [ 17,  18,  14,   8,  19, 122,   7],
       [ 20,  32,  15,  34,  20,   6,  99]], dtype=int64)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值