# Logistic Regression Cost Function (C1W2L03) | Summary and Q&A

128.4K views
August 25, 2017
by
DeepLearningAI
Logistic Regression Cost Function (C1W2L03)

## TL;DR

This video explains the logistic regression model, the cost function, and the importance of using a different loss function that is convex for optimization.

## Key Insights

• 🚂 Logistic regression requires defining a cost function to train the model parameters.
• 🌸 The loss function used in logistic regression differs from squared error to ensure convex optimization.
• 🟰 The loss function aims to make y hat large when y is equal to 1 and small when y is equal to 0.
• 😫 The cost function measures the overall performance of the parameters on the training set.

## Transcript

in the previous video you saw the logistic regression model to train the parameters W and B of your logistic regression model you need to define a cost function let's take a look at a cost function you can use to Train logistic regression to recap this is what we had defined from the previous slide so you output Y hat is sigmoid of W transpose X pl... Read More

### Q: Why is a different loss function used in logistic regression instead of squared error?

The squared error loss function leads to non-convex optimization problems, which may result in local optima. The logistic regression loss function ensures convex optimization and is better suited for this model.

### Q: What happens to the loss function when the true label (y) is equal to 1?

When y is equal to 1, the loss function aims to make y hat as large as possible because log y hat needs to be large. However, y hat can never be greater than one, so the objective is to make y hat close to one.

### Q: What is the purpose of the cost function in logistic regression?

The cost function measures how well the parameters are performing on the entire training set. It is calculated as the average of the loss function applied to each training example.

### Q: How does logistic regression relate to neural networks?

Logistic regression can be viewed as a small neural network. Understanding logistic regression helps in gaining intuition about the workings of neural networks.

## Summary & Key Takeaways

• The video discusses logistic regression and the need to define a cost function to train the parameters of the model.

• The cost function used in logistic regression is different from squared error to ensure convex optimization.

• The loss function for logistic regression is defined as negative y log y hat plus 1 minus y log 1 minus y hat.

• The cost function is the average of the loss function applied to each training example.