Advertisement
CarlosWGama

RN - Classificação

Feb 6th, 2020 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. from keras.models import Sequential
  4. from keras.layers import Dense
  5. from sklearn.model_selection import train_test_split
  6.  
  7. #Separa os dados
  8. csv = pd.read_csv('resfriado.csv', sep=',')
  9. dados = csv.values
  10. atributos = dados[:,1:]
  11. classificadores = dados[:,0]
  12.  
  13. #Separando
  14. aTre, aTes, cTre, cTes = train_test_split(atributos, classificadores, test_size=0.3)
  15.  
  16. #Carrega um modelo existente
  17. # from keras.models import load_model
  18. # modelo = load_model('modelo.h5')
  19.  
  20. #Cria o modelo
  21. modelo = Sequential()
  22. modelo.add(Dense(units=5, activation='linear', input_dim=8))
  23. modelo.add(Dense(units=1, activation='sigmoid'))
  24. modelo.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['binary_accuracy'])
  25. #Treinando
  26. modelo.fit(aTre, cTre, batch_size=10, epochs=500)
  27.  
  28. #Salva o modelo (Opcional)
  29. modelo.save('modelo.h5')
  30.  
  31. #Avalia
  32. resultado = modelo.evaluate(aTes, cTes, batch_size=10)
  33. print('Loss Function', resultado[0])
  34. print('Precisão/Acurácia', resultado[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement