ValueError: Gefundene Arrays mit inkonsistenter Anzahl von Samples [6 1786]

Hier ist mein Code:

from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
from sklearn.cross_validation import KFold
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import datasets
import numpy as np

newsgroups = datasets.fetch_20newsgroups(
                subset='all',
                categories=['alt.atheism', 'sci.space']
         )
X = newsgroups.data
y = newsgroups.target

TD_IF = TfidfVectorizer()
y_scaled = TD_IF.fit_transform(newsgroups, y)
grid = {'C': np.power(10.0, np.arange(-5, 6))}
cv = KFold(y_scaled.size, n_folds=5, shuffle=True, random_state=241) 
clf = SVC(kernel='linear', random_state=241)

gs = GridSearchCV(estimator=clf, param_grid=grid, scoring='accuracy', cv=cv)
gs.fit(X, y_scaled) 

Ich erhalte eine Fehlermeldung und verstehe nicht warum. Der Traceback:

Traceback (letzter Aufruf zuletzt): File
"C: /Users/Roman/PycharmProjects/week_3/assignment_2.py", Zeile 23, in

gs.fit (X, y_scaled) #TODO: Aktivieren Sie diese Zeile. Datei "C: \ Users \ Roman \ AppData \ Roaming \ Python \ Python35 \ site-packages \ sklearn \ grid_search.py",
line 804, in fit
return self._fit (X, y, ParameterGrid (self.param_grid)) Datei "C: \ Users \ Roman \ AppData \ Roaming \ Python \ Python35 \ site-packages \ sklearn \ grid_search.py",
Zeile 525, in _fit
X, y = indexierbare (X, y) Datei "C: \ Users \ Roman \ AppData \ Roaming \ Python \ Python35 \ site-packages \ sklearn \ utils \ validation.py",
line 201, in indexierbarem
check_consistent_length (* result) Datei "C: \ Users \ Roman \ AppData \ Roaming \ Python \ Python35 \ site-packages \ sklearn \ utils \ validation.py",
line 176, in check_consistent_length
"% s"% str (einzigartig))

ValueError: Gefundene Arrays mit inkonsistenter Anzahl von Samples: [6 1786]

Kann jemand erklären, warum dieser Fehler auftritt?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage