MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# What is the meaning of loss functions in keras?

# What is the meaning of loss functions in keras?

This recipe explains what is the meaning of loss functions in keras

To understand the meaning of loss functions in keras.

The loss is calculated to get the gradients(please refer to gradient descent graph to understand) concerning model weights and update those weights accordingly via backpropagation. Loss is calculated then network weights are updated after every iteration until model updates don't get close or make any improvement in the desired evaluation metric.

```
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
```

We will define the layers, kernel initializer, and its input nodes shape in the model.

```
model = keras.Sequential()
model.add(layers.Dense(64, kernel_initializer='uniform', input_shape=(10,)))
```

We will define the activation function as relu.

```
model.add(layers.Activation('relu'))
```

We will initialize the loss function as 'Binary_Cross_entropy' with reduction as 'sum_over_batch_size'.

```
BC = keras.losses.BinaryCrossentropy(reduction='sum_over_batch_size')
model.compile(loss=loss_fn, optimizer='adamax')
```

Let's take a sample dataset of predicted and true values then calculate the loss.

```
y_true = [[1, 2], [4, 6],[0.5, 0.7],[0.4, 0.6]]
y_pred = [[1.5, 1.4], [5, 7],[0.6, 0.5],[0.7, 0.7]]
BC(y_true, y_pred).numpy()
```

-16.878973

As we can see minimum loss with this model is -16.878973 for the sample dataset. We can improve it by choosing another type of loss function or optimizer.

In this Deep Learning Project on Image Segmentation Python, you will learn how to implement the Mask R-CNN model for early fire detection.

In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

In this time series project, you will build a model to predict the stock prices and identify the best time series forecasting model that gives reliable and authentic results for decision making.