<jupyter_start><jupyter_text><jupyter_code># Mount Google Drive
from google.colab import drive # import drive from google colab

ROOT = "/content/drive"     # default location for the drive
print(ROOT)                 # print content of ROOT (Optional)

drive.mount(ROOT)           # we mount the google drive at /content/drive
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
# numpy
import numpy
print('numpy: %s' % numpy.__version__)
# matplotlib
import matplotlib
print('matplotlib: %s' % matplotlib.__version__)
# pandas
import pandas
print('pandas: %s' % pandas.__version__)
# statsmodels
import statsmodels
print('statsmodels: %s' % statsmodels.__version__)
# scikit-learn
import sklearn
print('sklearn: %s' % sklearn.__version__)
# theano
import theano
print('theano: %s' % theano.__version__)
# tensorflow
import tensorflow
print('tensorflow: %s' % tensorflow.__version__)
# keras
import keras
print('keras: %s' % keras.__version__)
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
import pandas as pd
import math
from matplotlib import pyplot<jupyter_output><empty_output><jupyter_text>Read Data<jupyter_code>df = pd.read_excel('Gillig139_2020-01-01-0000_2020-02-01-0000.xlsm', index_col=False)
print(len(df))
df.columns<jupyter_output>1048575<jupyter_text>Linear Intrepolate Empty Entries<jupyter_code>df.columns =['Timestamp', 'Time', 'FuelUsed', 'FuelDriving', 'FuelIdling', 'AccP', 'Temp', 'FuelRate', 'RPM', 'Speed',
            'Alt', 'Lat', 'Long', 'SpeedGPS']
AccP = df['AccP']
#print(AccP)
AccP = AccP.interpolate()
#print(AccP)
df['AccP']=AccP

FuelRate = df['FuelRate']
#print(FuelRate)
FuelRate = FuelRate.interpolate()
#print(FuelRate)
df['FuelRate'] = FuelRate

RPM = df['RPM']
#print(RPM)
RPM = RPM.interpolate()
#print(RPM)
df['RPM'] = RPM

Speed = df['Speed']
#print(Speed)
Speed = Speed.interpolate()
#print(Speed)
df['Speed'] = Speed

df1 = df[['AccP', 'FuelRate', 'RPM', 'Speed']]
print(len(df1))
df1=df1.dropna()
print(len(df1))
print(df1.head(3))<jupyter_output>1048575
1046576
          AccP  FuelRate       RPM     Speed
1999  0.005458    1.9680  1000.325  0.000485
2000  0.008188    1.9745  1000.225  0.000969
2001  0.010917    1.9810  1000.125  0.001454<jupyter_text>Split Train and Test Datasets<jupyter_code>df1['Speed2'] = df1['Speed']**2
df1['Speed3'] = df1['Speed']**3

train = df1.sample(n=math.floor(0.8*df1.shape[0]))
test = df1.sample(n=math.ceil(0.2*df1.shape[0]))<jupyter_output><empty_output><jupyter_text>Establish ANN model and train<jupyter_code>Y_train = train['FuelRate']
X_train = train[['AccP','Speed','RPM','Speed2','Speed3']]

Y_test = test['FuelRate']
X_test = test[['AccP','Speed','RPM','Speed2','Speed3']]

model = Sequential()
model.add(Dense(10,kernel_initializer='normal', input_dim=5, activation ='relu'))
model.add(Dense(5, kernel_initializer='normal', activation ='relu'))
model.add(Dense(3, kernel_initializer='normal', activation ='relu'))
model.add(Dense(1,kernel_initializer='normal', activation ='linear'))

model.compile(loss='mean_absolute_error', optimizer='adam')

history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=100, batch_size=256, verbose = 0)
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()<jupyter_output><empty_output><jupyter_text>Make predictions and plot against ground truth<jupyter_code>pre = model.predict(X_test)
abline_x = [-1, 19]
abline_y = [-1, 19]
pyplot.scatter(Y_test,pre)
pyplot.plot(abline_x,abline_y)
pyplot.show()<jupyter_output><empty_output><jupyter_text>Distributions of errors and ground truth values<jupyter_code>difference = pre
for i in range(pre.shape[0]):
    difference[i] = Y_test.values[i] - pre[i]
dff = pd.DataFrame(data=difference, index=None, columns=None)<jupyter_output><empty_output><jupyter_text>Errors<jupyter_code>dff.plot.hist(grid=True, bins=26, rwidth=0.9,
                   color='#607c8e')<jupyter_output><empty_output><jupyter_text>Ground truth values<jupyter_code>Y_test.plot.hist(grid=True, bins=26, rwidth=0.9,
                   color='#607c8e')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1564071856287425, 'fraction_numerical': 0.04862275449101797, 'mean_word_length': 6.457142857142857, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '371210', 'license': 'Apache-2.0', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1587, 'n_words': 290, 'path': 'files/notebooks/Micro_Prediction_Models/DieselBusModel/DieselBus_Model.ipynb', 'repo_name': 'HDEMMA/hddemma.github.io', 'size': '4175'}