简体   繁体   English

ValueError:未知标签类型sklearn

[英]ValueError: Unknown label type sklearn

I 'm new in sklearn.我是 sklearn 的新手。 I 'm trying to do this code:我正在尝试执行此代码:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
X_train, X_test, y_train, y_test = train_test_split(df['review'], df['nota'], random_state = 0)
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(X_train)
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
clf = MultinomialNB().fit(X_train_tfidf, y_train) 

And I saw this error:我看到了这个错误:

ValueError: Unknown label type: (array([5. , 4. , 4. , 5. , 1.5, 3. , 4. , 1.9, 4.5, 4.5, 2.3, 1.5, 5. ,4.5, 4.3, 2.5, 1.5, 2.7, 4.5, 4. , 3.4, 3.5, 2. , 4. , 1.5, 4.8 ]),)

In column review there are phrases and in nota floats.在列审查中有短语和 nota 浮动。

我认为它将两种类型都读为对象,为什么不尝试使用以下代码。

X_train, X_test, y_train, y_test = train_test_split(x=df['review'],y=df['nota'].astype('float'), random_state = 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM