ML-From-Scratch

Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from data mining to deep learning.

Github星跟踪图

Machine Learning From Scratch

About

Python implementations of some of the fundamental Machine Learning models and algorithms from scratch.

The purpose of this project is not to produce as optimized and computationally efficient algorithms as possible
but rather to present the inner workings of them in a transparent and accessible way.

Table of Contents

Installation

$ git clone https://github.com/eriklindernoren/ML-From-Scratch
$ cd ML-From-Scratch
$ python setup.py install

Examples

Polynomial Regression

$ python mlfromscratch/examples/polynomial_regression.py

Classification With CNN

$ python mlfromscratch/examples/convolutional_neural_network.py

+---------+, ConvNet, +---------+
Input Shape: (1, 8, 8)
+----------------------+------------+--------------+, Layer Type, Parameters, Output Shape, +----------------------+------------+--------------+, Conv2D, 160, (16, 8, 8), Activation (ReLU), (16, 8, 8), Dropout, (16, 8, 8), BatchNormalization, 2048, (16, 8, 8), Conv2D, 4640, (32, 8, 8), Activation (ReLU), (32, 8, 8), Dropout, (32, 8, 8), BatchNormalization, 4096, (32, 8, 8), Flatten, (2048,), Dense, 524544, (256,), Activation (ReLU), (256,), Dropout, (256,), BatchNormalization, 512, (256,), Dense, 2570, (10,), Activation (Softmax), (10,), +----------------------+------------+--------------+
Total Parameters: 538570

Training: 100% [------------------------------------------------------------------------] Time: 0:01:55
Accuracy: 0.987465181058

Density-Based Clustering

$ python mlfromscratch/examples/dbscan.py

Generating Handwritten Digits

$ python mlfromscratch/unsupervised_learning/generative_adversarial_network.py

+-----------+, Generator, +-----------+
Input Shape: (100,)
+------------------------+------------+--------------+, Layer Type, Parameters, Output Shape, +------------------------+------------+--------------+, Dense, 25856, (256,), Activation (LeakyReLU), (256,), BatchNormalization, 512, (256,), Dense, 131584, (512,), Activation (LeakyReLU), (512,), BatchNormalization, 1024, (512,), Dense, 525312, (1024,), Activation (LeakyReLU), (1024,), BatchNormalization, 2048, (1024,), Dense, 803600, (784,), Activation (TanH), (784,), +------------------------+------------+--------------+
Total Parameters: 1489936

+---------------+, Discriminator, +---------------+
Input Shape: (784,)
+------------------------+------------+--------------+, Layer Type, Parameters, Output Shape, +------------------------+------------+--------------+, Dense, 401920, (512,), Activation (LeakyReLU), (512,), Dropout, (512,), Dense, 131328, (256,), Activation (LeakyReLU), (256,), Dropout, (256,), Dense, 514, (2,), Activation (Softmax), (2,), +------------------------+------------+--------------+
Total Parameters: 533762

Deep Reinforcement Learning

$ python mlfromscratch/examples/deep_q_network.py

+----------------+, Deep Q-Network, +----------------+
Input Shape: (4,)
+-------------------+------------+--------------+, Layer Type, Parameters, Output Shape, +-------------------+------------+--------------+, Dense, 320, (64,), Activation (ReLU), (64,), Dense, 130, (2,), +-------------------+------------+--------------+
Total Parameters: 450

Image Reconstruction With RBM

$ python mlfromscratch/examples/restricted_boltzmann_machine.py

Evolutionary Evolved Neural Network

$ python mlfromscratch/examples/neuroevolution.py

+---------------+, Model Summary, +---------------+
Input Shape: (64,)
+----------------------+------------+--------------+, Layer Type, Parameters, Output Shape, +----------------------+------------+--------------+, Dense, 1040, (16,), Activation (ReLU), (16,), Dense, 170, (10,), Activation (Softmax), (10,), +----------------------+------------+--------------+
Total Parameters: 1210

Population Size: 100
Generations: 3000
Mutation Rate: 0.01

[0 Best Individual - Fitness: 3.08301, Accuracy: 10.5%]
[1 Best Individual - Fitness: 3.08746, Accuracy: 12.0%]
...
[2999 Best Individual - Fitness: 94.08513, Accuracy: 98.5%]
Test set accuracy: 96.7%

Genetic Algorithm

$ python mlfromscratch/examples/genetic_algorithm.py

+--------+, GA, +--------+
Description: Implementation of a Genetic Algorithm which aims to produce
the user specified target string. This implementation calculates each
candidate's fitness based on the alphabetical distance between the candidate
and the target. A candidate is selected as a parent with probabilities proportional
to the candidate's fitness. Reproduction is implemented as a single-point
crossover between pairs of parents. Mutation is done by randomly assigning
new characters with uniform probability.

Parameters
----------
Target String: 'Genetic Algorithm'
Population Size: 100
Mutation Rate: 0.05

[0 Closest Candidate: 'CJqlJguPlqzvpoJmb', Fitness: 0.00]
[1 Closest Candidate: 'MCxZxdr nlfiwwGEk', Fitness: 0.01]
[2 Closest Candidate: 'MCxZxdm nlfiwwGcx', Fitness: 0.01]
[3 Closest Candidate: 'SmdsAklMHn kBIwKn', Fitness: 0.01]
[4 Closest Candidate: '  lotneaJOasWfu Z', Fitness: 0.01]
...
[292 Closest Candidate: 'GeneticaAlgorithm', Fitness: 1.00]
[293 Closest Candidate: 'GeneticaAlgorithm', Fitness: 1.00]
[294 Answer: 'Genetic Algorithm']

Association Analysis

$ python mlfromscratch/examples/apriori.py
+-------------+, Apriori, +-------------+
Minimum Support: 0.25
Minimum Confidence: 0.8
Transactions:
    [1, 2, 3, 4]
    [1, 2, 4]
    [1, 2]
    [2, 3, 4]
    [2, 3]
    [3, 4]
    [2, 4]
Frequent Itemsets:
    [1, 2, 3, 4, [1, 2], [1, 4], [2, 3], [2, 4], [3, 4], [1, 2, 4], [2, 3, 4]]
Rules:
    1 -> 2 (support: 0.43, confidence: 1.0)
    4 -> 2 (support: 0.57, confidence: 0.8)
    [1, 4] -> 2 (support: 0.29, confidence: 1.0)

Implementations

Supervised Learning

Unsupervised Learning

Reinforcement Learning

Deep Learning

Contact

If there's some implementation you would like to see here or if you're just feeling social,
feel free to email me or connect with me on LinkedIn.

主要指标

概览
名称与所有者eriklindernoren/ML-From-Scratch
主编程语言Python
编程语言Python (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-02-05 12:11:23
推送于2023-10-15 06:05:06
最后一次提交2019-10-18 14:42:16
发布数0
用户参与
星数26.8k
关注者数0.9k
派生数4.8k
提交数374
已启用问题?
问题数73
打开的问题数36
拉请求数9
打开的拉请求数22
关闭的拉请求数10
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?