<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import numpy as np <EOL> from sklearn import linear_model <EOL> n_samples_train , n_samples_test , n_features = <NUM_LIT> , <NUM_LIT> , <NUM_LIT> <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> coef = np . random . randn ( n_features ) <EOL> coef [ <NUM_LIT:50> : ] = <NUM_LIT:0.0> <EOL> X = np . random . randn ( n_samples_train + n_samples_test , n_features ) <EOL> y = np . dot ( X , coef ) <EOL> X_train , X_test = X [ : n_samples_train ] , X [ n_samples_train : ] <EOL> y_train , y_test = y [ : n_samples_train ] , y [ n_samples_train : ] <EOL> alphas = np . logspace ( - <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> enet = linear_model . ElasticNet ( l1_ratio = <NUM_LIT> ) <EOL> train_errors = list ( ) <EOL> test_errors = list ( ) <EOL> for alpha in alphas : <EOL> enet . set_params ( alpha = alpha ) <EOL> enet . fit ( X_train , y_train ) <EOL> train_errors . append ( enet . score ( X_train , y_train ) ) <EOL> test_errors . append ( enet . score ( X_test , y_test ) ) <EOL> i_alpha_optim = np . argmax ( test_errors ) <EOL> alpha_optim = alphas [ i_alpha_optim ] <EOL> print ( "<STR_LIT>" % alpha_optim ) <EOL> enet . set_params ( alpha = alpha_optim ) <EOL> coef_ = enet . fit ( X , y ) . coef_ <EOL> import matplotlib . pyplot as plt <EOL> plt . subplot ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> plt . semilogx ( alphas , train_errors , label = '<STR_LIT>' ) <EOL> plt . semilogx ( alphas , test_errors , label = '<STR_LIT>' ) <EOL> plt . vlines ( alpha_optim , plt . ylim ( ) [ <NUM_LIT:0> ] , np . max ( test_errors ) , color = '<STR_LIT:k>' , <EOL> linewidth = <NUM_LIT:3> , label = '<STR_LIT>' ) <EOL> plt . legend ( loc = '<STR_LIT>' ) <EOL> plt . ylim ( [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> plt . xlabel ( '<STR_LIT>' ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> plt . subplot ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> plt . plot ( coef , label = '<STR_LIT>' ) <EOL> plt . plot ( coef_ , label = '<STR_LIT>' ) <EOL> plt . legend ( ) <EOL> plt . subplots_adjust ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> plt . show ( ) </s>
