<s> import scipy . io as sio <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> from scipy . optimize import minimize <EOL> from common_functions import add_zero_feature , cf_lr as cost_function , gf_lr as grad_function , cf_lr_reg as cost_function_reg , gf_lr_reg as grad_function_reg <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> data = sio . loadmat ( '<STR_LIT>' ) <EOL> y = data [ '<STR_LIT:y>' ] <EOL> X = data [ '<STR_LIT:X>' ] <EOL> y = y % <NUM_LIT:10> <EOL> n_sampels = <NUM_LIT:100> <EOL> sampels = np . random . choice ( len ( X ) , n_sampels ) <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> fig . subplots_adjust ( left = <NUM_LIT:0> , right = <NUM_LIT:1> , bottom = <NUM_LIT:0> , top = <NUM_LIT:1> , hspace = <NUM_LIT> , wspace = <NUM_LIT> ) <EOL> for i , j in enumerate ( sampels ) : <EOL> ax = fig . add_subplot ( <NUM_LIT:10> , <NUM_LIT:10> , i + <NUM_LIT:1> , xticks = [ ] , yticks = [ ] ) <EOL> ax . imshow ( X [ j , : ] . reshape ( <NUM_LIT:20> , <NUM_LIT:20> ) . T , cmap = plt . cm . binary , interpolation = '<STR_LIT>' ) <EOL> ax . text ( <NUM_LIT:0> , <NUM_LIT:7> , str ( y [ j , <NUM_LIT:0> ] ) ) <EOL> plt . show ( ) <EOL> num_labels = <NUM_LIT:10> <EOL> X = add_zero_feature ( X ) <EOL> m , n = X . shape <EOL> initial_theta = np . ones ( ( n , <NUM_LIT:1> ) ) <EOL> all_theta = np . vstack ( [ minimize ( cost_function , initial_theta , method = '<STR_LIT>' , jac = grad_function , options = { '<STR_LIT>' : True , '<STR_LIT>' : <NUM_LIT:100> } , <EOL> args = ( X , ( y == i ) . astype ( int ) ) ) . x for i in range ( num_labels ) ] ) <EOL> y_pred = np . argmax ( np . dot ( X , all_theta . T ) , axis = <NUM_LIT:1> ) <EOL> print '<STR_LIT>' . format ( np . mean ( y_pred == y . ravel ( ) ) * <NUM_LIT:100> ) <EOL> lambda_coef = <NUM_LIT:0.1> <EOL> all_theta = np . vstack ( [ minimize ( cost_function_reg , initial_theta , method = '<STR_LIT>' , jac = grad_function_reg , options = { '<STR_LIT>' : True , '<STR_LIT>' : <NUM_LIT:100> } , <EOL> args = ( X , ( y == i ) . astype ( int ) , lambda_coef ) ) . x for i in range ( num_labels ) ] ) <EOL> y_pred = np . argmax ( np . dot ( X , all_theta . T ) , axis = <NUM_LIT:1> ) <EOL> print '<STR_LIT>' . format ( np . mean ( y_pred == y . ravel ( ) ) * <NUM_LIT:100> ) </s>
