【发布时间】:2020-04-25 23:06:54
【问题描述】:
数据集包含 3 列:comment、parent_comment 和 label(0 或 1)。我尝试预测 y_test 的标签,但出现错误
Found input variables with inconsistent numbers of samples: [2, 758079]
不知何故,y_predict 的形状是 (2,0)。 为什么会这样以及如何解决?
当我这样做时
y_test = y_test_["comment"]
一切都很好。
由于某种原因 y_predict 的形状为 (2,) 而 y_true 的形状为正常的 (252694,)
x_train, y_test_ = train_test_split(df1, random_state=17)
y_test = y_test_[["comment", "parent_comment"]]
y_true = y_test_["label"]
tf_idf = TfidfVectorizer(stop_words = 'english', ngram_range=(1, 2), max_features=700000, min_df=0.01)
# multinomial logistic regression a.k.a softmax classifier
logit = LogisticRegression(C=1, n_jobs=4, solver='lbfgs',
random_state=17, verbose=1)
# sklearn's pipeline
tfidf_logit_pipeline = Pipeline([('tf_idf', tf_idf),
('logit', logit)])
tfidf_logit_pipeline.fit(x_train[['comment',"parent_comment"]], x_train["label"])
y_predict = tfidf_logit_pipeline.predict(y_test)
accuracy_score(y_predict, y_true)
【问题讨论】:
-
你的错误发生在哪一行?
-
@PV8 最后一个,我在这里尝试测量准确性
标签: python machine-learning classification tfidfvectorizer