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




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


Daft Explained: The Python/Rust Distributed Engine for ML Engineers

At its core, Daft is a distributed query engine that's built for modern data science and machine learning workflows. Think of it as a powerful


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


Unleashing Deep Learning with Rust's Burn Framework

Let's dive into tracel-ai/burn from a software engineer's perspective. This looks like a really interesting project, and I'll explain how it can be useful


Mastering Machine Learning: A Software Engineer's Guide to Microsoft's ML-For-Beginners

Let's dive into microsoft/ML-For-Beginners from a software engineer's perspective. This is a fantastic resource, and I'll explain how it can benefit you


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


Scaling AI Solutions with Agent SQUAD: An Engineer's Perspective

From a software engineer's perspective, Agent SQUAD is a powerful tool for building multi-agent systems. Instead of having one monolithic AI model handle everything


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


Building TinyML: The Power and Portability of the ggml Library

ggml is a C library for tensor operations and machine learning, designed with a focus on minimalism, performance, and portability


OpenArm Deep Dive: Setup, Control, and Sample Code for Robotics Development

The enactic/openarm project is a fully open-source humanoid arm designed for physical AI research and deployment, especially in environments where the arm needs to make contact with objects or its surroundings