分组分析,是指将客体(问卷、特征、现实)按研究要求进行分类编组,使得同组客体之间的差别小于各种客体之间的差别,进而进行分析研究的方法。其特点在于不依赖于原始资料分布的正常性假设,可以按任意规律分布,在分析既包括数量资料,又包括质量资料的混合资料时尤为重要。
离散属性的分组比较容易,而连续属性的分组,分组前要进行离散化
![img_89bc0985aa861e2dfbd5fa8c8a9959d0.png](https://i-blog.csdnimg.cn/blog_migrate/b6b65ce9fb1a09dfdffb8e347c135512.png)
![img_6fc5138c7dabcd6cb90c5c67570b9c74.png](https://i-blog.csdnimg.cn/blog_migrate/83c428ee00238637c24d12992f8a5f7a.png)
![img_20111b886fdcc7088dfa85dd298622ce.png](https://i-blog.csdnimg.cn/blog_migrate/9efde581357113212caef7e941d87d99.png)
image.png
![img_71a70bb08db5d322913e8535bdeae4e5.png](https://i-blog.csdnimg.cn/blog_migrate/cd261e43f5363bf7ff86ad8e0e7273c9.png)
离散值基尼系数的计算
![img_1d84c09be39a4ad3ba21f1de2f4cb8e8.png](https://i-blog.csdnimg.cn/blog_migrate/cdc74a378f33fdef3774ce209cb77653.png)
连续值的基尼系数的计算
代码实现
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_context(font_scale=1.5)
df = pd.read_csv("./data/HR.csv")
sns.barplot(x="salary",y="left",hue="department",data=df)
plt.show()
![img_d74a76e29b226b5fc91a8a5b65c2e64e.png](https://i-blog.csdnimg.cn/blog_migrate/ea6ec7f41b7eb4ec206ec948987799e5.png)
未去除异常值,因此图像比较模糊
sl_s = df["satisfaction_level"]
sl_s = sl_s.dropna()
sns.barplot(list(range(len(sl_s))),sl_s.sort_values())
plt.show()
![img_c93ba53816212ffe8b9a53d65aac602b.png](https://i-blog.csdnimg.cn/blog_migrate/9ecd1f4788defa427827e97df1cc1465.png)
图中有两个明显的拐弯的界限,可以根据界限来对满意度分组