Machine Learning library written in Python and NumPy.
Project description
pykitml (Python Kit for Machine Learning)
Machine Learning library written in Python and NumPy.
Installation
python3 -m pip install pykitml
Documentation
https://pykitml.readthedocs.io/en/latest/
Demo (MNIST)
Training
import os.path
import numpy as np
import pykitml as pk
from pykitml.datasets import mnist
# Download dataset
if(not os.path.exists('mnist.pkl')): mnist.get()
# Load dataset
training_data, training_targets, testing_data, testing_targets = mnist.load()
# Create a new neural network
digit_classifier = pk.NeuralNetwork([784, 100, 10])
# Train it
digit_classifier.train(
training_data=training_data,
targets=training_targets,
batch_size=50,
epochs=1200,
optimizer=pk.Adam(learning_rate=0.012, decay_rate=0.95),
testing_data=testing_data,
testing_targets=testing_targets,
testing_freq=30,
decay_freq=15
)
# Save it
pk.save(digit_classifier, 'digit_classifier_network.pkl')
# Show performance
accuracy = digit_classifier.accuracy(training_data, training_targets)
print('Train Accuracy:', accuracy)
accuracy = digit_classifier.accuracy(testing_data, testing_targets)
print('Test Accuracy:', accuracy)
# Plot performance graph
digit_classifier.plot_performance()
# Show confusion matrix
digit_classifier.confusion_matrix(training_data, training_targets)
Trying the model
import random
import numpy as np
import matplotlib.pyplot as plt
import pykitml as pk
from pykitml.datasets import mnist
# Load dataset
training_data, training_targets, testing_data, testing_targets = mnist.load()
# Load the trained network
digit_classifier = pk.load('digit_classifier_network.pkl')
# Pick a random example from testing data
index = random.randint(0, 9999)
# Show the test data and the label
plt.imshow(training_data[index].reshape(28, 28))
plt.show()
print('Label: ', training_targets[index])
# Show prediction
digit_classifier.feed(training_data[index])
model_output = digit_classifier.get_output_onehot()
print('Predicted: ', model_output)
Performance Graph
Confusion Matrix
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
pykitml-0.1.3.tar.gz
(89.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pykitml-0.1.3-py3-none-any.whl
(93.9 kB
view details)
File details
Details for the file pykitml-0.1.3.tar.gz.
File metadata
- Download URL: pykitml-0.1.3.tar.gz
- Upload date:
- Size: 89.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db00cf6d04273764be1b1d3b2e36a86ba6c1488f9d39858893a2e7ec0ac7c1bb
|
|
| MD5 |
13b73a7a03149b289b0389e603163447
|
|
| BLAKE2b-256 |
51b4b6f4206ef1948458a76ed7476c86a565c6dba6cc76d82a4da0fa767f7962
|
File details
Details for the file pykitml-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pykitml-0.1.3-py3-none-any.whl
- Upload date:
- Size: 93.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c9beffc244b60430ebf003262a6182e7c3b5fab2866b6a5a6cfd46fbf1cd77
|
|
| MD5 |
20311da5b869649f550e9b0d434fb2b2
|
|
| BLAKE2b-256 |
299d8745e5074bbe8e95d5807d7ec3727f4c811c625206d8384cbcfb67b5b43a
|