当前位置:网站首页>R语言书籍学习03 《深入浅出R语言数据分析》-第八章 逻辑回归模型 第九章 聚类模型
R语言书籍学习03 《深入浅出R语言数据分析》-第八章 逻辑回归模型 第九章 聚类模型
2022-06-11 21:39:00 【深竹清风】
1 逻辑回归模型
1.1 逻辑回归
逻辑回归模型属于广义的线性模型,在数学上,GLM可以表示为


1.2 构建回归模型
使用glm()构建逻辑回归模型,在逻辑回归模型中,使用default特征作为因变量,其他作为自变量。
modle<-glm(default~., data=default_trn,family="binomial")
#family="gaussian"表示调用glm等同于lm
1.3 逻辑回归预测
使用predict()函数进行预测,指定type="response"。
predict(model_glm,type="response")1.4 逻辑回归评估
评估分类模型最常见的事情可能是使用交叉表将实际响应值与预测响应值进行比较,可以使用base中的table()函数生成此矩阵。
trn_tab<-table(predicted=trn_pred, actual= default_trn$default)1.5 总结
逻辑回归模型适用于二分类问题。ROC、KS等方法被用来衡量模型的优劣。
2 聚类模型
2.1 概述
聚类是一种非监督的机器学习模型,用于识别数据中存在的模式。基本思想是计算样本之间的相似性。有K均值聚类、分层聚类、Medoids聚类等方法。
2.2 K均值聚类——确定K值
可以使用Gap统计法、Elbow方法等。详见其他R语言数据分析与挖掘的介绍。
2.3 层次聚类
dist_data<-dist(food[,-1],method="euclidean")
hdata<-hclust(dist_data)
#绘制树形图2.4 Medoids聚类(PAM)
K均值算法使用均值获得中心点,但均值对异常值敏感。这个问题通过PAM解决,PAM在数据中搜索k个代表性对象或中间体。在找到k个代表性对象后,通过将每个观察数据指定到最近的中间体来构建k个簇。
food_pam<-pam(food[,-1],3)

2.5 总结
聚类分析是机器学习中的一种非监督算法,可以用来识别数据中的潜在模式。最常用的是K均值聚类和层次聚类。
边栏推荐
- How to manually send events exposed by SAP commerce cloud mock application using SAP kyma console
- How to realize double speed playback and fast forward for restricted ckplayer players
- C语言实现八种排序(2)
- Leetcode-155-minimum stack
- Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
- LeetCode-76-最小覆盖子串
- Codeworks round 744 (Div. 3) problem solving Report
- 华为设备配置H-VPN
- 如何使用 SAP Kyma 控制台手动发送 SAP Commerce Cloud Mock 应用暴露的事件
- 实现栈和队列
猜你喜欢

RPA super automation | nongnongji and cloud expansion accelerate financial intelligent operation
![Game client performance (memory) [previous]](/img/b6/869b83e92efcdf95aa6bd5e8ff0d10.jpg)
Game client performance (memory) [previous]

快速排序的优化

Master of a famous school has been working hard for 5 years. AI has no paper. How can the tutor free range?

189. 轮转数组

LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)

LeetCode-98-验证二叉搜索树

学习位段(1)

Leetcode-129- sum of numbers from root node to leaf node

Leetcode-110-balanced binary tree
随机推荐
快速排序的三种方法
Classes and objects (3)
Endnotex9 introduction and basic tutorial instructions
Game client performance (memory) [previous]
Leetcode - 第2天
Codeworks round 744 (Div. 3) problem solving Report
AC automata
八、BOM - 章节课后练习题及答案
Apache local multi port configuration
RPA超自动化 | 农耕记携手云扩加速财务智能化运营
如何将SAP API Hub 上提供的工作流导入到 SAP BTP 上
线性表的链式存储结构
Servlet get form data
实现栈和队列
LeetCode-155-最小栈
LeetCode-129-求根节点到叶节点数字之和
RPA+低代码为何是加速财务数字化转型之利器?
LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
类和对象(4)
每日一题 -- 验证回文串