Skip to main content
# Python wrapper for the machinelearningforkids.co.uk API

This library was designed for use with [machinelearningforkids.co.uk](https://machinelearningforkids.co.uk).

## Installation

Use pip to install the `ml4k` package:

sudo pip install ml4k

## Usage

In order to use your machine learning model, create a `Model` object
with your project's API key:

import ml4k

API_KEY = "PASTE-API-KEY-HERE"
model = ml4k.Model(API_KEY)


The following methods are available:

### `model.classify(data)`

Classifies the given data and returns a dictionary with the result. The
result dictionary contains the `"label"` and `"confidence"` values.


### `model.add_training_data(label, data)`

Adds training data to the given label "bucket". You can pass text,
images, or a list of numbers.


## Examples

### Recognizing Text

# Get input from user and pass it to our model
command = input("Type a command: ")
result = model.classify("Turn on the lamp")

if result["label"] == "lamp_on":
print("Turning on the lamp")
elif result["label"] == "lamp_off":
print("Turning off the lamp")


### Recognizing Images

Recognizing images is similar, but you need to pass binary image data.
There are many was to get image data in python, such as opening and
reading a file, or capturing from the webcam using a the
[SimpleCV](http://simplecv.org/) library.

Images will be automatically downsized before sending to the API.

# Assuming you have image data stored as a binary string...
result = model.classify(image)
if result["label"] == "dog":
print("That's a dog")
elif result["label"] == "cat":
print("That's a cat")

Release files for ml4k 0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ml4k 0.8
File Size Uploaded
ml4k-0.8.tar.gz 3.0 kB Details

Release files / ml4k-0.8.tar.gz

Download URL ml4k-0.8.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ed77e874821f566567d68cfeb59200e02de596360e20a86346c75d0b1552c440
BLAKE2b-256 checksum
How to use checksums
8aa8e3a93bcdb7e6b1f4a7117fe917e10282b126fabe0631c2bf159e0162df16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.8 This release

1 release file

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

1 release file

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page