{"id":26768632,"url":"https://github.com/kunalpisolkar24/gradientdescent","last_synced_at":"2026-05-06T07:31:45.084Z","repository":{"id":283027065,"uuid":"950431367","full_name":"kunalPisolkar24/gradientDescent","owner":"kunalPisolkar24","description":"A Python implementation of gradient descent for linear regression, visualized with cost function history, parameter trajectory, and a 3D cost surface.","archived":false,"fork":false,"pushed_at":"2025-03-18T07:01:07.000Z","size":242,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T08:21:54.999Z","etag":null,"topics":["cost-function","gradient-descent","numpy","visualization"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kunalPisolkar24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-18T06:36:08.000Z","updated_at":"2025-03-18T07:01:11.000Z","dependencies_parsed_at":"2025-03-19T00:15:14.567Z","dependency_job_id":null,"html_url":"https://github.com/kunalPisolkar24/gradientDescent","commit_stats":null,"previous_names":["kunalpisolkar24/gradientdescent"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalPisolkar24%2FgradientDescent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalPisolkar24%2FgradientDescent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalPisolkar24%2FgradientDescent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunalPisolkar24%2FgradientDescent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kunalPisolkar24","download_url":"https://codeload.github.com/kunalPisolkar24/gradientDescent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246106259,"owners_count":20724394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cost-function","gradient-descent","numpy","visualization"],"created_at":"2025-03-28T21:34:45.859Z","updated_at":"2026-05-06T07:31:45.026Z","avatar_url":"https://github.com/kunalPisolkar24.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradient Descent Implementation for Linear Regression\n\nThis repository contains a Jupyter Notebook (`gradient-descent-implementation.ipynb`) that demonstrates a basic implementation of the gradient descent algorithm for optimizing a simple linear regression model.  It's designed to be educational, showing the key steps and visualizing the process.\n\n## Overview\n\nThe notebook does the following:\n\n1.  **Imports Libraries:**  Uses `numpy` for numerical computation, `matplotlib` and `seaborn` for plotting, and `mpl_toolkits.mplot3d` for 3D visualization.  No external data is needed; a simple dataset is created within the notebook.\n\n2.  **Defines `gradientDescent` Function:**\n    *   Takes input data (`x`, `y`), number of iterations, and learning rate as arguments.\n    *   Initializes the slope (`m`) and y-intercept (`b`) to 0.\n    *   Iteratively updates `m` and `b` using the gradient descent update rule:\n        *   Calculates the predicted y values (`y_pred`).\n        *   Calculates the cost (Mean Squared Error).\n        *   Calculates the gradients of the cost function with respect to `m` and `b`.\n        *   Updates `m` and `b` by subtracting the learning rate times their respective gradients.\n    *   Tracks the cost, `m`, and `b` values over each iteration in lists (`cost_history`, `m_history`, `b_history`).\n    *   Returns the final `m`, `b`, and the history lists.\n\n3.  **Defines `plotResults` Function:**\n    *   Creates a series of plots to visualize the results:\n        *   **Data \u0026 Regression Line:** Shows the original data points and the final regression line fitted by the algorithm.\n        *   **Cost Function History:** Plots the cost (MSE) over each iteration, demonstrating the convergence of the algorithm.  The y-axis is on a log scale to better show the decrease in cost.\n        *   **Parameter Trajectory:**  Shows the path of the `m` (slope) and `b` (intercept) values during the optimization process.  This visualizes how the parameters converge to their optimal values.\n        *   **3D Cost Surface:**  Plots the cost function as a 3D surface, with `m` and `b` on the x and y axes, and the cost on the z-axis. The path of the gradient descent is overlaid on this surface.\n\n4.  **Main Execution Block (`if __name__ == '__main__':`)**:\n    *   Creates a simple linear dataset: `x = [1, 2, 3, 4, 5]` and `y = [5, 7, 9, 11, 13]`.  This represents a line with a slope of 2 and a y-intercept of 3, plus some noise.\n    *   Calls the `gradientDescent` function with the data, 1000 iterations, and a learning rate of 0.08.\n    *   Calls the `plotResults` function to generate the visualizations.\n\n## Key Concepts Illustrated\n\n*   **Gradient Descent:** The core algorithm for minimizing the cost function.\n*   **Linear Regression:**  Fitting a straight line to data.\n*   **Cost Function (Mean Squared Error):**  A measure of how well the regression line fits the data.\n*   **Learning Rate:** A hyperparameter that controls the step size during gradient descent.\n*   **Convergence:**  The process of the algorithm approaching the optimal solution.\n*   **Data Visualization:** Using plots to understand the algorithm's behavior.\n\n## How to Run\n\n1.  **Clone the repository:**\n    ```bash\n    git clone https://github.com/kunalPisolkar24/gradientDescent.git\n    ```\n2.  **Navigate to the directory:**\n    ```bash\n    cd gradientDescent\n    ```\n3.  **Open the Jupyter Notebook:**\n    ```bash\n    jupyter notebook gradient-descent-implementation.ipynb\n    ```\n4.  **Run all cells** in the notebook.  The plots will be displayed within the notebook.\n\n## Dependencies\n\n*   `numpy`\n*   `matplotlib`\n*   `seaborn`\n*   `mpl_toolkits` (specifically, `mplot3d`)\n\nThese can typically be installed via `pip`:\n\n```bash\npip install numpy matplotlib seaborn\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunalpisolkar24%2Fgradientdescent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkunalpisolkar24%2Fgradientdescent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunalpisolkar24%2Fgradientdescent/lists"}