In [23]:
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
In [2]:
df = pd.read_csv('evasao.csv')
df.head()
Out[2]:
In [3]:
df.describe()
Out[3]:
Separação dos dados em features (características ou preditores) e labels (variável dependente):
In [4]:
features = df[['periodo','bolsa','repetiu','ematraso','disciplinas','faltas']]
labels = df[['abandonou']]
Separação em dados de treino e teste:
In [5]:
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.33, random_state=42)
In [8]:
model = Sequential()
In [9]:
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'])
In [14]:
df_train_x = X_train.values
df_train_y = y_train.values
historico = model.fit(df_train_x, df_train_y)
In [15]:
model.summary()
Plotando a acurácia e a perda (referência: https://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/)
In [26]:
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()
In [36]:
df_test_x = X_test.values
df_test_y = y_test.values
print(model.metrics_names)
model.evaluate(df_test_x,df_test_y)
Out[36]:
Temos uma acurácia de 65%