<s> import numpy as np <EOL> from theano import tensor as T <EOL> import theano <EOL> from sklearn . datasets import make_classification <EOL> from sklearn . cross_validation import train_test_split <EOL> from sklearn . metrics import classification_report <EOL> rng = np . random . RandomState ( <NUM_LIT> ) <EOL> X , y = make_classification ( n_samples = <NUM_LIT> , n_features = <NUM_LIT> , n_informative = <NUM_LIT:10> , <EOL> n_classes = <NUM_LIT:2> , n_clusters_per_class = <NUM_LIT:2> , <EOL> random_state = <NUM_LIT> ) <EOL> X_train , X_test , y_train , y_test = train_test_split ( X , y , train_size = <NUM_LIT> ) <EOL> n_samples , n_features = X_train . shape <EOL> x = T . matrix ( '<STR_LIT:x>' ) <EOL> y = T . vector ( '<STR_LIT:y>' ) <EOL> w = theano . shared ( rng . randn ( n_features ) , name = '<STR_LIT:w>' ) <EOL> b = theano . shared ( <NUM_LIT:0.> , name = '<STR_LIT:b>' ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( w . get_value ( ) , b . get_value ( ) ) <EOL> learning_rate = <NUM_LIT> <EOL> reg = <NUM_LIT> <EOL> n_iter = <NUM_LIT> <EOL> prob = <NUM_LIT:1> / ( <NUM_LIT:1> + T . exp ( - T . dot ( x , w ) - b ) ) <EOL> pred = prob > <NUM_LIT:0.5> <EOL> loss = - y * T . log ( prob ) - ( <NUM_LIT:1> - y ) * T . log ( <NUM_LIT:1> - prob ) <EOL> penalty = reg * abs ( w ) . sum ( ) <EOL> cost = loss . mean ( ) + penalty <EOL> gw , gb = T . grad ( cost , [ w , b ] ) <EOL> train = theano . function ( inputs = [ x , y ] , outputs = [ pred , loss ] , <EOL> updates = ( ( w , w - learning_rate * gw ) , <EOL> ( b , b - learning_rate * gb ) ) ) <EOL> predict = theano . function ( inputs = [ x ] , outputs = pred ) <EOL> for i in range ( n_iter ) : <EOL> pred , err = train ( X_train , y_train ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( w . get_value ( ) , b . get_value ( ) ) <EOL> print ( "<STR_LIT>" ) <EOL> y_pred = predict ( X_test ) <EOL> report = classification_report ( y_test , y_pred ) <EOL> print ( report ) </s>
