Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions machine_learning/decision_tree.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
33 changes: 30 additions & 3 deletions machine_learning/linear_regression.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,9 +46,6 @@
# ]
# ///

import httpx
import numpy as np


def collect_dataset():
"""Collect dataset of CSGO
Expand Down
26 changes: 22 additions & 4 deletions machine_learning/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down