In [1]:
import pandas as pd               
import numpy as np

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, LSTM
from keras.optimizers import SGD
from keras.callbacks import History 
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.layers import Embedding
from keras.layers import MaxPooling1D

%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

history = History()
history_testing = History()


/Users/sgez/bin/anaconda/lib/python3.6/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
/Users/sgez/bin/anaconda/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)

In [2]:
df_init = df = pd.read_csv('maintenance_data.csv')
#Convert strings to discrete integers
try:
    mymap = {'TeamA':1, 'TeamB':2, 'TeamC':3, 'Provider1':1, 'Provider2':2, 'Provider3':3, 'Provider4':4}
    df = df.applymap(lambda s: mymap.get(s) if s in mymap else s)
except:
    pass  

X = df.drop('broken', axis=1).values
Y = df.broken.values[np.newaxis].T
df.head()


Out[2]:
lifetime broken pressureInd moistureInd temperatureInd team provider
0 56 0 92.178854 104.230204 96.517159 1 4
1 81 1 72.075938 103.065701 87.271062 3 4
2 60 0 96.272254 77.801376 112.196170 1 1
3 86 1 94.406461 108.493608 72.025374 3 2
4 34 0 97.752899 99.413492 103.756271 2 1

In [3]:
model = Sequential()

model.add(Dense(64, activation='relu', input_dim=6))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(X, Y, epochs=200, verbose=0, validation_split=0.15, callbacks=[history])

#Accuracy during training epochs
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('Model Accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='lower right')
plt.grid()
plt.show()

#Loss during training epochs
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model Loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper right')
plt.grid()
plt.show()



In [ ]:


In [ ]: