python注释分为_使用ScikitLearn和Python将注释分为正反两类

我试图编写一个代码,将注释分为肯定和否定(0表示否定,1表示肯定)。在

我有一个pandas数据帧,有两列,comments和results。我在Python Scikit-Learn库中使用了Logistic Regression(我将尝试其他分类器,如决策树、SVM、KNN…),但它给了我一个错误(我想在没有情绪分析的情况下这样做)。我认为问题是因为我输入的是字符串而不是数字。

我的程序应该接受一个注释(字符串值),并计算它是0或{}。

代码如下:import pandas as pd

from sklearn.feature_extraction.text import CountVectorizer

from sklearn.linear_model import LogisticRegression

from sklearn import linear_model

full_comment_data = pd.DataFrame({"Comment":["This is bad", "Good job", "I do not like this"],

"Result":[0,1,0]})

features = full_comment_data["Comment"]

results = full_comment_data["Result"]

cv = CountVectorizer()

features = cv.fit_transform(features)

logistic_regression = linear_model.LogisticRegression(solver="lbfgs")

model = logistic_regression.fit(features, results)

input_values = ["I love this comment"] #This value should be evaluated

prediction = logistic_regression.predict([input_values]) #adding values for prediction

prediction = prediction[0]

print(prediction)

这是我得到的错误:

^{pr2}$

我也尝试过:

^{3}$

我得到一个错误:ValueError: X has 3 features per sample; expecting ...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值