diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py index 72970431c3fc..5bbd5de52153 100644 --- a/machine_learning/decision_tree.py +++ b/machine_learning/decision_tree.py @@ -1,11 +1,52 @@ +import numpy as np + +""" +Decision Tree Regression Implementation + +This module implements a basic regression decision tree using Python and NumPy. + +📄 Overview: +Decision Trees are a type of supervised learning algorithm used for both +classification and regression tasks. In this implementation, the tree +is specifically designed for regression: mapping continuous input features +to continuous outputs. + +📌 Features: +- Supports one-dimensional datasets with continuous labels. +- Splits data recursively based on minimizing mean squared error. +- Can specify maximum tree depth and minimum leaf size. +- Predicts outputs for unseen data using the trained tree. + +🌟 Educational Value: +This implementation is lightweight and designed for learning purposes. +It demonstrates: +- The core concept of recursive partitioning in decision trees. +- How mean squared error guides splitting decisions. +- The trade-off between tree depth and model complexity. + +💡 Use Cases: +- Understanding how regression trees work internally. +- Testing and experimenting with small datasets. +- Educational projects, tutorials, or self-learning exercises. + +Audience: +- Beginners learning machine learning concepts +- Students studying regression algorithms +- Anyone interested in understanding decision tree internals + +📦 Dependencies: +- numpy + +Note: This implementation is meant for demonstration and learning purposes +and may not be optimized for large-scale production datasets. +""" + """ Implementation of a basic regression decision tree. Input data set: The input data set must be 1-dimensional with continuous labels. Output: The decision tree maps a real number input to a real number output. """ -import numpy as np - class DecisionTree: def __init__(self, depth=5, min_leaf_size=5): diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 5b1e663116cc..38c1f19387f9 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -1,3 +1,33 @@ +import httpx +import numpy as np + +""" +Linear Regression Algorithm - Predictive Analysis (Enhanced Documentation) + +This file implements linear regression using gradient descent to predict +values based on a dataset. The example dataset here is from CSGO (ADR vs Rating). + +Purpose: +- Demonstrates basic linear regression with a small dataset. +- Shows how to collect data from an online source. +- Illustrates calculation of errors (sum of squares and mean absolute error). +- Provides a step-by-step gradient descent implementation. + +Audience: +- Beginners learning machine learning algorithms. +- Students who want to understand linear regression implementation in Python. + +Dependencies: +- Python >= 3.13 +- httpx +- numpy + +Notes: +- The algorithm iteratively updates feature weights to minimize error. +- Output includes the feature vector representing the best-fit line. +- Designed for educational purposes; can be adapted for other datasets. +""" + """ Linear regression is the most basic type of regression commonly used for predictive analysis. The idea is pretty simple: we have a dataset and we have @@ -16,9 +46,6 @@ # ] # /// -import httpx -import numpy as np - def collect_dataset(): """Collect dataset of CSGO diff --git a/machine_learning/logistic_regression.py b/machine_learning/logistic_regression.py index 496026631fbe..15ebc77b08ad 100644 --- a/machine_learning/logistic_regression.py +++ b/machine_learning/logistic_regression.py @@ -9,10 +9,29 @@ # importing all the required libraries """ -Implementing logistic regression for classification problem +Implementation of Logistic Regression from scratch. + +Audience: +- Beginners exploring supervised learning and classification algorithms +- Students learning how logistic regression works mathematically and programmatically +- Developers wanting to understand how to implement gradient descent for classification + +Dependencies: +- numpy +- matplotlib +- scikit-learn (for dataset demonstration) + +Notes: +- This implementation is for educational purposes and demonstrates logistic regression + without using high-level libraries. +- The training is done with gradient descent; for large datasets, optimization + techniques like stochastic gradient descent may be preferable. +- Visualization is based on the Iris dataset, focusing only on two features + for simplicity. + Helpful resources: -Coursera ML course -https://medium.com/@martinpella/logistic-regression-from-scratch-in-python-124c5636b8ac +- Coursera Machine Learning course +- https://medium.com/@martinpella/logistic-regression-from-scratch-in-python-124c5636b8ac """ import numpy as np @@ -21,7 +40,6 @@ # get_ipython().run_line_magic('matplotlib', 'inline') - # In[67]: # sigmoid function or logistic function is used as a hypothesis function in