# -*-coding:utf-8-*-
# ----------------------
# Author:kevinelstri
# Datetime:2017.2.17
# ----------------------
# -----------------------
# A tutorial on statistical-learning for scientific data processing 科学数据处理的统计学习教程
# http://scikit-learn.org/stable/tutorial/statistical_inference/index.html
# -----------------------
'''
'''
'''
Statistical learning 统计学习:
随着实验科学面临的数据集的大小急剧增加,机器学习技术逐渐发挥着重要的作用。
这个教程将会探索统计学习,机器学习技术就是为了达到统计判断的目的:从数据中获得结论。
scikit-learn 是python中实现经典机器学习的模块,实现了与python库(Numpy, Scipy, matplotlib)的紧密结合
'''
# -------------------------------
# Statistical learning: the setting and the estimator object in scikit-learn
# 统计学习:scikit-learn 的设置和估计对象
# http://scikit-learn.org/stable/tutorial/statistical_inference/settings.html
# -------------------------------
'''
Datasets 数据集:
scikit-learn 是从一个或多个数据集学习信息,这样的数据集也就是二维数组。
二维数组的第一个轴为样本轴(samples axis),第二个轴为特征轴(features axis)
'''
from sklearn import datasets
iris = datasets.load_iris()
data = iris.data
print data.shape # 数据集iris的形状(150, 4),iris数据集由150个观察值构成,每个观察值有4个特征,他们的萼片和花瓣的长度和宽度存储在iris.DESCR
print iris.DESCR
# 由于数据集的最初格式不是(n_samples, n_features), 所以还需要进行预处理,来满足scikit-learn的要求
digits = datasets.load_digits()
print digits.images.shape # (1797, 8, 8)
import matplotlib.pyplot as plt
print plt.imshow(digits.images[-1], cmap=plt.cm.gray_r)
# 将scikit应用于这个数据集上,可以将8*8的图像转换为一个长度为64的特征向量
data = digits.images.reshape((digits.images.shape[0], -1))
print data
'''
Estimators objects 估计对象
Fitting data:数据拟合
scikit-learn 主要实现的功能就是预测器的功能,预测器就是从数据中学习,可能是分类,回归,聚类算法,或者是从原始数据中进行提取和过滤特征
'''
# 一个预测对象包括fit()方法
estimator.fit(data) # 预测器的方法
estinator = Estimator(param1, param2) # 当被实例化或者是更改属性时,所有的参数都可以进行设置
estinator.param1
'''
Estimator parameters 参数估计:
1、当被实例化或者是更改属性时,所有的参数都可以进行设置
2、当数据与估计值匹配时,参数就从数据中估计获得;所有的参数估计都是由以下划线结束的对象估计的属性
'''
estinator.estimated_param_