MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to create a custom cost function to evaluate keras model?

# How to create a custom cost function to evaluate keras model?

This recipe helps you create a custom cost function to evaluate keras model

How to create a custom cost function to evaluate keras model

The formula for every loss function is predefined, but if we want to create a loss function(cost function) specifically for our model then we can create. So we can define our own loss function and call it a custom cost function.

```
import keras as k
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
```

We will define two sample arrays as predicted and actual to calculate the loss.
```
y_pred=np.array([2,3,5,7,9])
y_actual=np.array([4,2,8,5,2])
```

we are considering the formula for MSE here.

```
def custom_loss(y_true,y_pred):
return K.mean(K.square(y_pred - y_actual) + K.square(layer), axis=-1)
```

We will pass our own custom cost function to the model.

```
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Compile model
model.compile(loss='custom_loss', optimizer='adam', metrics=['accuracy'])
```

```
model.summary
```

>

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

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

In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

In this project, we are going to work on Deep Learning using H2O to predict Census income.

In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.