我试图编写一个代码,将注释分为肯定和否定(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 ...