Kaggle competition: ASHRAE - Great Energy Predictor III
<SOS> metric: RMSLE Kaggle data source: ashrae-great-energy-predictor-iii<define_search_space>
warnings.filterwarnings('ignore')
pipelines = [Pipeline([('xgb', xgb)]),
Pipeline([('tree', tree)]),
Pipeline([('ada', ada)]),
Pipeline([('grad', grad)])]
getd = [
{'xgb__max_depth': sp.stats.randint(1, 11),
'xgb__n_estimators': [100, 200, 500, 1000],
'xgb__colsample_bytree': [0.5,0.6,0.7,0.8]}
,{'tree__n_estimators': [100, 200, 500, 1000],
'tree__min_samples_split':[2, 4, 8, 10],
'tree__min_samples_leaf': [1, 2, 3, 4]}
,{'ada__learning_rate': [0.3, 0.4,0.5,0.7,1],
'ada__n_estimators': [10, 50, 100, 500]}
,{'grad__learning_rate': [0.1,0.2,0.5,1],
'grad__max_depth': [3,5,7],
'grad__n_estimators': [1, 2, 3, 4]}
]
warnings.filterwarnings('ignore')
 for i in range(len(pipelines)) :
print(get_scores_and_params(pipelines[i], getd[i])) 
<train_model>
test = pd.read_csv('.. /input/ashrae-energy-prediction/test.csv', index_col=0, parse_dates = ['timestamp'])
 building = pd.read_csv('.. /input/ashrae-energy-prediction/building_metadata.csv', usecols=['site_id', 'building_id'] )
features = feat_imp[:40].index
print(features )<drop_column>
test = test.merge(building, left_on = "building_id", right_on = "building_id", how = "left" )
X_train = X_train[features]
X_test = X_test[features]
X_valid = X_valid[features]<prepare_x_and_y>
submission_base = pd.read_csv('.. /input/ashrae-kfold-lightgbm-without-leak-1-08/submission.csv', index_col=0 )
X_train
df = df[df.line_race != 0]<compute_train_metric>
submission = submission_base.copy()
clf.fit(X_train, y_train)
 preds = clf.predict(X_test)
 val_pred = clf.predict(X_valid)
 roc_auc_score(y_test, preds), roc_auc_score(y_valid, val_pred )<predict_on_test>
site_0 = pd.read_csv('.. /input/new-ucf-starter-kernel/submission_ucf_replaced.csv', index_col=0)
 submission.loc[test[test['site_id']==0].index, 'meter_reading'] = site_0['meter_reading']
del site_0
gc.collect()
pros = clf.predict(data_for_sub[features] )<save_to_csv>
with open('.. /usr/lib/ucl_data_leakage_episode_2/site1.pkl', 'rb')as f:
site_1 = pickle.load(f)
 site_1 = site_1[site_1['timestamp'].dt.year > 2016]
sub = pd.DataFrame()
sub['ID'] = test_data['ID']
sub['target'] = pros
sub.to_csv('submission.csv',index=False)
 test = pd.read_csv('submission.csv')
 test.head()<import_modules>
t = test[['building_id', 'meter', 'timestamp']]
t['row_id'] = t.index
site_1 = site_1.merge(t, left_on = ['building_id', 'meter', 'timestamp'], right_on = ['building_id', 'meter', 'timestamp'], how = "left")
 site_1 = site_1[['meter_reading_scraped', 'row_id']].set_index('row_id' ).dropna()
submission.loc[site_1.index, 'meter_reading'] = site_1['meter_reading_scraped']
del site_1
gc.collect()
import numpy as np
import pandas as pd
import pydicom
import os
import random
import matplotlib.pyplot as plt
from tqdm import tqdm
from PIL import Image
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import KFold<import_modules>
site_2 = pd.read_csv('.. /input/asu-buildings-energy-consumption/asu_2016-2018.csv', parse_dates = ['timestamp'])
 site_2 = site_2[site_2['timestamp'].dt.year > 2016]
import tensorflow as tf
import tensorflow.keras.backend as K
import tensorflow.keras.layers as L
import tensorflow.keras.models as M<define_variables>
t = test[['building_id', 'meter', 'timestamp']]
t['row_id'] = t.index
site_2 = site_2.merge(t, left_on = ['building_id', 'meter', 'timestamp'], right_on = ['building_id', 'meter', 'timestamp'], how = "left")
 site_2 = site_2[['meter_reading', 'row_id']].set_index('row_id' ).dropna()
submission.loc[site_2.index, 'meter_reading'] = site_2['meter_reading']
del site_2
gc.collect()
def seed_everything(seed=2020):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 tf.random.set_seed(seed)
 seed_everything(42 )<define_variables>
site_4 = pd.read_csv('.. /input/ucb-data-leakage-site-4/site4.csv' )
<load_from_csv><EOS> 
submission.to_csv('submission.csv' )