local_x, global_x, y, tag = cPickle.load( open(alignedFeaturesFilename, 'rb')) y = label_binarize(y, classes=range(7)) n_classes = 7 print("Training SVM") TIMES = 100 l = [] for i in range(TIMES): print '\rFitting %d/%d ' % (i, TIMES), sys.stdout.flush() # resampling classifier = OneVsRestClassifier( svm.SVC(kernel=multichannel_wrapper(2, chi_square_kernel), probability=True)) X_train, X_test, y_train, y_test = train_test_split( local_x, global_x, y, tag) y_score = classifier.fit(X_train, y_train).decision_function(X_test) l.append( float((y_test.argmax(1) == y_score.argmax(1)).sum()) / y_score.shape[0] * 100) print map(lambda x: '%.3f%%' % x, l), '=', np.mean(l) y_score = classifier.decision_function(x) print 'Test all = %.3f%%' % (float( (y.argmax(1) == y_score.argmax(1)).sum()) / y_score.shape[0] * 100) if True:
y = np.array(y, dtype=int)-1 y = label_binarize(y, classes=range(7)) n_classes = 7 X_train, X_test, y_train, y_test = train_test_split(x, y, tag) print("Training SVM") TIMES = 10 l = [] for i in range(TIMES): print '\rFitting %d/%d ' % (i, TIMES), sys.stdout.flush() # resampling classifier = OneVsRestClassifier(svm.SVC(kernel=multichannel_wrapper(2, chi_square_kernel), probability=True)) X_train, X_test, y_train, y_test = train_test_split(x, y, tag) y_score = classifier.fit(X_train, y_train).decision_function(X_test) l.append(float((y_test.argmax(1) == y_score.argmax(1)).sum())/y_score.shape[0]*100) print map(lambda x: '%.3f%%' % x, l), '=', np.mean(l) y_score = classifier.decision_function(x) print 'Test all = %.3f%%' % (float((y.argmax(1) == y_score.argmax(1)).sum())/y_score.shape[0]*100 ) if True: import matplotlib.pyplot as plt from sklearn.metrics import precision_recall_curve from sklearn.metrics import average_precision_score # Compute Precision-Recall and plot curve