Я пытаюсь сделать классификацию текста с помощью Наивного Байеса.Это мой код:
#splitting Pandas dataframe into train set and test set
x_train, x_test, y_train, y_test = cross_validation.train_test_split(data['description'], data['category_id'], test_size=0.2, random_state=42)
#production of bag of words from x_train
count_vect = CountVectorizer()
x_train_counts = count_vect.fit_transform(x_train)
train_vocab = count_vect.get_feature_names()
#training the Naive Bayes classifier
clf = MultinomialNB().fit(x_train_counts, y_train)
Ошибка:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-46-0cb3dc7193bf> in <module>()
1 #training the Naive Bayes classifier
2
----> 3 clf = MultinomialNB().fit(x_train_counts, y_train)
~/anaconda3/envs/tensorflow/lib/python3.5/site-packages/sklearn/naive_bayes.py in fit(self, X, y, sample_weight)
577 Returns self.
578 """
--> 579 X, y = check_X_y(X, y, 'csr')
580 _, n_features = X.shape
581
~/anaconda3/envs/tensorflow/lib/python3.5/site-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
577 else:
578 y = column_or_1d(y, warn=True)
--> 579 _assert_all_finite(y)
580 if y_numeric and y.dtype.kind == 'O':
581 y = y.astype(np.float64)
~/anaconda3/envs/tensorflow/lib/python3.5/site-packages/sklearn/utils/validation.py in _assert_all_finite(X)
42 and not np.isfinite(X).all()):
43 raise ValueError("Input contains NaN, infinity"
---> 44 " or a value too large for %r." % X.dtype)
45
46
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
Тип x_train_counts - scipy.sparse.csr.csr_matrix.
print(type(x_train_counts))
<class 'scipy.sparse.csr.csr_matrix'>
Типy_train - это pandas.core.series.Series.
print(type(y_train))
<class 'pandas.core.series.Series'>