[Machine Learning step by step][By jy]2.2.1 统计学习:scikit-learn库的设置和估计器对象

第一次翻译,翻译的不足之处请大家多多指教。谢谢

2.2.1  统计学习:scikit-learn库的设置和估计器对象 
2.2.1.1数据集

在scikit-learn库中,我们使用二维数组来处理一个到多个数据集,这些数据集可以理解成一系列的多维的观测数据集。我们说这个数组的第一个轴是样本轴,而第二个是特征轴。


Scikit库附带的简单例子:鸢尾花数据集:

>>> from sklearn import datasets
>>> iris = datasets.load_iris()
>>> data = iris.data
>>> data.shape
输出为(150,4)
这个数据集是由150个鸢尾花的观测值,每一个观测值是由4个特征组成:花萼、花瓣长度、花瓣宽度,在虹膜备注中有详细说明
如果数据没有初始化成(N个样本,N个特征),必须要对数据进行预处理来让scikit使用。

下面是一个数据预处理的例子:

这个数字数据集是用1797 个8*8手写数字图像组成:



>>> digits = datasets.load_digits()
>>> digits.images.shape
(1797, 8, 8)
>>> import pylab as pl 
>>> pl.imshow(digits.images[-1], cmap=pl.cm.gray_r) 

在scikit库中使用此数据,我们把每一个8*8的数据集转换成长度为64的特征向量

>>> data = digits.images.reshape((digits.images.shape[0], -1))

2.2.1.2 估计对象
数据拟合:scikit-learn 应用的主要的API是estimator(评估量)。一个estimator(评估量)是从数据学习的目标,可能是分类,回归或者聚类算法或者一个能从原始数据得到有用的特征的转换器。
每一个评估量对象都提供一个fit方法,函数的参数一个通常是二维数组的数据集;

>>> estimator.fit(data)

参数估计:在实例化或者修改相应的属性时,所有的估计量的参数都可以被设置:

>>> estimator = Estimator(param1=1, param2=2)
>>> estimator.param1

得到结果:1
       被估计的参量:当估计量来拟合数据时,数据来估算参数。所有的被估计的参量都是估计量对象的属性,而且都已下划线来结尾:

>>> estimator.estimated_param_




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Machine Learning: Step-by-Step Guide To Implement Machine Learning Algorithms with Python By 作者: Rudolph Russell ISBN-10 书号: 1719528403 ISBN-13 书号: 9781719528405 出版日期: 2018-05-22 pages 页数: 106 This book contains illustrations and step-by-step explanations with bullet points and exercises for easy and enjoyable learning. Benefits of reading this book that you’re not going to find anywhere else: Introduction to Machine Learning Classification How to train a Model Different Models Combinations CHAPTER1 INTRODUCTION TO MACHINE LEARNING Theory What is machine learning? Why machine learning? When should you use machine learning? Types of Systems of Machine Learning Supervised and unsupervised learning Reinforcement Learning Batch Learning Online Learning Instance based learning Model-based learning Bad and Insufficient Quantity of Training Data Poor-Quality Data Irrelevant Features Testing Overfitting the Data Underfitting the Data EXERCISES SUMMARY REFERENCES CHAPTER2 CLASSIFICATION Installation The MNIST Measures of Performance Confusion Matrix Recall Recall Tradeoff ROC Multi-class Classification Training a Random Forest Classifier Error Analysis Multi-label Classifications Multi-output Classification EXERCISES REFERENCES CHAPTER3 HOW TO TRAIN A MODEL Linear Regression Computational Complexity Gradient Descent Batch Gradient Descent Stochastic Gradient Descent Mini-Batch Gradient Descent Polynomial Regression Learning Curves Regularized Linear Models EXERCISES SUMMARY REFERENCES Chapter4 Different models combinations
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值