ValueError:无法将字符串转换为在 pandas 中浮动 [英] ValueError: could not convert string to float in panda

查看:84
本文介绍了ValueError:无法将字符串转换为在 pandas 中浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

 import pandas as pd
data = pd.read_table('train.tsv')

X=data.Phrase
Y=data.Sentiment
from sklearn import cross_validation
X_train,X_test,Y_train,Y_test=cross_validation.train_test_split(X,Y,test_size=0.2,random_state=0)
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(X,Y)

我收到错误消息:ValueError: could not convert string to float:

我可以对我的代码进行哪些更改?

What changes can I make that my code works?

推荐答案

您不能按照 scikit-learn中的任何算法都不能直接处理文本数据.您需要进行一些预处理以获得所需的输出.您首先需要使用装袋或标记化等技术从文本数据中提取功能.看看这个链接可以更好地理解.

None of the algorithms in scikit-learn works directly with text data. You need to do some preprocessing to get desired output. You'll need to first extract the features from text data using techniques like bagging or tokenizing. Have a look at this link for better understanding.

您还可能希望针对自己的用例使用 NLTK .

You also might want to look at using NLTK for such use cases as yours.

这篇关于ValueError:无法将字符串转换为在 pandas 中浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆