《sklearn机器学习第二版》(加文海克著)学习笔记

本文是一本机器学习书籍的阅读笔记,附sklearn示例程序。书中从调用函数角度介绍常用机器学习方法,涵盖线性回归、逻辑回归、决策树等。涉及监督、无监督、半监督和强化学习,还讲解了偏差方差、特征提取等知识,注重代码实践,原理易懂。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本书附以sklearn机器学习示例程序,从调用函数的角度解释了常用的机器学习的方法,包括线性回归、逻辑回归、决策树、SVM、朴素贝叶斯、ANN、K-means、PCA。原理粗浅易懂,注重代码实践。本文作为该书的阅读笔记,仅供参考。

第一章:机器学习基础

0.机器学习:监督学习(分类、回归)、无监督学习(聚类、降维)、半监督学习、强化学习

其中无监督学习尝试在数据中发现模式或规律;强化学习靠近监督学习的一端,从决策中接受反馈(奖励或惩罚),但错误不会显式地修正。

1. 偏差(衡量欠拟合)与方差(衡量过拟合)

2. scikit-learn拥有BSD许可证,可应用到商业中

第二章:简单线性回归

0.简单线性回归假设解释变量与响应变量之间存才线性关系,使用超平面(线性面)进行建模。超平面比特征空间少一个维度。

1.求解方法,最小二乘。y=kx+b:     k=cov(x,y)/var(x),     b=y_-k*x_

2.评价指标,皮尔斯相关系数r的平方

第三章:用K近邻算法分类和回归

0.KNN可用于分类和回归(加权均值),运用与推进和搜索。

1.KNN是惰性学习模型、非参数模型。可以实现立刻预测,但是代价大。勤奋学习如线性回归、逻辑回归、SVM、决策树等训练时耗费资源,测试时代价小。

2.特征缩放/标准化/归一化

第四章:特征提取

0. 文本特征:

词袋模型(给张单词表,每个词对于one-hot的一位进行词频统计,逆频率统计tf-idf),每个句子的特征对单词表中每个单词的出现频率;

词向量,每个词用特征向量表示。

第五章:从简单线性回归到多元线性回归

0.多元线性回归:y=k1*x1+k2*x2+....+b

1.多项式回归:y=k1*x1+k2*x1**2+b  用以捕获曲线关系

2.加入正则化,若是二范数正则项则成为岭回归

第六章:从线性回归到逻辑回归

0.正态分布的均值、中位数和众数都相同

1.sklearn交叉验证集成函数、网格搜索集成函数

2.多类别分类中对每个类使用一个二元的逻辑回归模型

3.泛化的线性模型使用一个连接函数(激活函数)来联系解释变量的线性组合,其模型不一定是线性的

第七章:朴素贝叶斯

0.生成模型与判别模型 参考 https://blog.youkuaiyun.com/qq_38742161/article/details/91955893

第八章:非线性分类和决策树回归

0.决策树可用来分类和回归,无需标准化数据,是一种非线性模型,可以容忍特征缺失

1.信息熵 ,用以确定不确定性的程度,H(X)=-np.sum( p(xi)logp(xi) )

2.ID3(迭代二叉树第三代算法)划分节点时采用最大信息增益来衡量,每次将不确定性下降幅度最大。若幅度相等,则随机取特征当做当前划分的节点特征。最大信息增益等于父节点增益减去各个子节点增益的加权均值,权值为当前子节点的样本数比上父节点的样本数:IG(T,a)=H(T)-np.sum( n/N*H(n) )

3.另外一种衡量信息下降的方式是基尼不纯度

4.决策树容易过拟合,需要剪枝(最大深度、每个节点划分样本的个数)或者集成学习(随机森林)

第九章集成方法:从决策树到随机森林

0.降低方差、过拟合:随机森林,每个树自发重采样,每个样本被选到的个数为零或多次

1.降低偏差、欠拟合:adaboost,所有样本均参与训练,每次赋予不同权值,级联形式

第十章:感知机

0.线性模型:线性回归、逻辑回归、感知机

1.典型线性不可分问题:异或,需要核化或者ANN(多个感知机)

第十一章:从感知机到支持向量机

0.当使用线性模型逼近非线性模型时,初步操作是增加特征空间的维度,如多项式回归。but带来计算问题和泛化难。

1.SVM,可用来分类和回归,利用核函数可将特征映射到更高维的空间。 高斯核产生的特征空间可以拥有无限维。SVM的优化函数是一个凸优化问题。求解时利用强对偶关系与SMO(序列最小优化算法,将优化问题分解成小的子问题,类似于分治思想)。

第十二章:从感知机到人工神经网络

0.sklearn不支持GPU,无法建立大型CNN/RNN

1.ANN就是多个感知机,单个感知机无法完成异或运算,但是可以采用多个的与或非进行表示。

第十三章:K-means

0.确定超参数k,采用手肘法,一种启发式方法,计算不同K时的类内方差,找到梯度最大的端对应的K值即可。

1.K-means是一种局部最优的求解,与初值设定相关(类中心的选取)

第十四章:主成分分析降维

0.PCA:缓解维度诅咒、压缩数据、可视化

1.PCA也叫KLT,将一系列可能相关的高维变量减少至被称为主成分的低维度线性不相关合成变量,主要思想:最大投影方差或最小平方误差。

Mastering Machine Learning with scikit-learn - Second Edition by Gavin Hackeling English | 24 July 2017 | ASIN: B06ZYRPFMZ | ISBN: 1783988363 | 254 Pages | AZW3 | 5.17 MB Key Features Master popular machine learning models including k-nearest neighbors, random forests, logistic regression, k-means, naive Bayes, and artificial neural networks Learn how to build and evaluate performance of efficient models using scikit-learn Practical guide to master your basics and learn from real life applications of machine learning Book Description Machine learning is the buzzword bringing computer science and statistics together to build smart and efficient models. Using powerful algorithms and techniques offered by machine learning you can automate any analytical model. This book examines a variety of machine learning models including popular machine learning algorithms such as k-nearest neighbors, logistic regression, naive Bayes, k-means, decision trees, and artificial neural networks. It discusses data preprocessing, hyperparameter optimization, and ensemble methods. You will build systems that classify documents, recognize images, detect ads, and more. You will learn to use scikit-learn's API to extract features from categorical variables, text and images; evaluate model performance, and develop an intuition for how to improve your model's performance. By the end of this book, you will master all required concepts of scikit-learn to build efficient models at work to carry out advanced tasks with the practical approach. What you will learn Review fundamental concepts such as bias and variance Extract features from categorical variables, text, and images Predict the values of continuous variables using linear regression and K Nearest Neighbors Classify documents and images using logistic regression and support vector machines Create ensembles of estimators using bagging and boosting techniques Discover hidden structures in data using K-Means clustering Evaluate the performance of machine learning systems in common tasks About the Author Gavin Hackeling is a data scientist and author. He was worked on a variety of machine learning problems, including automatic speech recognition, document classification, object recognition, and semantic segmentation. An alumnus of the University of North Carolina and New York University, he lives in Brooklyn with his wife and cat. Table of Contents The Fundamentals of Machine Learning Simple linear regression Classification and Regression with K Nearest Neighbors Feature Extraction and Preprocessing From Simple Regression to Multiple Regression From Linear Regression to Logistic Regression Naive Bayes Nonlinear Classification and Regression with Decision Trees From Decision Trees to Random Forests, and other Ensemble Methods The Perceptron From the Perceptron to Support Vector Machines From the Perceptron to Artificial Neural Networks Clustering with K-Means Dimensionality Reduction with Principal Component Analysis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值