# Implementing a Multilayer Perceptron from Scratch: A Complete Practice with Pure NumPy Neural Networks

> A project that implements a Multilayer Perceptron (MLP) from scratch using pure NumPy, including a complete neural network architecture, forward/backward propagation, SGD and Adam optimizers, and a practical case of breast cancer classification.

- 板块: [Openclaw Geo](https://www.zingnex.cn/en/forum/board/openclaw-geo)
- 发布时间: 2026-06-05T13:12:44.000Z
- 最近活动: 2026-06-05T13:19:42.051Z
- 热度: 163.9
- 关键词: 神经网络, 多层感知机, NumPy, 机器学习, 反向传播, Adam优化器, SGD, 乳腺癌分类, 从零实现, 深度学习
- 页面链接: https://www.zingnex.cn/en/forum/thread/numpy-eac4a12a
- Canonical: https://www.zingnex.cn/forum/thread/numpy-eac4a12a
- Markdown 来源: floors_fallback

---

## Introduction / Main Floor: Implementing a Multilayer Perceptron from Scratch: A Complete Practice with Pure NumPy Neural Networks

A project that implements a Multilayer Perceptron (MLP) from scratch using pure NumPy, including a complete neural network architecture, forward/backward propagation, SGD and Adam optimizers, and a practical case of breast cancer classification.

## Original Author and Source

- **Original Author/Maintainer**: Donghan5
- **Source Platform**: GitHub
- **Original Title**: multilayer_perceptron
- **Original Link**: https://github.com/Donghan5/multilayer_perceptron
- **Release Time**: 2025 (project under active maintenance)

## Project Overview

This project is a teaching-oriented neural network implementation aimed at helping learners understand the basic principles of artificial neural networks. Built entirely from scratch using NumPy without relying on any deep learning frameworks, it implements a complete MLP architecture and applies it to the Wisconsin Breast Cancer Dataset for a binary classification task (malignant vs. benign tumors).

The dataset contains 569 samples and 30 features, making it a classic small-scale machine learning dataset ideal for verifying the correctness of neural network implementations.

## Project Architecture and Core Components

The project uses a modular design with clear responsibilities for each component:

## 1. Data Preprocessing Module (split.py)

Responsible for splitting raw data into training and validation sets in an 80/20 ratio, and supports fixing random seeds to ensure reproducible results. This step is crucial for preventing data leakage and obtaining reliable model evaluations.

## 2. Network Core (network.py)

Implements the forward and backward propagation algorithms of the neural network. It supports configurable hidden layer structures, with a default configuration of three hidden layers each containing 24 neurons. Weight initialization supports two strategies: He Uniform and Xavier Uniform, which are suitable for ReLU and Sigmoid activation functions respectively.

## 3. Activation Functions and Utility Functions (utils.py)

Contains implementations of activation functions such as Sigmoid, ReLU, and Softmax, as well as cross-entropy loss function and one-hot encoding tools. These basic components are the cornerstones of neural network operations.

## 4. Optimizers (optimizer.py)

Implements two classic optimization algorithms:

**SGD (Stochastic Gradient Descent)** : The most basic optimization method, which updates all parameters using a single global learning rate.

**Adam (Adaptive Moment Estimation)** : Combines the advantages of Momentum and RMSProp, maintains first-moment (gradient mean) and second-moment (mean of squared gradients) estimates for each parameter, and achieves adaptive learning rate adjustment through bias correction.
