In [1]:
import logging
from sklearn.datasets import fetch_rcv1
from sklearn.multiclass import OneVsRestClassifier
from sklearn.metrics import f1_score, precision_score, recall_score
from sklearn.pipeline import Pipeline
from sklearn import svm
logging.basicConfig()
rcv1 = fetch_rcv1()
In [2]:
training_samples = 23149
X_train = rcv1.data[:training_samples]
X_test = rcv1.data[training_samples:]
y_train = rcv1.target[:training_samples]
y_test = rcv1.target[training_samples:]
In [3]:
clf = OneVsRestClassifier(svm.LinearSVC(penalty='l1',tol=0.01,multi_class='crammer_singer',dual=False))
In [4]:
clf.fit(X_train,y_train)
Out[4]:
In [5]:
y_pred = clf.predict(X_test)
current_score = f1_score(y_test,y_pred,average='micro')
In [6]:
current_score
Out[6]: