ML-From-Scratch: The Bare-Bones Approach to Machine Learning


ML-From-Scratch: The Bare-Bones Approach to Machine Learning

eriklindernoren/ML-From-Scratch

2025-09-10

I'd be happy to explain what eriklindernoren/ML-From-Scratch is all about and how it can be a valuable resource for a software engineer.

Think of eriklindernoren/ML-From-Scratch as a fantastic learning tool, specifically for understanding the core mechanics of machine learning. Instead of using high-level libraries like scikit-learn, TensorFlow, or PyTorch, this repository implements machine learning algorithms from the ground up using only NumPy.

From a software engineer's perspective, this is a huge advantage. Here's why

Deeper Understanding
You'll move beyond just calling a function like model.fit() and truly understand what's happening under the hood. For example, you'll see how gradient descent actually updates weights in a neural network or how a decision tree is built by recursively splitting data. This foundational knowledge is crucial for debugging, optimizing, and confidently applying ML models.

Problem-Solving Skills
By working with the bare-bones implementations, you'll develop a better intuition for common machine learning problems like overfitting, underfitting, and numerical stability.

Interview Preparation
This is an excellent resource for preparing for machine learning or data science-focused interviews. Many companies ask candidates to explain how an algorithm works or even to write a simplified version of one.

Customization and Specialization
If you ever need to create a custom algorithm or modify an existing one for a very specific task, having this low-level understanding is a must. You're not limited by the features of a library; you can build exactly what you need.

Getting started with this project is straightforward. You'll need to have Python and NumPy installed.

Clone the Repository
First, get a copy of the project on your local machine. Open your terminal or command prompt and run

git clone https://github.com/eriklindernoren/ML-From-Scratch.git

Explore the Code
Navigate into the cloned directory. You'll see different folders, each dedicated to a specific type of algorithm (e.g., supervised_learning, unsupervised_learning, deep_learning).

cd ML-From-Scratch
ls

Install Dependencies
While the project is built on NumPy, some examples might have other dependencies like Matplotlib for plotting. It's a good practice to set up a virtual environment and install them.

pip install -r requirements.txt

Run the Examples
Each algorithm's folder usually contains a Python script that you can run to see the algorithm in action. For example, to see how the K-Nearest Neighbors algorithm works, you can run

python supervised_learning/k_nearest_neighbors.py

Let's take a look at a simplified example to illustrate the "from scratch" approach. While the actual repository code is more robust, this shows the core idea.

Here's a very basic representation of a Linear Regression model. Instead of relying on sklearn.linear_model.LinearRegression, you would implement it like this:

import numpy as np

class LinearRegression:
    def __init__(self, learning_rate=0.01, n_iterations=1000):
        self.learning_rate = learning_rate
        self.n_iterations = n_iterations
        self.weights = None
        self.bias = None

    def fit(self, X, y):
        n_samples, n_features = X.shape
        self.weights = np.zeros(n_features)
        self.bias = 0

        # Gradient Descent optimization
        for _ in range(self.n_iterations):
            y_predicted = np.dot(X, self.weights) + self.bias
            
            # Calculate gradients
            dw = (1 / n_samples) * np.dot(X.T, (y_predicted - y))
            db = (1 / n_samples) * np.sum(y_predicted - y)
            
            # Update weights and bias
            self.weights -= self.learning_rate * dw
            self.bias -= self.learning_rate * db

    def predict(self, X):
        y_predicted = np.dot(X, self.weights) + self.bias
        return y_predicted

# --- Example Usage ---
# You would then use this class in your main script
if __name__ == "__main__":
    from sklearn.datasets import make_regression
    import matplotlib.pyplot as plt

    X, y = make_regression(n_samples=100, n_features=1, noise=20, random_state=42)

    model = LinearRegression(learning_rate=0.01, n_iterations=1000)
    model.fit(X, y)
    y_pred = model.predict(X)

    plt.scatter(X, y)
    plt.plot(X, y_pred, color='red')
    plt.show()

As you can see, this code explicitly shows the gradient descent loop, the calculation of the gradients (dw and db), and the updates to the weights. This level of detail is exactly what ML-From-Scratch provides, helping you build a solid and practical understanding of machine learning principles.


eriklindernoren/ML-From-Scratch




Unlock Your Knowledge Base: A Software Engineer's Guide to DocsGPT

At its core, DocsGPT is an open-source tool that leverages generative AI to provide reliable answers from your documentation and knowledge bases


Bridging the Gap: Software Engineering to AI Development

The ai-engineering-hub repository is a great resource for software engineers looking to dive into the world of AI and machine learning


The Power of Detection Transformers: RF-DETR Installation and Code Sample

Here's a friendly, detailed breakdown of how you can leverage it, including installation steps and a code example.From a software engineering perspective


Model-Driven AI Agents: Building Sophisticated Tools with Strands-Agents/sdk-python

This SDK is particularly exciting because it allows you to build sophisticated AI agents using a model-driven approach with minimal code


Beyond Algorithms: System-Level Thinking for ML Engineers with CS249r

This resource is an open-source textbook and course material focusing on the engineering and systems aspects of building and deploying real-world AI/ML applications


Integrating Amazon Chronos for Scalable Time Series Predictions

Chronos is a family of pretrained, transformer-based foundation models for time series forecasting. Think of it like a Large Language Model (LLM), but instead of text


Beyond Storage: Exploring Paperless-ngx's API and Machine Learning Core

Paperless-ngx is an open-source, community-supported document management system (DMS). Think of it as a powerful, self-hosted system to scan


From Code to Clarity: Why Engineers Need Perplexica

Perplexica is an open-source, AI-powered search engine. Think of it as an alternative to commercial services like Perplexity AI


Unlocking Text from Images: An Introduction to Tesseract for Engineers

From a software engineering perspective, Tesseract's power lies in its ability to automate tasks that would otherwise require manual data entry


Software Engineer's Guide to mrdbourke/pytorch-deep-learning: Unleashing Deep Learning with PyTorch

The mrdbourke/pytorch-deep-learning repository is the official material for the "Learn PyTorch for Deep Learning Zero to Mastery" course by Daniel Bourke