Kaggle competition: ASHRAE - Great Energy Predictor III
<SOS> metric: RMSLE Kaggle data source: ashrae-great-energy-predictor-iii<compute_test_metric>
import numpy as np
import sys
import pandas as pd
from skimage.io import imread, imsave
from skimage.color import gray2rgb
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
from functools import reduce
import os
test_loss, test_acc = model.evaluate(X_test_cnn, y_test_cnn, verbose=2)
 print('test loss:',test_loss)
 print('test acc:',test_acc )<import_modules>
sub = pd.read_csv(".. /input/ashrae-energy-prediction/sample_submission.csv" )
tf.__version__<import_modules>
hub.__version__<load_from_url>
df0 = pd.read_csv(".. /input/ashrae-public/ashrae-highway-kernel-route2.csv")
 df1 = pd.read_csv(".. /input/ashrae-public/ashrae-leak-validation-and-more.csv")
 df2 = pd.read_csv(".. /input/ashrae-public/ashrae-leak-validation-bruteforce-heuristic-search.csv")
 df3 = pd.read_csv(".. /input/ashrae-public/ashrae-may-make-it-up-to-1-0.csv")
 df4 = pd.read_csv(".. /input/ashrae-public/ashrae-maybe-this-can-make-public-lb-some-useful.csv")
 df5 = pd.read_csv(".. /input/ashrae-public/ashrae-simple-data-cleanup-lb-1-08-no-leaks.csv")
!wget --quiet https://raw.githubusercontent.com/tensorflow/models/master/official/nlp/bert/tokenization.py 
<import_modules>
blend1 = df0['meter_reading']*0.5 + df4['meter_reading']*0.3 + df5['meter_reading']*0.2
import tensorflow as tf
from tensorflow.keras.callbacks import ModelCheckpoint
import tensorflow_hub as hub
import tokenization<categorify>
sub['meter_reading'] = blend1
df11 = sub
def bert_encode(texts, bert_layer, max_len=128):
vocab_file = bert_layer.resolved_object.vocab_file.asset_path.numpy()
do_lower_case = bert_layer.resolved_object.do_lower_case.numpy()
tokenizer = tokenization.FullTokenizer(vocab_file, do_lower_case)
 all_tokens = []
all_masks = []
all_segments = []
for text in texts:
text = tokenizer.tokenize(text)
 text = text[:max_len - 2]
input_sequence = ["[CLS]"] + text + ["[SEP]"]
pad_len = max_len - len(input_sequence)
 tokens = tokenizer.convert_tokens_to_ids(input_sequence)
 input_ids = tokens + [0]* pad_len
all_tokens.append(input_ids)
 masks = [1]*len(input_sequence)+ [0]* pad_len
all_masks.append(masks)
 segments = [0]* max_len
all_segments.append(segments)
 return np.array(all_tokens), np.array(all_masks), np.array(all_segments)
 def build_model(bert_layer, max_len = 128, lr = 1e-5):
input_word_ids = tf.keras.layers.Input(shape=(max_len,), dtype=tf.int32,name="input_word_ids")
 input_mask = tf.keras.layers.Input(shape=(max_len,), dtype=tf.int32,name="input_mask")
 segment_ids = tf.keras.layers.Input(shape=(max_len,), dtype=tf.int32,name="segment_ids")
 pooled_output, sequence_output = bert_layer([input_word_ids, input_mask, segment_ids])
 dense_out = Dense(1,activation="relu" )(pooled_output)
 drop_out = tf.keras.layers.Dropout(0.8 )(dense_out)
 out = Dense(1,activation="sigmoid" )(pooled_output)
 model = Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=out)
 adam = tf.keras.optimizers.Adam(lr)
 model.compile(optimizer=adam, loss='binary_crossentropy', metrics=['accuracy'])
 return model
def plot_curve(history):
plt.plot(history.history['accuracy'], label='accuracy')
 plt.plot(history.history['val_accuracy'], label='val_accuracy')
 plt.xlabel('Epoch')
 plt.ylabel('Accuracy')
 plt.ylim([0.5,1])
 plt.legend()
plt.show()<choose_model_class>
blend2 = df11['meter_reading']*0.1 + df1['meter_reading']*0.15 + df2['meter_reading']*0.6 + df3['meter_reading']*0.15
%%time
module_url = "https://tfhub.dev/tensorflow/bert_en_uncased_L-24_H-1024_A-16/1"
bert_layer = hub.KerasLayer(module_url, trainable=True )<load_from_csv>
sub1 = pd.read_csv(".. /input/ashrae-energy-prediction/sample_submission.csv" )
train = pd.read_csv("/kaggle/input/nlp-getting-started/train.csv")
 train_input = bert_encode(train.text.values, bert_layer, max_len=128)
 train_labels = np.array(train.target )<load_from_csv>
sub1['meter_reading'] = blend2
sub1.head()
<save_to_csv><EOS> 
sub1.to_csv(f'submission.csv', index=False, float_format='%g' )