def cv(feature_dict, feature, polarity, folds):
kfold = KFold(len(polarity), n_folds = folds)
count, f1, recall, precision, accuracy = 0, 0, 0, 0, 0
for train, test in kfold:
LR = LogisticRegression()
count += 1
x = [(feature[i]) for i in train]
y = [(polarity[i])for i in train]
LR.fit(scipy.sparse.vstack(x), (y))
test_label = []
answer_label = [(polarity[j]) for j in test]
for j in test:
query = feature[j]
result = -1 if query.shape[1] != len(feature_dict) else predict(LR, query)
test_label.append(result[1][1])
pre, rec, thr = precision_recall_curve(answer_label, test_label)
return pre, rec, thr
return accuracy, precision, recall, f1
评论列表
文章目录