Skip to main content

Machine Learning in Python

Milk is a machine learning toolkit in Python.

Its focus is on supervised classification with several classifiers available: SVMs (based on libsvm), k-NN, random forests, decision trees. It also performs feature selection. These classifiers can be combined in many ways to form different classification systems.

For unsupervised learning, milk supports k-means clustering and affinity propagation.

Milk is flexible about its inputs. It optimised for numpy arrays, but can often handle anything (for example, for SVMs, you can use any dataype and any kernel and it does the right thing).

There is a strong emphasis on speed and low memory usage. Therefore, most of the performance sensitive code is in C++. This is behind Python-based interfaces for convenience.

To learn more, check the docs at http://packages.python.org/milk/ or the code demos included with the source at milk/demos/.

Examples

Here is how to test how well you can classify some features,labels data, measured by cross-validation:

import numpy as np
import milk
features = np.random.rand(100,10) # 2d array of features: 100 examples of 10 features each
labels = np.zeros(100)
features[50:] += .5
labels[50:] = 1
confusion_matrix, names = milk.nfoldcrossvalidation(features, labels)
print 'Accuracy:', confusion_matrix.trace()/float(confusion_matrix.sum())

If want to use a classifier, you instanciate a learner object and call its train() method:

import numpy as np
import milk
features = np.random.rand(100,10)
labels = np.zeros(100)
features[50:] += .5
labels[50:] = 1
learner = milk.defaultclassifier()
model = learner.train(features, labels)

# Now you can use the model on new examples:
example = np.random.rand(10)
print model.apply(example)
example2 = np.random.rand(10)
example2 += .5
print model.apply(example2)

There are several classification methods in the package, but they all use the same interface: train() returns a model object, which has an apply() method to execute on new instances.

Details

License: MIT

Author: Luis Pedro Coelho (with code from LibSVM and scikits.learn)

API Documentation: http://packages.python.org/milk/

Mailing List: http://groups.google.com/group/milk-users

Features

  • SVMs. Using the libsvm solver with a pythonesque wrapper around it.

  • K-means using as little memory as possible. It can cluster millions of instances efficiently.

  • Random forests

  • Self organising maps

  • Stepwise Discriminant Analysis for feature selection.

  • Non-negative matrix factorisation

  • Affinity propagation

Recent History

The ChangeLog file contains a more complete history.

New in 0.4.0

  • Use multiprocessing to take advantage of multi core machines (off by default).

  • Add perceptron learner

  • Set random seed in random forest learner

  • Add warning to milk/__init__.py if import fails

  • Add return value to gridminimise

  • Set random seed in precluster_learner

  • Implemented Error-Correcting Output Codes for reduction of multi-class to binary (including probability estimation)

  • Add multi_strategy argument to defaultlearner()

  • Make the dot kernel in svm much, much, faster

  • Make sigmoidal fitting for SVM probability estimates faster

  • Fix bug in randomforest (patch by Wei on milk-users mailing list)

New in 0.3.10

  • Add ext.jugparallel for integration with jug

  • parallel nfold crossvalidation using jug

  • parallel multiple kmeans runs using jug

  • cluster_agreement for non-ndarrays

  • Add histogram & normali(z|s)e options to milk.kmeans.assign_centroid

  • Fix bug in sda when features were constant for a class

  • Add select_best_kmeans

  • Added defaultlearner as a better name than defaultclassifier

  • Add measures.curves.precision_recall

  • Add unsupervised.parzen.parzen

New in 0.3.9

  • Add folds argument to nfoldcrossvalidation

  • Add assign_centroid function in milk.unsupervised.nfoldcrossvalidation

  • Improve speed of k-nearest neighbour (10x on scikits-learn benchmark)

  • Improve kmeans on newer numpy (works for larger datasets too)

  • Faster kmeans by coding centroid recalculation in C++

  • Fix gridminize for low count labels

  • Fix bug with non-integer labels for tree learning

New in 0.3.8

  • Fix compilation on Windows

New in 0.3.7

  • Logistic regression

  • Source demos included (in source and documentation)

  • Add cluster agreement metrics

  • Fix nfoldcrossvalidation bug when using origins

New in 0.3.6

  • Unsupervised (1-class) kernel density modeling

  • Fix for when SDA returns empty

  • weights option to some learners

  • stump learner

  • Adaboost (result of above changes)

Release files for milk 0.4.0

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

Source distribution (sdist)

Source distribution for milk 0.4.0
File Size Uploaded
milk-0.4.0.tar.gz 76.1 kB Details

Release files / milk-0.4.0.tar.gz

Download URL milk-0.4.0.tar.gz
Size 76.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cb8b093ba557fbf83fc0ba4c9ab11fe1f6db7604436e3ee077d6457eae583e3d
BLAKE2b-256 checksum
How to use checksums
f57f0e3150141dab43715603e7d2b8db4a365954fd9c1f49118cf61902a5d387
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.1

1 release file

0.6

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

This release

0.4.0 This release

1 release file

0.3.10

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

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