Why is the accuracy for my Keras model always 0 when training?

后端 未结 4 898
粉色の甜心
粉色の甜心 2020-12-23 09:36

I\'m pretty new to keras I have built a simple network to try:

import numpy as np;

from keras.models import Sequential;
from keras.layers import Dense,Activ         


        
4条回答
  •  不知归路
    2020-12-23 10:13

    Your model seems to correspond to a regression model for the following reasons:

    • You are using linear (the default one) as an activation function in the output layer (and relu in the layer before).

    • Your loss is loss='mean_squared_error'.

    However, the metric that you use- metrics=['accuracy'] corresponds to a classification problem. If you want to do regression, remove metrics=['accuracy']. That is, use

    model.compile(optimizer='adam',loss='mean_squared_error')
    

    Here is a list of keras metrics for regression and classification (taken from this blog post):

    Keras Regression Metrics

    •Mean Squared Error: mean_squared_error, MSE or mse

    •Mean Absolute Error: mean_absolute_error, MAE, mae

    •Mean Absolute Percentage Error: mean_absolute_percentage_error, MAPE, mape

    •Cosine Proximity: cosine_proximity, cosine

    Keras Classification Metrics

    •Binary Accuracy: binary_accuracy, acc

    •Categorical Accuracy: categorical_accuracy, acc

    •Sparse Categorical Accuracy: sparse_categorical_accuracy

    •Top k Categorical Accuracy: top_k_categorical_accuracy (requires you specify a k parameter)

    •Sparse Top k Categorical Accuracy: sparse_top_k_categorical_accuracy (requires you specify a k parameter)

提交回复
热议问题