04 Machine Learning Overview

A. Machine learning scenarios

1) Natural Language Processing

2) unmanned

3) Computer Vision

4) recommendation system

II. Characteristics engineering

1. Data Type

1) discrete data

Recording the number of different types of individual data obtained, also known as the count data, all of these data are all integers, and can not be subdivided, can not further increase their accuracy.

2) Continuous Data

Variable can take any of a number within a certain range, i.e., the values ​​may be continuously variable, e.g., length, time, mass value and the like, usually integer such non-integer, contains the fractional part.

 

Note: Just remember, is within the range of discrete inseparable, continuous type is divided into sections

2. Available data set

 

 

 

Kaggle URL: https: //www.kaggle.com/datasets

UCI datasets URL: http://archive.ics.uci.edu/ml/

scikit-learn Web site: http://scikit-learn.org/stable/datasets/index.html#datasets

3. What type of data is

Feature project is to convert the raw data into a feature potential problems better represent predictive model of the process, thereby increasing the accuracy of the model data is unknown.

Meaning: a direct impact on the predicted results of the model

4.Scikit-learn presentation

l Python language machine learning tool

l Scikit-learn including the realization of a number of well-known machine learning algorithms

l Scikit-learn documentation complete, easy to use, rich API, making it popular in academia.

l currently stable version 0.18

5. sklearn feature extraction API

5.1 dictionary feature extraction

Dictionary of feature values ​​of:

sklearn.feature_extraction.DictVectorizer

 

5.2one-hot encoding

 

 

 

After encoding, the result is:

 

 

 

5.3 text feature extraction processing

Characteristic values ​​of the text:

sklearn.feature_extraction.text.CountVectorizer

 

 

 

5.4 TF-IDF

1) TF-IDF's main idea is: If the high probability of a word or phrase that appears in an article,

And rarely seen in other articles, the word or phrase is considered to have a good class discrimination

Capability, suitable for classification

2) TF-IDF作用:用以评估一字词对于一个文件集或一个语料库中的其中一份文件的重要程度。

3) sklearn.feature_extraction.text.TfidfVectorizer

分类机器学习算法的的重要依据

 

 

 

6.数据的特征处理

特征处理:通过特定的统计方法(数学方法)将数据转换成算法要求的数据

l  数值型数据:标准缩放:

              1、归一化

        2、标准化

              3、缺失值

l  类别型数据:one-hot编码

l  时间类型:时间的切分

6.1特征处理API:sklearn. preprocessing
6.2归一化

特点:通过对原始数据进行变换把数据映射到(默认为[0,1])之间

 

 

 

sklearn.preprocessing.MinMaxScaler

 

 

 

注意在特定场景下最大值最小值是变化的,另外,最大值与最小值非常容易受异常点影响,所以这种方法鲁棒性(即稳定性)较差,只适合传统精确小数据场景。

6.3标准化

特点:通过对原始数据进行变换把数据变换到均值为0,方差为1范围内

 

l  对于归一化来说:如果出现异常点,影响了最大值和最小值,那么结果显然会发生改变

l  对于标准化来说:如果出现异常点,由于具有一定数据量,少量的异常点对于平均值的影响并不大,从而方差改变较小。

 

特征化API:scikit-learn.preprocessing.StandardScaler

 

 

 

在已有样本足够多的情况下比较稳定,适合现代嘈杂大数据场景。

6.3缺失值处理方法

删除

如果每列或者行数据缺失值达到一定的比例,建议放弃整行或者整列

插补

可以通过缺失值每行或者每列的平均值、中位数来填充

sklearn缺失值API:  sklearn.preprocessing.Imputer

 

 

 

7.特征选择

原因:

l  冗余:部分特征的相关度高,容易消耗计算性能

l  噪声:部分特征对预测结果有负影响

 

特征选择就是单纯地从提取到的所有特征中选择部分特征作为训练集特征,特征在选择前和选择后可以改变值、也不改变值,但是选择后的特征维数肯定比选择前小,毕竟我们只选择了其中的一部分特征。

主要方法(三大武器):

l  Filter(过滤式):VarianceThreshold

l  Embedded(嵌入式):正则化、决策树

l  Wrapper(包裹式)

特征选择API:sklearn.feature_selection.VarianceThreshold

 

 

 

8.降维

API:sklearn. decomposition

8.1 PCA

1)本质:PCA是一种分析、简化数据集的技术

2)目的:是数据维数压缩,尽可能降低原数据的维数(复杂度),损失少量信息。

3)作用:可以削减回归分析或者聚类分析中特征的数量

高维度数据容易出现的问题:

       特征之间通常是线性相关的

 

 

 

三.机器学习基础

1.开发流程

 

 

 

机器学习模型:

       通过一种映射关系将输入值到输出值。

2.机器学习算法分类

1)监督学习

l  分类: k-近邻算法、贝叶斯分类、决策树与随机森林、逻辑回归、神经网络

l  回归:线性回归、岭回归

l  标注:隐马尔可夫模型     (不做要求)

2)无监督学习

       聚类:k-means

3.监督学习与无监督学习

 

1)监督学习(英语:Supervised learning),可以由输入数据中学到或建立一个模型,并依此模式推测新的结果。输入数据是由输入特征值和目标值所组成。函数的输出可以是一个连续的值(称为回归),或是输出是有限个离散值(称作分类)。

2)无监督学习(英语:Supervised learning),可以由输入数据中学到或建立一个模型,并依此模式推测新的结果。输入数据是由输入特征值所组成。

4.分类、回归

1)分类是监督学习的一个核心问题,在监督学习中,当输出变量取有限个离散值时,预测问题变成为分类问题。最基础的便是二分类问题,即判断是非,从两个类别中选择一个作为预测结果。

2)回归是监督学习的另一个重要问题。回归用于预测输入变量和输出变量之间的关系,输出是连续型的值。

四.sklearn数据集

1.数据集划分

一般会划分为训练集和测试集。

l  训练数据:用于训练,构建模型

l  测试数据:在模型检验时使用,用于评估模型是否有效

比例一般有三种:70%:30%、80%:20%、75%:25%(第三种最常用)

 

API:sklearn.model_selection.train_test_split

数据集划分:

 

 

 

2.数据集加载

API:

 

 

 

获取到的数据集的返回类型:

 

3.转换器与预估器

1)转换器:把数据进行转换

fit_transform()方法相当于先调用fit(),再调用transform()

使用fit()+transform()时需注意每一次fit()之后的数据集应与transform()一致,不然得出的数据将会是用fit所传数据算出来的均值,标准差等来对数据集进行转换。

 

 

 

2)估计器

估计器需要输入x_test、y_test测试集的数据进行预测。

l  y_predict = predict (x_test)

l  预测准确率:score(x_test,y_test)

 

Guess you like

Origin www.cnblogs.com/yaopeiyun/p/12179919.html