Python : Wie finde ich die Genauigkeit Ergebnis in der SVM-Text Classifier-Algorithmus für Multilabel-Klasse

Benutzt habe ich folgenden code:
Und ich brauche, um zu überprüfen, die Genauigkeit der X_train und X_test

Der folgende code funktioniert für mich in meinem classification problem in multi-Label-Klasse

import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.svm import LinearSVC
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.multiclass import OneVsRestClassifier

X_train = np.array(["new york is a hell of a town",
                    "new york was originally dutch",
                    "the big apple is great",
                    "new york is also called the big apple",
                    "nyc is nice",
                    "people abbreviate new york city as nyc",
                    "the capital of great britain is london",
                    "london is in the uk",
                    "london is in england",
                    "london is in great britain",
                    "it rains a lot in london",
                    "london hosts the british museum",
                    "new york is great and so is london",
                    "i like london better than new york"])
y_train = [[0],[0],[0],[0]
            ,[0],[0],[1],[1]
            ,[1],[1],[1],[1]
            ,[2],[2]]
X_test = np.array(['nice day in nyc',
                   'the capital of great britain is london',
                   'i like london better than new york',
                   ])   
target_names = ['Class 1', 'Class 2','Class 3']

classifier = Pipeline([
    ('vectorizer', CountVectorizer(min_df=1,max_df=2)),
    ('tfidf', TfidfTransformer()),
    ('clf', OneVsRestClassifier(LinearSVC()))])
classifier.fit(X_train, y_train)
predicted = classifier.predict(X_test)
for item, labels in zip(X_test, predicted):
    print '%s => %s' % (item, ', '.join(target_names[x] for x in labels))

AUSGABE

nice day in nyc => Class 1
the capital of great britain is london => Class 2
i like london better than new york => Class 3

Möchte ich überprüfen die Genauigkeit zwischen Trainings-und Test-Datensatz.
Score-Funktion bei mir nicht funktioniert, es zeigt eine Fehlermeldung, die besagt, dass multilabel-Wert kann nicht akzeptiert

>>> classifier.score(X_train, X_test)

NotImplementedError: score wird nicht unterstützt für multilabel-Klassifikatoren

Freundlicherweise mir helfen, die Genauigkeit der Ergebnisse für Schulungs-und test-Daten, und wählen Sie einen Algorithmus für unsere Klassifizierung Fall.

InformationsquelleAutor user_az | 2013-10-28
Schreibe einen Kommentar