1.1 特征映射准备
对于包含字符串的分类特征,需要先转换为数值型才能进行后续的相关性分析。
data["Home Ownership"].value_counts()#查看
1.2 使用嵌套字典进行特征映射
mappings = {
"Years in current job": {
"10+ years": 10,
"2 years": 2,
"3 years": 3,
"< 1 year": 0,
"5 years": 5,
"1 year": 1,
"4 years": 4,
"6 years": 6,
"7 years": 7,
"8 years": 8,
"9 years": 9
},
"Home Ownership": {
"Home Mortgage": 0,
"Rent": 1,
"Own Home": 2,
"Have Mortgage": 3
}
}
# 使用映射字典进行转换
data["Years in current job"] = data["Years in current job"].map(mappings["Years in current job"])
data["Home Ownership"] = data["Home Ownership"].map(mappings["Home Ownership"])
data.info()
1.3特征名中文映射
二、相关系数热力图
1.
相关系数的含义**:
- 取值范围: [-1, 1]
**注意事项**:
- 热力图适合展示连续变量之间的关系
- 对于离散变量,相关系数的意义需要谨慎解读
2.主要参数解释
- `annot=True`: 在每个单元格中显示数值
- `cmap`: 配色方案
- `vmin, vmax`: 设置颜色条的最小值和最大值
- `fmt='.2f'`: 数值格式,保留2位小数
- `linewidths`: 单元格之间的线宽
- `center`: 设置颜色的中心值(通常设为0)
- `square=True`: 设置单元格为正方形
- `cbar_kws`: 颜色条的参数设置
三、子图
四、enumerate()函数介绍:同时获得索引和值
五、绘制连续的箱线图

751

被折叠的 条评论
为什么被折叠?



