I have a neural net, and now?

Asked

Viewed 197 times

1

Hello, I made a neural net watching a video class on, the code is very simple but functional. And open a csv file, sort the data and do the training, right after the test is done and the result is shown. Great, is there no way to take it already trained and execute it?? Because the way it is always going to be done the training.

import pandas as pd
import sklearn
from sklearn.model_selection import train_test_split
from sklearn.ensemble import ExtraTreesClassifier

arquivo = pd.read_csv("/Users/marlorodrigues/wine_dataset.csv")

arquivo.head()

arquivo['style'] = arquivo['style'].replace('red', 0)
arquivo['style'] = arquivo['style'].replace('white', 1)

y = arquivo['style']
x = arquivo.drop('style', axis = 1)

x_treino, x_teste, y_treino, y_teste = train_test_split(x, y, test_size = 0.3)

modelo = ExtraTreesClassifier()
modelo.fit(x_treino, y_treino)

resultado = modelo.score(x_teste, y_teste)
# print("Acuracia da Rede Neural #1 --->> ", resultado)

print(y_teste[334:339])`

previsoes = modelo.predict(x_teste[334:339])
print(previsoes)
  • I admired the patience of putting the ` in each line of your code.

  • 1

    At the beginning of the question it says: "I made a neural network", in addition to the tag "neural networks" and the title, but in the code there is a model ExtraTreesClassifier. The question is how to save a Neural Network or sklearn model?

  • @Alexciuffa - the Extratreesclassifier model is not considered a way to make a neural network??

  • 1

    @Cypherpotato kkkkkkkkkkkk tried to copy the whole code, but it did not give, so I went line by line

  • @Colonopooper, no! Extratreesclassifier is an algorithm based on a set of decision trees. It can be used for selection of Features (inputs). The selected Features can be used for another model, such as a neural network, but are different models.

1 answer

2

Once trained your model, it is possible to save it with the module pickle.

To save a modelo already trained, just do:

import pickle

filename = 'modelo_final.pkl'
with open(filename, 'wb') as file:  
    pickle.dump(modelo, file)

Then to carry on:

import pickle

filename = 'modelo_final.pkl'
with open(filename, 'rb') as file:  
    modelo_carregado = pickle.load(file)

And then just use the model normally, like for example modelo_carregado.score(x_teste, y_teste).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.