Giter Site home page Giter Site logo

shotahorii / bareml Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 18.87 MB

Machine learning & deep learning implementation from scratch, depending only on numpy.

License: MIT License

Python 99.87% Dockerfile 0.13%
machine-learning machine-learning-algorithms machine-learning-from-scratch statistical-models data-science deep-learning deep-neural-networks

bareml's Introduction

Build Status PyPI version PyPI - Python Version

Logo

bareml is a set of "bare" implementations of machine learning / deep learning algorithms from scratch (only depending on numpy) in Python. "bare" means to aim at:

  1. Code as a direct translation of the algorithm / formula
  2. With minimum error handling and efficiency gain tricks

To maximise understandability of the code, interface of modules in bareml/machinelearning/ is aligned to Scikit-learn, and interface of modules in bareml/deeplearning/ is aligned to PyTorch, as seen in below 2 examples.

Example1:

from bareml.machinelearning.utils.model_selection import train_test_split
from bareml.machinelearning.supervised import KernelRidge

# assume the data X, y are defined
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

reg = KernelRidge(alpha=1, kernel='rbf')
reg.fit(X_train, y_train)
y_pred = reg.predict(X_test)
print(reg.score(X_test, y_test))

Example2:

from bareml.deeplearning import layers as nn
from bareml.deeplearning import functions as F

class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=1)
        self.conv2 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1)
        self.dropout1 = nn.Dropout(p=0.25)
        self.dropout2 = nn.Dropout(p=0.5)
        self.fc1 = nn.Linear(in_features=33856, out_features=128)
        self.fc2 = nn.Linear(in_features=128, out_features=10)

    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = self.conv2(x)
        x = F.relu(x)
        x = F.max_pool2d(x, 2)
        x = self.dropout1(x)
        x = x.flatten()
        x = self.fc1(x)
        x = F.relu(x)
        x = self.dropout2(x)
        x = self.fc2(x)
        return x

Installation

$ pip install bareml

or

$ git clone https://github.com/shotahorii/bareml.git
$ cd bareml
$ python setup.py install

Dependencies

Mandatory

  • numpy

Optional

  • cupy
  • PIL
  • matplotlib
  • graphviz

Examples

Generating handwriting digits by GAN

[Google Colab]

gif

Word embeddings by word2vec (CBoW)

[Google Colab]

img

Cart Pole Problem with Q-Learning

[Notebook]

gif

Clustering by DBSCAN

[Notebook]

gif

Fitting Sin function with Polynomial Linear Regression

[Notebook]

gif

Implementations

Deep Learning

Supervised Learning

Unsupervised Learning

Ensemble Learning

Utilities

References

  • Deep learning programs are based on O'Reilly Japan's book "Deep learning from scratch 3" (Koki Saitoh) and its implementation Dezero.
  • References of machine learning programs are documented in each source file, but mostly based on original papers, "Pattern Recognition and Machine Learning" (Christopher M. Bishop) and/or "Machine Learning: A Probabilistic Perspective" (Kevin P. Murphy).

bareml's People

Contributors

shotahorii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ahlag

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.