Skip to content

Instantly share code, notes, and snippets.

View arjay55's full-sized avatar

Arjeus Guevarra arjay55

View GitHub Profile
@arjay55
arjay55 / target_validation.py
Created August 25, 2019 06:55
target_validation
_,optvalues,resobj=load('hyperparam_best.joblib')
outparams=linkopt(['input_layer','hidden_1','navpu_infl','uni_reg','dropout_rate','hidden_reg'],optvalues)
acc_sigma=np.min(resobj.func_vals) #target validation error
@arjay55
arjay55 / discount_loss.py
Created August 24, 2019 14:43
discount_loss
ct = 0
for _ in test_data:
ct += 1
powcoeffs = np.arange(ct)
loss_base = np.full(ct,0.9)
loss_array = np.power(loss_base, powcoeffs)
@arjay55
arjay55 / multistep_compare.py
Created August 24, 2019 14:23
multistep_compare
for _, test in test_data:
predictions = model.predict(tf.boolean_mask(
reshape_sample, boolmask, axis=1))
y_pred.append(predictions[0][0])
y_true.append(test[0][0])
reshape_sample = np.roll(reshape_sample, -1, axis=1)
reshape_sample[0][-1] = predictions
@arjay55
arjay55 / Optimization_command.py
Created August 24, 2019 08:39
Optimization_command
res = gp_minimize(objective, # the function to minimize
space, # the bounds on each dimension of x
acq_func="LCB", # the acquisition function
n_calls=78, # the number of evaluations of f #78
n_random_starts=5, # the number of random initialization points
random_state=0) # the random seed
@arjay55
arjay55 / Hyperparams_list.py
Created August 24, 2019 08:13
Hyperparams
space = [Integer(2, 21, name='input_layer'), #number of neurons in input layer
Integer(1,3, name='hidden_1'), #number of neurons in the 1st hidden layer
Real(0.0, 0.3, name='navpu_infl'), #adjustment of class weighting in the mutual_unit(navpu) and the inflation.
Real(0.0, 0.8, name='uni_reg'), # regularization factor in the 1st hidden layer
Real(0.0, 0.5, name='dropout_rate'), #dropout fraction on the weights outside the 1st hidden layer
Real(0.0, 0.8, name='hidden_reg'), #regularization at the final layer
]
@arjay55
arjay55 / Masking.py
Created August 24, 2019 03:43
Masking_example
masked_indices=kwargs.pop('masked_indices',[4,6,7,9,10,11,12,14,15])
boolmask=np.full(est_period,True)
boolmask[masked_indices]=False
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(kwargs.pop('input_layer',7),
input_shape=(tf.boolean_mask(train_data[0][0],boolmask,axis=1).shape[1],
train_data[0][0].shape[2]),
kernel_initializer='he_normal',
kernel_regularizer=tf.keras.regularizers.l1(
@arjay55
arjay55 / Train_test.py
Created August 22, 2019 08:25
Creation of train/test datasets.
def form_dataset(normalized_data, est_period, **kwargs):
percent_validation = kwargs.pop('percent_validation', 0.8)
rel_norm=normalized_data
# end_index=(int(((rel_norm.shape[0]-est_period)*0.9)//batch_size))*batch_size-2
# batch size to be changed to 1
# end_index_test=(
@arjay55
arjay55 / correl.py
Created August 20, 2019 11:49
Correl1
dfcorr = dfrel.corr()
heatmap(dfrel.corr())
@arjay55
arjay55 / R_auto_arima.r
Last active August 20, 2019 04:21
R_auto_arima
model = auto.arima(ts(data$inflation,frequency = 1),seasonal = FALSE,stepwise=FALSE,
approximation = TRUE, max.p = myp, max.q = myq, max.P = myp,
max.Q = myq, max.d = 4, max.D=4,
max.order=120, num.cores = 3,parallel = TRUE)
flength=15
fcast_no_holdout <- forecast(model,flength)
@arjay55
arjay55 / Filling_nans2.py
Created August 19, 2019 15:55
Filling_nans2
dftemp = pd.read_csv('pb_forecast_f.csv', index_col=None)
get_outernan(dfrel.loc[:, 'inflation']) #gets the x and y values
dfrel.iloc[-15:, 2] = dftemp.loc[:, 'Point Forecast'].values
dftemp = pd.read_csv('pb_forecast_b.csv', index_col=None)
dfrel.iloc[:5, 2][::-1] = dftemp.loc[:, 'Point Forecast'].values
dfrel.iloc[:5, 2][::-1] = dftemp.loc[:, 'Point Forecast'].values
fill_data(dfrel) #fills the missing data through forward, backwards fill, and linear interpolation