<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import math <EOL> import matplotlib . pyplot as plt <EOL> from windml . datasets . nrel import NREL <EOL> from windml . mapping . power_mapping import PowerMapping <EOL> from sklearn . grid_search import GridSearchCV <EOL> from sklearn . neighbors import KNeighborsRegressor <EOL> from sklearn . svm import SVR <EOL> from sklearn . metrics import mean_squared_error <EOL> def compute_mse ( regressor , horizon ) : <EOL> windpark = NREL ( ) . get_windpark ( NREL . park_id [ '<STR_LIT>' ] , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> ) <EOL> target = windpark . get_target ( ) <EOL> feature_window = <NUM_LIT:3> <EOL> mapping = PowerMapping ( ) <EOL> X = mapping . get_features_park ( windpark , feature_window , horizon ) <EOL> y = mapping . get_labels_turbine ( target , feature_window , horizon ) <EOL> train_to = int ( math . floor ( len ( X ) * <NUM_LIT:0.5> ) ) <EOL> test_to = len ( X ) <EOL> train_step , test_step = <NUM_LIT> , <NUM_LIT> <EOL> X_train = X [ : train_to : train_step ] <EOL> y_train = y [ : train_to : train_step ] <EOL> X_test = X [ train_to : test_to : test_step ] <EOL> y_test = y [ train_to : test_to : test_step ] <EOL> if ( regressor == '<STR_LIT>' ) : <EOL> reg = SVR ( kernel = '<STR_LIT>' , epsilon = <NUM_LIT:0.1> , C = <NUM_LIT> , gamma = <NUM_LIT> ) . fit ( X_train , y_train ) <EOL> mse = mean_squared_error ( reg . predict ( X_test ) , y_test ) <EOL> elif ( regressor == '<STR_LIT>' ) : <EOL> reg = KNeighborsRegressor ( <NUM_LIT:10> , '<STR_LIT>' ) . fit ( X_train , y_train ) <EOL> mse = mean_squared_error ( reg . predict ( X_test ) , y_test ) <EOL> return mse <EOL> regressors = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> horizons = range ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:2> ) <EOL> errors = { } <EOL> for regressor in regressors : <EOL> errors [ regressor ] = [ ] <EOL> for horizon in horizons : <EOL> errors [ regressor ] . append ( compute_mse ( regressor , horizon ) ) <EOL> print "<STR_LIT>" , errors [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" , errors [ '<STR_LIT>' ] <EOL> with plt . style . context ( "<STR_LIT>" ) : <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:8> , <NUM_LIT:5> ) ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> N = len ( horizons ) <EOL> ind = np . arange ( N ) <EOL> width = <NUM_LIT> <EOL> ax . set_xticks ( ind + width ) <EOL> ax . set_xticklabels ( [ str ( i ) for i in horizons ] ) <EOL> rects1 = ax . bar ( ind , errors [ '<STR_LIT>' ] , width , color = '<STR_LIT>' ) <EOL> rects2 = ax . bar ( ind + width , errors [ '<STR_LIT>' ] , width , color = '<STR_LIT>' ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . legend ( loc = '<STR_LIT>' ) <EOL> plt . tight_layout ( ) <EOL> plt . show ( ) </s>
