<s> "<STR_LIT>" <EOL> import pandas as pd <EOL> import numpy as np <EOL> import math <EOL> import csv <EOL> import hyperopt <EOL> import os <EOL> import sys <EOL> from time import time <EOL> from glob import glob <EOL> from math import log <EOL> from hyperopt import hp , fmin , tpe <EOL> from elm import * <EOL> from random_layer import * <EOL> from sklearn import pipeline <EOL> from sklearn . linear_model import Ridge <EOL> from sklearn . metrics import mean_squared_error as MSE <EOL> from sklearn . preprocessing import StandardScaler as Scaler <EOL> def RMSE ( y , p ) : <EOL> return math . sqrt ( MSE ( y , p ) ) <EOL> def relu ( x ) : <EOL> return np . maximum ( <NUM_LIT:0> , x ) <EOL> input_file = '<STR_LIT>' <EOL> try : <EOL> output_file = sys . argv [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> output_file = '<STR_LIT>' <EOL> data = pd . read_csv ( input_file ) <EOL> train = data [ <NUM_LIT:0> : <NUM_LIT> ] <EOL> test = data [ <NUM_LIT> : ] <EOL> x_train = train [ [ c for c in train . columns if c != '<STR_LIT>' ] ] <EOL> x_test = test [ [ c for c in train . columns if c != '<STR_LIT>' ] ] <EOL> scaler = Scaler ( ) <EOL> x_train = scaler . fit_transform ( x_train ) <EOL> x_test = scaler . transform ( x_test ) <EOL> y_train = train [ '<STR_LIT>' ] <EOL> y_test = test [ '<STR_LIT>' ] <EOL> max_evals = <NUM_LIT:100> <EOL> run_counter = <NUM_LIT:0> <EOL> def run_wrapper ( params ) : <EOL> global run_counter <EOL> global o_f <EOL> run_counter += <NUM_LIT:1> <EOL> print "<STR_LIT>" , run_counter <EOL> s = time ( ) <EOL> rmse = run_test ( params ) <EOL> print <EOL> print "<STR_LIT>" , rmse <EOL> print "<STR_LIT>" . format ( int ( round ( time ( ) - s ) ) ) <EOL> writer . writerow ( [ rmse ] + list ( params ) ) <EOL> o_f . flush ( ) <EOL> return rmse <EOL> def run_test ( params ) : <EOL> n_hidden_1 , alpha_1 , rbf_width_1 , n_hidden_2 , alpha_2 , rbf_width_2 , ridge_alpha = params <EOL> n_hidden_1 = int ( n_hidden_1 ) <EOL> n_hidden_2 = int ( n_hidden_2 ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , n_hidden_1 <EOL> print "<STR_LIT>" , alpha_1 <EOL> print "<STR_LIT>" , rbf_width_1 <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , n_hidden_2 <EOL> print "<STR_LIT>" , alpha_2 <EOL> print "<STR_LIT>" , rbf_width_2 <EOL> print <EOL> print "<STR_LIT>" , ridge_alpha <EOL> rl1 = RandomLayer ( n_hidden = n_hidden_1 , alpha = alpha_1 , <EOL> rbf_width = rbf_width_1 , activation_func = relu ) <EOL> rl2 = RandomLayer ( n_hidden = n_hidden_2 , alpha = alpha_2 , <EOL> rbf_width = rbf_width_2 , activation_func = relu ) <EOL> ridge = Ridge ( alpha = ridge_alpha ) <EOL> elmr = pipeline . Pipeline ( [ ( '<STR_LIT>' , rl1 ) , ( '<STR_LIT>' , rl2 ) , ( '<STR_LIT>' , ridge ) ] ) <EOL> elmr . fit ( x_train , y_train ) <EOL> p = elmr . predict ( x_test ) <EOL> rmse = RMSE ( y_test , p ) <EOL> return rmse <EOL> space = ( <EOL> hp . qloguniform ( '<STR_LIT>' , log ( <NUM_LIT:10> ) , log ( <NUM_LIT:1000> ) , <NUM_LIT:1> ) , <EOL> hp . uniform ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> hp . loguniform ( '<STR_LIT>' , log ( <NUM_LIT> ) , log ( <NUM_LIT:100> ) ) , <EOL> hp . qloguniform ( '<STR_LIT>' , log ( <NUM_LIT:10> ) , log ( <NUM_LIT:1000> ) , <NUM_LIT:1> ) , <EOL> hp . uniform ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> hp . loguniform ( '<STR_LIT>' , log ( <NUM_LIT> ) , log ( <NUM_LIT:100> ) ) , <EOL> hp . loguniform ( '<STR_LIT>' , - <NUM_LIT:15> , <NUM_LIT:5> ) <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> headers = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> o_f = open ( output_file , '<STR_LIT:wb>' ) <EOL> writer = csv . writer ( o_f ) <EOL> writer . writerow ( headers ) <EOL> start_time = time ( ) <EOL> best = fmin ( run_wrapper , space , algo = tpe . suggest , max_evals = max_evals ) <EOL> end_time = time ( ) <EOL> print "<STR_LIT>" , int ( round ( end_time - start_time ) ) <EOL> print best </s>
