<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from sklearn . metrics import r2_score <EOL> np . random . seed ( <NUM_LIT> ) <EOL> n_samples , n_features = <NUM_LIT:50> , <NUM_LIT:200> <EOL> X = np . random . randn ( n_samples , n_features ) <EOL> coef = <NUM_LIT:3> * np . random . randn ( n_features ) <EOL> inds = np . arange ( n_features ) <EOL> np . random . shuffle ( inds ) <EOL> coef [ inds [ <NUM_LIT:10> : ] ] = <NUM_LIT:0> <EOL> y = np . dot ( X , coef ) <EOL> y += <NUM_LIT> * np . random . normal ( ( n_samples , ) ) <EOL> n_samples = X . shape [ <NUM_LIT:0> ] <EOL> X_train , y_train = X [ : n_samples / <NUM_LIT:2> ] , y [ : n_samples / <NUM_LIT:2> ] <EOL> X_test , y_test = X [ n_samples / <NUM_LIT:2> : ] , y [ n_samples / <NUM_LIT:2> : ] <EOL> from sklearn . linear_model import Lasso <EOL> alpha = <NUM_LIT:0.1> <EOL> lasso = Lasso ( alpha = alpha ) <EOL> y_pred_lasso = lasso . fit ( X_train , y_train ) . predict ( X_test ) <EOL> r2_score_lasso = r2_score ( y_test , y_pred_lasso ) <EOL> print ( lasso ) <EOL> print ( "<STR_LIT>" % r2_score_lasso ) <EOL> from sklearn . linear_model import ElasticNet <EOL> enet = ElasticNet ( alpha = alpha , l1_ratio = <NUM_LIT> ) <EOL> y_pred_enet = enet . fit ( X_train , y_train ) . predict ( X_test ) <EOL> r2_score_enet = r2_score ( y_test , y_pred_enet ) <EOL> print ( enet ) <EOL> print ( "<STR_LIT>" % r2_score_enet ) <EOL> plt . plot ( enet . coef_ , color = '<STR_LIT>' , linewidth = <NUM_LIT:2> , <EOL> label = '<STR_LIT>' ) <EOL> plt . plot ( lasso . coef_ , color = '<STR_LIT>' , linewidth = <NUM_LIT:2> , <EOL> label = '<STR_LIT>' ) <EOL> plt . plot ( coef , '<STR_LIT>' , color = '<STR_LIT>' , label = '<STR_LIT>' ) <EOL> plt . legend ( loc = '<STR_LIT>' ) <EOL> plt . title ( "<STR_LIT>" <EOL> % ( r2_score_lasso , r2_score_enet ) ) <EOL> plt . show ( ) </s>
