scikit-learn Tutorials
An introduction to machine learning with scikit-learn
Machine learning: the problem setting
ML中数据若是多维特征,则被称为 multivariate data,即多个feature。
Loading an example dataset
带有一些小数据集如iris。dataset 是类字典对象,其包含了数据体和数据的元信息。
如iris.data ,iris.target
值得注意的是,所有数据都被表示为(n_samples, n_features)的2D数据。这意味着图片都被展平为向量了。如果需要载入外部数据集,需要用7.4节的东西
Learning and predicting
使用estimator做分类:estimator必须有fit方法和predict方法。SVC是一个分类的例子:
>>> from sklearn import svm
>>> clf = svm.SVC(gamma=0.001, C=100.)
Conventions
sklearn遵循一些传统使得模型更具预测性:
- Type casting:将数据默认转化为float64
下面代码预测结果是str类型的,这是因为传入的target就是str:
>>> clf.fit(iris.data, iris.target_names[iris.target])
SVC()
>>> list(clf.predict(iris.data[:3]))
['setosa', 'setosa', 'setosa']
- Refitting and updating parameters:可以用set_params()方法改变超参数
- Multiclass vs. multilabel fitting:可以实现标签分类。传入什么样子的target,预测就是
A tutorial on statistical-learning for scientific data processing
Statistical learning: the setting and the estimator object in scikit-learn
Datasets
数据都是二维表示的,第一个轴是sample 轴,第二个轴是feature轴。如果输入数据不是这样的形状,则必须经过预处理将其转换为这种形状.
iris.DESCR详细描述了数据信息
Estimators objects
estimator是核心对象,是一个可以从数据中学习,或者提取、转换特征的对象:the main API implemented by scikit-learn is that of the estimator. An estimator is any object that learns from data; it may be a classification, regression or clustering algorithm or a transformer that extracts/filters useful features from raw data.
查看其参数字典:
estimator.estimated_param_