3

Im en utilisant le code suivant pour la classification des données multi-label: -Problèmes avec scikit sur des données multi-étiquettes

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 
from sklearn import preprocessing 

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_text = [[1],[1],[1],[1],[1],[1],[2],[2],[2],[2],[2],[2],[12],[12]] 

X_test = np.array(['nice day in nyc', 
        'welcome to london', 
        'london is rainy', 
        'it is raining in britian', 
        'it is raining in britian and the big apple', 
        'it is raining in britian and nyc', 
        'hello welcome to new york. enjoy it here and london too']) 
target_names = ['New York', 'London'] 

lb = preprocessing.MultiLabelBinarizer() 
Y = lb.fit_transform(y_train_text) 

classifier = Pipeline([ 
    ('vectorizer', CountVectorizer()), 
    ('tfidf', TfidfTransformer()), 
    ('clf', OneVsRestClassifier(LinearSVC()))]) 

classifier.fit(X_train, Y) 
predicted = classifier.predict(X_test) 

SORTIE ====== =====

[1, 0, 0],'New York' 
[0, 1, 0],'London' 
[0, 1, 0],'London' 
[0, 1, 0],'London' 
[1, 0, 0],'New York' 
[0, 0, 0], 
[0, 0, 0]] 

Les deux derniers sont faussement prédits, ils devraient tous deux être [0,0,1] pour ['New York', 'London']

J'ai donc ces questions: - 1.] Quel est le problème avec mon code 2.] Est-ce une propriété r moyen de gérer les données "multi-labels"? Ou y a-t-il une autre meilleure approche? Parce que ceci et un code ou deux sont tout ce que j'ai pu trouver sur internet à propos des données "Multi-label". Alors que pour la classification binaire il y en a des milliers. S'il vous plaît aidez-moi sur ce

Répondre

1

12 n'est pas "1" et "2" il est douze, ainsi

[[1],[1],[1],[1],[1],[1],[2],[2],[2],[2],[2],[2],[12],[12]] 

devrait être

[[1],[1],[1],[1],[1],[1],[2],[2],[2],[2],[2],[2],[1, 2],[1, 2]]