当我们分析特征时,类别特征该可视化怎么做

一、只画类别特征:

1.df[col].value_counts().plot.bar()

2.sns.countplot(df[col])

import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns

# 读取数据文件
telcom=pd.read_csv('F:\\python\\电信用户数据\\WA_Fn-UseC_-Telco-Customer-Churn.csv')

telcom["gender"].value_counts().plot.bar()
sns.countplot(telcom["gender"])

df[col].value_counts().plot.bar(),sns.countplot(df[col])类别特征画条形图df[col].value_counts().plot.bar(),sns.countplot(df[col])类别特征画条形图

 

 二、类别特征和y值,

y值也是类别(0,1)

1.pd.crosstab( df[col] , df[y] ).plot.bar()

2.sns.countplot( df[col], hue=y,data=df)

3.1.sns.barplot( df[col],df[y])   这个可以明显看出不同类别的y值的类型占比

y值是连续型的

1.sns.barplot( df[col],df[y])

pd.crosstab(telcom["gender"],telcom["Churn"]).plot.bar()
sns.countplot(x="gender",hue="Churn",data=telcom)

sns.barplot(telcom["gender"],telcom["Churn"])

df[col].value_counts().plot.bar(),sns.countplot(df[col])类别特征画条形图df[col].value_counts().plot.bar(),sns.countplot(df[col])类别特征画条形图df[col].value_counts().plot.bar(),sns.countplot(df[col])类别特征画条形图

 

相关文章:

  • 2021-07-20
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2021-10-15
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2022-02-08
  • 2022-01-10
  • 2021-08-26
  • 2021-12-29
  • 2022-12-23
相关资源
相似解决方案