8.1 机器学习库
(1) scikit-learn ---- Machine Learning in Python
scikit-learn (formerly scikits.learn) is an open source machine learning library for the Python programming language. It features various classification, regression and clustering algorithms including support vector machines, logistic regression, naive Bayes, random forests, gradient boosting, k-means and DBSCAN, and is designed to interoperate with the Python numerical and scientific libraries NumPy and SciPy.
最初于2007年发布的scikit-learn是为机器学习开发的开源库。这个传统的框架是用Python编写的,并且包含了几种机器学习模型,包括分类,回归,聚类和降维。

Scikit-learn是在另外三个开源项目Matplotlib,NumPy和SciPy上设计的,它专注于数据挖掘和数据分析。
在线学习:https://mofanpy.com/tutorials/machine-learning/sklearn/
(1)sklearn的安装
安装Anaconda(Anaconda的免费发布版提供scikit-learn)(建议)
pip虚拟环境安装最新版本
(2)sklearn机器学习简介
机器学习分类
(1)监督学习:数据包含有要预测的额外属性。
分类:如果所期待的输出包含一个或多个离散变量,则该任务称为分类。
回归:如果所期待的输出包含一个或多个连续变量,则该任务称为回归。
(2)无监督学习:训练数据由一组输入向量x组成,没有任何对应的目标值。
训练集与测试集
在该训练集上我们学习一些属性;
在该测试集上我们测试学习到的属性。
示例数据集
回归:波士顿房价数据集。
from sklearn import datasets iris = datasets.load_iris() digits = datasets.load_digits()
boston = datasets.load_boston()
学习和预测
在scikit-learn中,分类的一个估计器(estimator)是一个Python对象,该对象实现
fit(X, y)和predict(T)方法。from sklearn import svm clf = svm.SVC(gamma=0.001, C=100.)
result = clf.fit(digits.data[:-1], digits.target[:-1])
result.predict(digits.data[-1:])
估计器对象
拟合数据 : scikit-learn 实现的主要API是
estimator(估计器). 估计器(estimator)是在数据中进行学习的任何对象; 它可以是分类、回归或聚类算法或从原始数据中提取/过滤有用特征的转换器。所有估计器(estimator)对象都公开一个“fit”方法,该方法接受一个数据集(通常是二维阵列)。估算器参数 : 估计器(estimator)的所有参数可以在实例化时设置,也可以在创建估计器(estimator)之后通过修改相应的属性来设置。
拟合参数 : 当估计器(estimator)拟合完数据之后,所有参数可从估计器(estimator)中获取。拟合参数都是估计器(estimator)对象以下划线结尾的属性
(2) mlpy ---- Machine Learning Python
mlpy is a Python module for Machine Learning built on top of NumPy/SciPy and the GNU Scientific Libraries.mlpy provides a wide range of state-of-the-art machine learning methods for supervised and unsupervised problems and it is aimed at finding a reasonable compromise among modularity, maintainability, reproducibility, usability and efficiency. mlpy is multiplatform, it works with Python 2 and 3 and it is Open Source, distributed under the GNU General Public License version 3.

