При обучение модели с nlp ошибка ValueError: Found input variables with inconsistent numbers of samples: [1, 1692]?

Пишу классификатор новостей по темам. Пр обучении модели вылезает такая ошибка ValueError: Found input variables with inconsistent numbers of samples: [1, 1692].
Вот исходный код:
from sklearn.datasets import fetch_20newsgroups
from pandas import DataFrame
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.linear_model import SGDClassifier
from sklearn.metrics import accuracy_score, f1_score, roc_auc_score

categories = ['alt.atheism', 'soc.religion.christian', 'comp.graphics', 'sci.med']
twenty_train = fetch_20newsgroups(subset='train', categories=categories, shuffle=True, random_state=42)

df = DataFrame(twenty_train['data'], columns=['text'])
df['target'] = twenty_train['target']

X_train, X_test, y_train, y_test = train_test_split(df.drop('target', axis=1), df['target'])

text_clf = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()), ('clf', SGDClassifier())])
model = text_clf.fit(X_train, y_train)

import numpy as np

twenty_test = fetch_20newsgroups(subset='test',
                                 categories=categories, shuffle=True, random_state=42)
docs_test = twenty_test.data
predicted = text_clf.predict(docs_test)
print(np.mean(predicted == twenty_test.target))

pred_y = model.predict(X_test)
print('accuracy - ', accuracy_score(y_test, pred_y))


Буду благодарен за помощь
  • Вопрос задан
  • 549 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы