import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
import keras
from keras.models import Sequential
from keras.layers import Activation, Dense, Dropout, Flatten
from keras.optimizers import Adam
import matplotlib.pyplot as plt
%matplotlib inline

df = pd.read_csv('evasao.csv')
df.head()

df.describe()

"""
Explanation: Keras com Python
End of explanation
"""


features = df[['periodo','bolsa','repetiu','ematraso','disciplinas','faltas']]
labels = df[['abandonou']]

"""
Explanation: Separação dos dados em features (características ou preditores) e labels (variável dependente):
End of explanation
"""


X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.33, random_state=42)

model = Sequential()

model.add(Dense(128, input_dim=6, kernel_initializer='normal', activation='relu'))
model.add(Dense(512, activation='relu'))
model.add(Dense(512, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])

df_train_x = X_train.values
df_train_y = y_train.values
historico = model.fit(df_train_x, df_train_y)

model.summary()

"""
Explanation: Separação em dados de treino e teste:
End of explanation
"""


print(historico.history.keys())
# summarize history for accuracy
plt.plot(historico.history['acc'])
#plt.plot(historico.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(historico.history['loss'])
#plt.plot(historico.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()

df_test_x = X_test.values
df_test_y = y_test.values
print(model.metrics_names)
model.evaluate(df_test_x,df_test_y)

"""
Explanation: Plotando a acurácia e a perda (referência: https://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/)
End of explanation
"""


