Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1K
Visualizações
model.predict_classes is deprecated - What to use instead?

I have been trying to revisit my python code for prediction on neural network and i realized after running the code that model.predict_classes is deprecated since 1st Jan 2021.

Kindly can you support me to know what i can use instead for my code ?

The code line is:

y_pred_nn = model.predict_classes(X_test)

The issue:

NameError
Traceback (most recent call last)
<ipython-input-11-fc1ddbecb622> in <module>
----> 1 print(y_pred_nn)

NameError: name 'y_pred_nn' is not defined
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

model.predict_classes is deprecated, as mentioned by @Kaveh, use model.predict() function instead.

np.argmax(model.predict(x_test), axis=-1)

To know more about model.predict() check this link.

over 4 years ago · Santiago Trujillo Relatório

0

If your model performs multi-class classification (e.g. if it uses a softmax last-layer activation) use: np.argmax(model.predict(x), axis=-1)

If your model performs binary classification (e.g. if it uses a sigmoid last-layer activation) use:

(model.predict(X_test) > 0.5).astype("int32")

over 4 years ago · Santiago Trujillo Relatório

0

The best explanation of how to handle this is given at:

https://androidkt.com/get-class-labels-from-predict-method-in-keras/

First use model.predict() to extract the class probabilities. Then depending on the number of classes do the following:

Binary Classification

Use a threshold to select the probabilities that will determine class 0 or 1

np.where(y_pred > threshold, 1,0)

For example use a threshold of 0.5

Mutli-class Classification

Select the class with the highest probability

np.argmax(predictions, axis=1)

Multi-label Classification

Where you can have multiple output classes per example, use a threshold to select which labels apply.

y_pred = model.predict(x, axis=1)
[i for i,prob in enumerate(y_pred) if prob > 0.5]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda