Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] Neural Networks ai gradient descent #5785

Merged
merged 12 commits into from
Dec 18, 2024

Conversation

PragatiVerma18
Copy link
Collaborator

Description

Add a new term entry in the AI concept for neural-network: gradient descent.

Issue Solved

Closes #4526

Type of Change

  • Adding a new entry
  • Editing an existing entry (fixing a typo, bug, issues, etc)
  • Updating the documentation

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@PragatiVerma18 PragatiVerma18 added new entry New entry or entries ai Artificial Intelligence entries labels Dec 9, 2024
@mamtawardhani mamtawardhani self-assigned this Dec 9, 2024
@mamtawardhani mamtawardhani added status: under review Issue or PR is currently being reviewed neural-networks Neural Networks labels Dec 9, 2024
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @PragatiVerma18 , thank you for contributing to Codecademy Docs, the entry is nicely written! 😄

I've suggested a few changes, could you please review and modify those at your earliest convenience? Thank you! 😃

@@ -0,0 +1,112 @@
---
Title: 'Gradient Descent'
Description: 'Gradient Descent is an optimization algorithm used in machine learning and neural networks to minimize a cost function by iteratively moving towards the minimum using the gradient of the function.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should not be more than 160 characters

- 'path/data-science'
---

**Gradient Descent** is an optimization algorithm commonly used to minimize a cost function in machine learning and neural networks. The goal of gradient descent is to find the optimal parameters (weights) for a model that minimizes the error or loss function.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Gradient Descent** is an optimization algorithm commonly used to minimize a cost function in machine learning and neural networks. The goal of gradient descent is to find the optimal parameters (weights) for a model that minimizes the error or loss function.
**Gradient Descent** is an optimization algorithm commonly used in machine learning and neural networks to minimize a cost function. Its goal is to iteratively find the optimal parameters (weights) that minimize the error or loss.


**Gradient Descent** is an optimization algorithm commonly used to minimize a cost function in machine learning and neural networks. The goal of gradient descent is to find the optimal parameters (weights) for a model that minimizes the error or loss function.

In the context of neural networks, gradient descent adjusts the model’s parameters by computing the gradient (or derivative) of the cost function with respect to each parameter. The algorithm then updates the parameters in the direction that reduces the cost.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the context of neural networks, gradient descent adjusts the model’s parameters by computing the gradient (or derivative) of the cost function with respect to each parameter. The algorithm then updates the parameters in the direction that reduces the cost.
In neural networks, gradient descent computes the gradient (derivative) of the cost function with respect to each parameter. It then updates the parameters in the direction of the negative gradient, effectively reducing the cost with each step.

| Type | Description |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Batch Gradient Descent** | Uses the entire dataset to compute the gradient and update the weights. Typically slower but more accurate for large datasets. |
| **Stochastic Gradient Descent (SGD)** | Uses a single sample to compute the gradient and update the weights. Faster, but the updates are noisy and can lead to fluctuations in the convergence path. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| **Stochastic Gradient Descent (SGD)** | Uses a single sample to compute the gradient and update the weights. Faster, but the updates are noisy and can lead to fluctuations in the convergence path. |
| **Stochastic Gradient Descent (SGD)** | Uses a single sample to compute the gradient and update the weights. It is faster, but the updates are noisy and can cause fluctuations in the convergence path. |

theta = theta - learning_rate * gradient_of_cost_function
```

- `theta`: The parameter (weight) of the model.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `theta`: The parameter (weight) of the model.
- `theta`: The parameter (weight) of the model that is being optimized.


- `theta`: The parameter (weight) of the model.
- `learning_rate`: A hyperparameter that controls the step size.
- `gradient_of_cost_function`: The gradient (derivative) of the cost function with respect to the parameters.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `gradient_of_cost_function`: The gradient (derivative) of the cost function with respect to the parameters.
- `gradient_of_cost_function`: The gradient (derivative) of the cost function with respect to the parameters, indicating the direction and magnitude of the change needed.

Comment on lines 50 to 51
theta = initial_value # Parameters (weights)
learning_rate = value # Learning rate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
theta = initial_value # Parameters (weights)
learning_rate = value # Learning rate
theta = initial_value # Model Parameters (weights)
learning_rate = value # Learning rate (step size)

# Repeat until convergence
for i in range(iterations):
# Calculate the gradient of the cost function
gradient = compute_gradient(X, y, theta)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gradient = compute_gradient(X, y, theta)
gradient = compute_gradient(X, y, theta) # Gradient calculation

# Cost function (Mean Squared Error)
def compute_cost(X, y, theta):
m = len(y)
cost = (1/(2*m)) * np.sum((X*theta - y)**2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cost = (1/(2*m)) * np.sum((X*theta - y)**2)
cost = (1/(2*m)) * np.sum((X*theta - y)**2) # The cost function for linear regression

@PragatiVerma18
Copy link
Collaborator Author

Hey @mamtawardhani, I am done with the changes. Please review. Thanks. 🫡

Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing to Codecademy Docs @PragatiVerma18 😄

The entry looks good to be merged! 🚀

@mamtawardhani mamtawardhani merged commit 7eb32b3 into Codecademy:main Dec 18, 2024
6 checks passed
Copy link

👋 @PragatiVerma18
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 Your contribution(s) can be seen here:

https://www.codecademy.com/resources/docs/ai/neural-networks/gradient-descent

Please note it may take a little while for changes to become visible.
If you're appearing as anonymous and want to be credited, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai Artificial Intelligence entries neural-networks Neural Networks new entry New entry or entries status: review 1️⃣ completed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] Neural Networks ai gradient descent
2 participants