<s> """<STR_LIT>""" <EOL> from matplotlib import dates <EOL> import matplotlib . pylab as plt <EOL> import datetime , time <EOL> import numpy as np <EOL> from numpy import array , matrix <EOL> from sklearn . grid_search import GridSearchCV <EOL> from sklearn . cross_validation import KFold <EOL> from sklearn import __version__ as sklearn_version <EOL> from sklearn . svm import SVR <EOL> from sklearn . neighbors import KNeighborsRegressor <EOL> from windml . datasets . nrel import NREL <EOL> from windml . visualization . plot_response_curve import plot_response_curve <EOL> ds = NREL ( ) <EOL> turbine = ds . get_turbine ( NREL . park_id [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> timeseries = turbine . get_measurements ( ) <EOL> max_speed = <NUM_LIT> <EOL> skip = <NUM_LIT:1> <EOL> speed = [ m [ <NUM_LIT:2> ] for m in timeseries [ : : skip ] ] <EOL> score = [ m [ <NUM_LIT:1> ] for m in timeseries [ : : skip ] ] <EOL> X_train = speed [ <NUM_LIT:0> : len ( speed ) : <NUM_LIT:1> ] <EOL> Y_train = score [ <NUM_LIT:0> : len ( score ) : <NUM_LIT:1> ] <EOL> X_train_array = array ( [ [ element ] for element in X_train ] ) <EOL> k_neighbors = <NUM_LIT:30> <EOL> knn = KNeighborsRegressor ( k_neighbors , '<STR_LIT>' ) <EOL> T = np . linspace ( <NUM_LIT:0> , max_speed , <NUM_LIT> ) [ : , np . newaxis ] <EOL> Y_hat = knn . fit ( X_train_array , Y_train ) . predict ( T ) <EOL> start_speed = <NUM_LIT:15> <EOL> threshold = <NUM_LIT> <EOL> elements = max_speed - start_speed <EOL> num_over_thres = np . zeros ( ( elements ) , dtype = np . int ) <EOL> num_below_thres = np . zeros ( ( elements ) , dtype = np . int ) <EOL> for i in range ( len ( X_train ) ) : <EOL> elem = <NUM_LIT:0> <EOL> for j in range ( start_speed , max_speed ) : <EOL> act_value = np . float32 ( j ) <EOL> if ( X_train [ i ] >= ( act_value ) and X_train [ i ] < ( act_value + <NUM_LIT:1.0> ) ) : <EOL> if ( Y_train [ i ] < threshold ) : <EOL> num_below_thres [ elem ] += <NUM_LIT:1> <EOL> else : <EOL> num_over_thres [ elem ] += <NUM_LIT:1> <EOL> elem += <NUM_LIT:1> <EOL> fraction = np . zeros ( max_speed , dtype = np . float32 ) <EOL> for i in range ( start_speed , len ( fraction ) ) : <EOL> if ( np . float32 ( num_below_thres [ i - start_speed ] + num_over_thres [ i - start_speed ] ) > <NUM_LIT:0> ) : <EOL> fraction [ i ] = np . float32 ( num_below_thres [ i - start_speed ] ) / ( num_below_thres [ i - start_speed ] + num_over_thres [ i - start_speed ] ) <EOL> else : <EOL> fraction [ i ] = - <NUM_LIT:1> <EOL> print fraction <EOL> figure = plt . figure ( figsize = ( <NUM_LIT:15> , <NUM_LIT:10> ) ) <EOL> plot_abs = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . scatter ( speed , score , color = "<STR_LIT:b>" ) <EOL> plt . xlim ( [ - <NUM_LIT:1> , max_speed ] ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylim ( [ - <NUM_LIT:2> , <NUM_LIT:32> ] ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plot_scatter = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . plot ( T , Y_hat , color = '<STR_LIT:b>' ) <EOL> plt . scatter ( speed , score , color = "<STR_LIT>" ) <EOL> plt . xlim ( [ - <NUM_LIT:1> , max_speed ] ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylim ( [ - <NUM_LIT:2> , <NUM_LIT:32> ] ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plot_abs = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . hist ( X_train , bins = np . float ( max_speed ) , histtype = '<STR_LIT>' , normed = True , color = '<STR_LIT:b>' ) <EOL> plt . xlim ( [ - <NUM_LIT:1> , max_speed ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plot_scatter = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> steps = range ( <NUM_LIT> ) <EOL> plt . plot ( steps , fraction , "<STR_LIT:o>" , color = '<STR_LIT:b>' ) <EOL> plt . xlim ( [ - <NUM_LIT:1> , max_speed ] ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylim ( [ - <NUM_LIT:0.1> , <NUM_LIT> ] ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . show ( ) </s>
