형상은 상이하다.
내가 찾을 수있는 가장 좋은 예는 found here on http://scikit-learn.org 될 수 있습니다
SVC 및 NuSVC은 "한 - 대한 - 하나"접근 방식을 구현하는 멀티 클래스 (Knerr 등, 1990). 분류. n_class
이 클래스 수인 경우 n_class * (n_class - 1)/2
분류자를 생성하고 및 각 클래스는 두 클래스의 데이터를 전달합니다. 다른 분류와 일치 인터페이스를 제공하기 위해, decision_function_shape
옵션 모양의 결정 함수에 "한 - 대한 - 하나"분류 의 결과를 집계 할 수 있습니다 (N_SAMPLES, n_classes)
>>> X = [[0], [1], [2], [3]]
>>> Y = [0, 1, 2, 3]
>>> clf = svm.SVC(decision_function_shape='ovo')
>>> clf.fit(X, Y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovo', degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
>>> dec = clf.decision_function([[1]])
>>> dec.shape[1] # 4 classes: 4*3/2 = 6
6
>>> clf.decision_function_shape = "ovr"
>>> dec = clf.decision_function([[1]])
>>> dec.shape[1] # 4 classes
4
이 말은 단순한 의미에서 무엇을 의미합니까?
n_class * (n_class - 1)/2
의 의미를 이해하려면 itertools.combinations
을 사용하여 2 종 조합을 생성하십시오.
def ovo_classifiers(classes):
import itertools
n_class = len(classes)
n = n_class * (n_class - 1)/2
combos = itertools.combinations(classes, 2)
return (n, list(combos))
>>> ovo_classifiers(['a', 'b', 'c'])
(3.0, [('a', 'b'), ('a', 'c'), ('b', 'c')])
>>> ovo_classifiers(['a', 'b', 'c', 'd'])
(6.0, [('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd')])
다중 레이블 분류에는 어떤 견적서를 사용해야합니까?
상황에 따라 StackOverflow의 여러 태그에 질문이 있습니다. 당신이-사전 태그 (클래스)를 알고 있다면, 내가 OneVsRestClassifier(LinearSVC())
제안 할 수 있지만 당신이 시도 할 수 DecisionTreeClassifier 또는 RandomForestClassifier (내 생각) :
import pandas as pd
from sklearn.preprocessing import MultiLabelBinarizer
from sklearn.svm import SVC, LinearSVC
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import Pipeline
from sklearn.multiclass import OneVsRestClassifier, OneVsOneClassifier
df = pd.DataFrame({
'Tags': [['python', 'pandas'], ['c#', '.net'], ['ruby'],
['python'], ['c#'], ['sklearn', 'python']],
'Questions': ['This is a post about python and pandas is great.',
'This is a c# post and i hate .net',
'What is ruby on rails?', 'who else loves python',
'where to learn c#', 'sklearn is a python package for machine learning']},
columns=['Questions', 'Tags'])
X = df['Questions']
mlb = MultiLabelBinarizer()
y = mlb.fit_transform(df['Tags'].values)
pipeline = Pipeline([
('vect', CountVectorizer(token_pattern='|'.join(mlb.classes_))),
('linear_svc', OneVsRestClassifier(LinearSVC()))
])
pipeline.fit(X, y)
final = pd.DataFrame(pipeline.predict(X), index=X, columns=mlb.classes_)
def predict(text):
return pd.DataFrame(pipeline.predict(text), index=text, columns=mlb.classes_)
test = ['is python better than c#', 'should i learn c#',
'should i learn sklearn or tensorflow',
'ruby or c# i am a dinosaur',
'is .net still relevant']
print(predict(test))
출력 :
.net c# pandas python ruby sklearn
is python better than c# 0 1 0 1 0 0
should i learn c# 0 1 0 0 0 0
should i learn sklearn or tensorflow 0 0 0 0 0 1
ruby or c# i am a dinosaur 0 1 0 0 1 0
is .net still relevant 1 0 0 0 0 0
당신은 모두를 시도하고 확인할 수있는 하나는 특정 데이터에 대해 더 나은 결과를 제공합니다. –