再看scikit-learn

粗略的上完北京理工大学礼欣老师的课以后,还是有很多疑问,这不,拿起scikit-learn的官方文档,重新撸一遍。

scikit-learn的安装以及简介见之前的博客:

http://hugo.qinqianshan.com/meachine-learning2-sklearn/

一、数据前准备

1.数据集的格式 scikit-learn一般处理的是二维数据,我们可以理解第一维的是样本,第二维的是特征。 例如:

>>> from sklearn import datasets
>>> iris = datasets.load_iris()
>>> data= iris.data
>>> data.shape
(150, 4)

>>> iris.DESCR
'Iris Plants Database\n====================\n\nNotes\n-----\nData Set Characteristics:\n    :Number of 

我们可以看到这个数据,这个iris的数据集有150个样本,每个样本有4个特征。如果数据集不是已这样的形式呈现(n_samples, n_features), 那我们就需要处理一下,好让sklearn能处理。 (怎么处理呢?)

还有一种电子数据集。例如手写图片,它就是由1797 8x8 构成

>>>i
>>> digits.images.shape
(1797, 8, 8)
>>> import matplotlib.pyplot as plt 
>>> plt.imshow(digits.images[-1], cmap=plt.cm.gray_r) 

To use this dataset with the scikit, we transform each 8x8 image into a feature vector of length 64
>>>
>>> data = digits.images.reshape((digits.images.shape[0], -1))

2.对数据的评估 (这一块的不是太了解,回头再来看)

>>> estimator.fit(data)
Estimator parameters: All the parameters of an estimator can be set when it is instantiated or by modifying the corresponding attribute:
>>>
>>> estimator = Estimator(param1=1, param2=2)
>>> estimator.param1
1
Estimated parameters: When data is fitted with an estimator, parameters are estimated from the data at hand. All the estimated parameters are attributes of the estimator object ending by an underscore:
>>>
>>> estimator.estimated_param_ 

ps:还是缺乏整体认知,先撸几个例子后,再来看这些概念

参考资料:

http://scikit-learn.org/stable/tutorial/statistical_inference/settings.html#datasets

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn