MILK - Python 机器学习工具包


MIT
跨平台
C/C++

软件简介

MILK(MACHINE LEARNING TOOLKIT) 是 Python 语言的机器学习工具包。

它主要是在很多可得到的分类比如
SVMS、K-NN、随机森林以及决策树中使用监督分类法,它还可执行特征选择。这些分类器在许多方面相结合,可以形成不同的例如无监督学习、密切关系传播和由
MILK 支持的 K-means 聚类等分类系统。

MILK 关注速度和内存的使用,因此大多数对性能比较敏感的代码都是用 C++ 编写的。为了方便起见,基于 Python 实现了接口。

示例代码

测试对一些 features,labels 数据的分类情况,通过交叉验证测量:

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())

如果想要使用分类器,可以创建一个 learner object 并调用它的 train() 方法:

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)

特性

  • 支持向量机。使用封装了 pythonesque 的 libsvm solver

  • LASSO 算法

  • K-means 使用的内存小,可有效地对数百万个实例进行集群

  • 随机森林

  • 自组织地图

  • 逐步判别分析特征选择

  • 非负矩阵分解(Non-negative Matrix Factorization,NMF)算法

  • AP(Affinity Propagation)聚类算法