Python 尝试查看验证测试的性能时出现DataConversionWarning

Python 尝试查看验证测试的性能时出现DataConversionWarning,python,numpy,scikit-learn,Python,Numpy,Scikit Learn,现在我正在做一个文本分类任务(我想看看响应是人工还是机器人生成的)。不幸的是,当我尝试查看验证数据集的准确度时,我得到以下错误: Blockquote DataConversionWarning:当需要1d数组时,传递了列向量y。请将y的形状更改为(n_samples,),例如使用ravel()。 y=列_或_1d(y,警告=真) 我尝试使用ravel()方法和重塑,但我仍然得到警告,在互联网上找不到有用的东西 我的代码的一部分是这样的: with open('validation.txt')

现在我正在做一个文本分类任务(我想看看响应是人工还是机器人生成的)。不幸的是,当我尝试查看验证数据集的准确度时,我得到以下错误:

Blockquote DataConversionWarning:当需要1d数组时,传递了列向量y。请将y的形状更改为(n_samples,),例如使用ravel()。 y=列_或_1d(y,警告=真)

我尝试使用ravel()方法和重塑,但我仍然得到警告,在互联网上找不到有用的东西

我的代码的一部分是这样的:

with open('validation.txt') as f:
reader = DictReader(f, delimiter='\t')
for row in reader:
    target_values_validation.append(int(row['human-generated']))
    row['response']=row['response'].replace('<first_speaker>', '')
    row['response'] = row['response'].replace('<second_speaker>', '')
    row['response'] = row['response'].replace('<third_speaker>', '')
    row['response'] = row['response'].replace('@@ ', '')
    row['response'] = row['response'].replace('<at>', '')
    row['response'] = row['response'].replace('<url>', '')
    row['response'] = row['response'].replace('<number>', '')
    list_response_validation.append(row['response'])
y_validation=numpy.asarray(target_values,dtype=int)
    text_clf = Pipeline([('vect', CountVectorizer()),
                 ('tfidf', TfidfTransformer()),
                 ('clf', MultinomialNB())])
text_clf=text_clf.fit(list_response_train, y)
predicted1=text_clf.predict(list_response_validation)
accuracy=numpy.mean(predicted1==y_validation.ravel())
print(accuracy)
以open('validation.txt')作为f的
:
reader=DictReader(f,分隔符='\t')
对于读取器中的行:
target_values_validation.append(int(行['human-generated']))
行['response']=行['response']。替换('','')
行['response']=行['response']。替换('','')
行['response']=行['response']。替换('','')
行['response']=行['response']。替换('@@','')
行['response']=行['response']。替换('','')
行['response']=行['response']。替换('','')
行['response']=行['response']。替换('','')
列表\响应\验证。追加(第['response']行)
y_validation=numpy.asarray(目标值,dtype=int)
text_clf=管道([('vect',CountVectorizer()),
('tfidf',tfidftranformer()),
('clf',多项式nb())]
text\u clf=text\u clf.fit(列表响应序列,y)
predicted1=text\u clf.predict(列表\u响应\u验证)
精度=numpy.mean(predicted1==y\u validation.ravel())
打印(准确性)

每个建议或替代解决方案都得到了高度重视。

1。固定缩进2。您创建了
y\u验证
,然后拟合
y
,您想要哪个?3.什么是
y.shape
y.dtype
?谢谢你的评论,实际上我完全忘了对y应用ravel()。缩进在我的文本编辑器中是很好的,但我想我在复制粘贴代码时把它们弄糟了。y是用于训练模型的目标值向量,y_验证用于测试性能。我现在唯一的问题是精度是0.0,我不明白为什么。固定缩进2。您创建了
y\u验证
,然后拟合
y
,您想要哪个?3.什么是
y.shape
y.dtype
?谢谢你的评论,实际上我完全忘了对y应用ravel()。缩进在我的文本编辑器中是很好的,但我想我在复制粘贴代码时把它们弄糟了。y是用于训练模型的目标值向量,y_验证用于测试性能。我现在唯一的问题是精度是0.0,我不明白为什么。