【问题标题】:ValueError: Unknown label type sklearnValueError:未知标签类型sklearn
【发布时间】:2020-05-14 10:18:59
【问题描述】:

我是 sklearn 的新手。我正在尝试执行此代码:

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) 

我看到了这个错误:

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 ]),)

在专栏评论中有短语,在 nota 浮动。

【问题讨论】:

    标签: python pandas scikit-learn


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 2018-01-01
      • 2020-05-11
      • 2018-07-22
      • 2017-09-21
      • 2018-01-02
      • 2018-12-16
      • 2021-08-17
      • 2018-03-16
      相关资源
      最近更新 更多