Skip to main content

Machine Learning package

Project description

mllb

Machine Learning algorithms.

pip install mllb

Overview

This repository contains Machine Learning algorithms for Linear Regression, Logistic Regression, and Convolutional Neural Networks. It also helps to easily and efficiently port, edit and select rows in csv files directly for training.

This project was inpired by the author's quest to understand the basic concepts and mathematics of Machine Learning.

It uses NumPy heavily for its computations.

Basics

Here, the basic a few basic things that can be done with the package are discussed. A more detailed documentation can be found in the docs directory.

Linear Regression

To train a simple Linear Regression algorithm from x, and y.


import mllb as ml

x = [1, 2, 3, 4, 5, 6]
y = [3, 5, 7, 9, 11, 13]

# Create a linear regression model
model = ml.linear_regression(x, y)

# Choose a learning rate
model.learning_rate.initial(0.1)

# Choose the number of epochs and train, the default optimizer is Stochastic Gradient Descent
model.train(10)

# Test the model by predicting a value
pr = model.predict([10])

# Print the prediction
print(pr)

Convolutional Neural Network

To train a simple Convolutional Neural Neural network, four simple 'pictures' whose resolutions are 4 x 4 pixel pictures will be used as an example here.

image 1 = [white, white]
          [black, black]

image 2 = [black, white]
          [white, black]

image 3 = [black, black]
          [white, white]

image 4 = [white, black]
          [black, white]

import mllb as ml

# Using white = 1 and black = 0, the four images can be represented as x
x = [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [1, 0, 0, 1]]

# Choose a corresponding value y that represents the classifier. Here, we choose:
# image 1 as [0, 0]; image 2 as [0, 1]; image 3 as [1, 0] and image 4 as [1, 1]
y = [[0, 0], [0, 1], [1, 0], [1, 1]]

# Create a cnn (Convolutional Neural Network model)
model = ml.cnn(x, y)

# Create the layers for the network using the activation function names
# Here two layers will be created; a ReLU layer with 5 nodes, and a sigmoid layer with 2 nodes
model.layers.create(ml.relu(5), ml.sigmoid(2))

# Intialize the layer weights with xavier method for faster convergence
model.layers.xavier_initialization()

# Set an intial learning rate
model.learning_rate.initial(0.01)

# If you wish, the learning rate can be multiplied by a value after every epoch for faster convergence.
# This part optional. Here we use 1.01 (increase learning rate by 1% after every epoch)
model.learning_rate.multiply_after_epoch(1.01)

# Train the model and choose the number of epochs, an epoch of 800 is chosen here. It defaults to Stochastic Gradient Descent.
model.train(800)

# Test your model by predicting an image
img1 = model.predict([1, 1, 0, 0])
img2 = model.predict([0, 1, 1, 0])
img3 = model.predict([0, 0, 1, 1])
img4 = model.predict([1, 0, 0, 1])

# Print the predictions
print(img1)
print(img2)
print(img3)
print(img4)

# Print the predictions
print(img1)
print(img2)
print(img3)
print(img4)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mllb-0.0.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mllb-0.0.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file mllb-0.0.3.tar.gz.

File metadata

  • Download URL: mllb-0.0.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.8

File hashes

Hashes for mllb-0.0.3.tar.gz
Algorithm Hash digest
SHA256 91c7649cbe53a12f7c870b8e2836935457f7892f887d6bd5529b1f49a88fc312
MD5 e9bb1b8c07970c71cf6c5defd2fbdcc0
BLAKE2b-256 cc0b36b3f9b4b448c3355a94c65768b7db6791382bb9e60235c64042407e4005

See more details on using hashes here.

File details

Details for the file mllb-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: mllb-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.8

File hashes

Hashes for mllb-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a63b417c7a4a6ad27d636369af39dfb82a856ccd42823a9c34da90c775e014d
MD5 5091cd199f229940624c361565b3dd05
BLAKE2b-256 95368848fe7584478d7e4b1139133aaaab44a4db51d1ba84ea06da591ea5b8a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page