<s> """<STR_LIT>""" <EOL> from time import time <EOL> import numpy as np <EOL> from sklearn . datasets import load_digits <EOL> from sklearn . cross_validation import train_test_split <EOL> from sklearn . svm import LinearSVC <EOL> from pystruct . models import MultiClassClf <EOL> from pystruct . learners import ( NSlackSSVM , OneSlackSSVM , <EOL> SubgradientSSVM , FrankWolfeSSVM ) <EOL> digits = load_digits ( ) <EOL> X , y = digits . data , digits . target <EOL> X = X / <NUM_LIT> <EOL> X_train , X_test , y_train , y_test = train_test_split ( X , y ) <EOL> X_train_bias = np . hstack ( [ X_train , np . ones ( ( X_train . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ) ] ) <EOL> X_test_bias = np . hstack ( [ X_test , np . ones ( ( X_test . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ) ] ) <EOL> model = MultiClassClf ( n_features = X_train_bias . shape [ <NUM_LIT:1> ] , n_classes = <NUM_LIT:10> ) <EOL> n_slack_svm = NSlackSSVM ( model , verbose = <NUM_LIT:2> , check_constraints = False , C = <NUM_LIT:0.1> , <EOL> batch_size = <NUM_LIT:100> , tol = <NUM_LIT> ) <EOL> one_slack_svm = OneSlackSSVM ( model , verbose = <NUM_LIT:2> , C = <NUM_LIT> , tol = <NUM_LIT> ) <EOL> subgradient_svm = SubgradientSSVM ( model , C = <NUM_LIT:0.1> , learning_rate = <NUM_LIT> , <EOL> max_iter = <NUM_LIT:1000> , verbose = <NUM_LIT:0> ) <EOL> fw_bc_svm = FrankWolfeSSVM ( model , C = <NUM_LIT> , max_iter = <NUM_LIT:50> ) <EOL> fw_batch_svm = FrankWolfeSSVM ( model , C = <NUM_LIT> , max_iter = <NUM_LIT:50> , batch_mode = True ) <EOL> start = time ( ) <EOL> n_slack_svm . fit ( X_train_bias , y_train ) <EOL> time_n_slack_svm = time ( ) - start <EOL> y_pred = np . hstack ( n_slack_svm . predict ( X_test_bias ) ) <EOL> print ( "<STR_LIT>" <EOL> % ( np . mean ( y_pred == y_test ) , time_n_slack_svm ) ) <EOL> start = time ( ) <EOL> one_slack_svm . fit ( X_train_bias , y_train ) <EOL> time_one_slack_svm = time ( ) - start <EOL> y_pred = np . hstack ( one_slack_svm . predict ( X_test_bias ) ) <EOL> print ( "<STR_LIT>" <EOL> % ( np . mean ( y_pred == y_test ) , time_one_slack_svm ) ) <EOL> start = time ( ) <EOL> subgradient_svm . fit ( X_train_bias , y_train ) <EOL> time_subgradient_svm = time ( ) - start <EOL> y_pred = np . hstack ( subgradient_svm . predict ( X_test_bias ) ) <EOL> print ( "<STR_LIT>" <EOL> % ( np . mean ( y_pred == y_test ) , time_subgradient_svm ) ) <EOL> libsvm = LinearSVC ( multi_class = '<STR_LIT>' , C = <NUM_LIT> ) <EOL> start = time ( ) <EOL> libsvm . fit ( X_train , y_train ) <EOL> time_libsvm = time ( ) - start <EOL> print ( "<STR_LIT>" <EOL> % ( libsvm . score ( X_test , y_test ) , time_libsvm ) ) <EOL> start = time ( ) <EOL> fw_bc_svm . fit ( X_train_bias , y_train ) <EOL> y_pred = np . hstack ( fw_bc_svm . predict ( X_test_bias ) ) <EOL> time_fw_bc_svm = time ( ) - start <EOL> print ( "<STR_LIT>" % <EOL> ( np . mean ( y_pred == y_test ) , time_fw_bc_svm ) ) <EOL> start = time ( ) <EOL> fw_batch_svm . fit ( X_train_bias , y_train ) <EOL> y_pred = np . hstack ( fw_batch_svm . predict ( X_test_bias ) ) <EOL> time_fw_batch_svm = time ( ) - start <EOL> print ( "<STR_LIT>" % <EOL> ( np . mean ( y_pred == y_test ) , time_fw_batch_svm ) ) </s>
