user572575
user572575

Reputation: 1049

How to calculate percent of error in keras

I use keras and set machine learning model to predict my data like this.

K.clear_session()

model = Sequential()
model.add(Dense(3, input_dim=1, activation='relu'))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X_train, y_train, epochs=500,
          batch_size=2, verbose=1,
          )

Output after model.fit show loss such as loss: 0.0382. I don't know what is mean loss: 0.0382. How many percent of error between train and test data ? How to calculate ?

Upvotes: 2

Views: 6617

Answers (1)

Sreeram TP
Sreeram TP

Reputation: 11907

You have used mean_squared_error (mse) loss function.

The MSE assesses the quality of an estimator (i.e., a mathematical function mapping a sample of data to a parameter of the population from which the data is sampled) or a predictor (i.e., a function mapping arbitrary inputs to a sample of values of some random variable).

Formula for MSE

MSE must be low for a good model. Lower the MSE better the model.

In your training you got a loss of 0.0382. Which is pretty good.

In Keras there is another loss function named mean_absolute_percentage_error. You can compile the model with mean_absolute_percentage_error as loss function if you want to know the percentage error of the model with train and test.

If you want to evaluate the model after compilation and training based on how much Accuracy the model has, you can use evaluate() function like this.

scores = model.evaluate(X_validation, Y_validation, verbose=1)
print("Accuracy: %.2f%%" % (scores[1]*100))

Upvotes: 3

Related Questions