当前位置: 首页 > article >正文

python图像类型分类汇总

图型所在包样例例图
热图seabornimport matplotlib.pyplot as plt
import seaborn as sns
sns.heatmap(df.isnull()) 
plt.show()

Bitmap

Bitmap

import numpy as np
# 获取数据
fraud = data_df[data_df['Class'] == 1]
nonFraud = data_df[data_df['Class'] == 0]

# 相关性计算
correlationNonFraud = nonFraud.loc[:, data_df.columns != 'Class'].corr()
correlationFraud = fraud.loc[:, data_df.columns != 'Class'].corr()

# 上三角矩阵设置
mask = np.zeros_like(correlationNonFraud)# 全部设置0
indices = np.triu_indices_from(correlationNonFraud)#返回函数的上三角矩阵
mask[indices] = True
grid_kws = {"width_ratios": (.9, .9, .05), "wspace": 0.2}
f, (ax1, ax2, cbar_ax) = plt.subplots(1, 3, gridspec_kw=grid_kws, figsize = (14, 9))

# 正常用户-特征相关性展示
cmap = sns.diverging_palette(220, 8, as_cmap=True)
ax1 =sns.heatmap(correlationNonFraud, ax = ax1, vmin = -1, vmax = 1, \
    cmap = cmap, square = False, linewidths = 0.5, mask = mask, cbar = False)
ax1.set_xticklabels(ax1.get_xticklabels(), size = 16);
ax1.set_yticklabels(ax1.get_yticklabels(), size = 16);
ax1.set_title('Normal', size = 20)
# 被盗刷的用户-特征相关性展示
ax2 = sns.heatmap(correlationFraud, vmin = -1, vmax = 1, cmap = cmap, \
ax = ax2, square = False, linewidths = 0.5, mask = mask, yticklabels = False, \
    cbar_ax = cbar_ax, cbar_kws={'orientation': 'vertical', \
                                 'ticks': [-1, -0.5, 0, 0.5, 1]})
ax2.set_xticklabels(ax2.get_xticklabels(), size = 16);
ax2.set_title('Fraud', size = 20);

柱形图matplotlibimport warnings
warnings.filterwarnings('ignore') 
import matplotlib.gridspec as gridspec
v_feat_col = ['V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'V10', 'V11', 'V12', 'V13', 'V14', 'V15',
         'V16', 'V17', 'V18', 'V19', 'V20','V21', 'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28']
v_feat_col_size = len(v_feat_col)
plt.figure(figsize=(16,v_feat_col_size*4))
gs = gridspec.GridSpec(v_feat_col_size, 1)
for i, cn in enumerate(data_df[v_feat_col]):
    ax = plt.subplot(gs[i])
    sns.distplot(data_df[cn][data_df["Class"] == 1], bins=50)# V1 异常  绿色表示
    sns.distplot(data_df[cn][data_df["Class"] == 0], bins=100)# V1 正常  橘色表示
    ax.set_xlabel('')
    ax.set_title('histogram of feature: ' + str(cn))

Bitmap

# 可视化特征重要性
plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = (12,6)

## feature importances 可视化##
importances = clf.feature_importances_
feat_names = data_df_new[x_feature].columns
indices = np.argsort(importances)[::-1]
fig = plt.figure(figsize=(20,6))
plt.title("Feature importances by RandomTreeClassifier")

x = list(range(len(indices)))

plt.bar(x, importances[indices], color='lightblue',  align="center")
plt.step(x, np.cumsum(importances[indices]), where='mid', label='Cumulative')
plt.xticks(x, feat_names[indices], rotation='vertical',fontsize=14)
plt.xlim([-1, len(indices)])

Bitmap

# 是否异常和交易金额关系分析
f, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(16,4))
bins = 30
ax1.hist(data_df["Amount"][data_df["Class"]== 1], bins = bins)
ax1.set_title('Fraud')

ax2.hist(data_df["Amount"][data_df["Class"] == 0], bins = bins)
ax2.set_title('Normal')

plt.xlabel('Amount ($)')
plt.ylabel('Number of Transactions')
plt.yscale('log')
plt.show()

Bitmap

plotly# Months_Inactive_12_mon字段与Attrition_Flag字段的关系(
fig = px.histogram(df, x="Months_Inactive_12_mon", color="Attrition_Flag",title='Number of months with no transactions in the last year')
plotly.offline.iplot(fig)

Bitmap

seabornimport seaborn as sns
Gender = sns.countplot(x = 'Gender',hue = 'Attrition_Flag',data=df1,palette='Set2')
Gen_att = df1.loc[df1['Attrition_Flag']=='Attrited Customer','Gender']
Gen_ex = df1.loc[df1['Attrition_Flag']=='Existing Customer','Gender']
print('Gender of Attrited customer:\n',Gen_att.value_counts())
print('-----------------------------------------------------------')
print('Gender of Existing customer:\n',Gen_ex.value_counts())
print('-----------------------------------------------------------')
print('Gender of Total customer:\n',df1.Gender.value_counts())

Bitmap

# 了解Customer_Age字段与Attrition_Flag字段的关系
import matplotlib.pyplot as plt
sns.set_style('whitegrid')
plt.figure(figsize=(10,8))
sns.set_context('paper', font_scale=1.5)
sns.histplot(x='Customer_Age', data = df1,
             hue ='Attrition_Flag').set_title('Customer by Age')

Bitmap

sns.factorplot(x="Hour", data=data_df, kind="count", size=6, aspect=3)

Bitmap

Bitmap

组合图matplotlib
seaborn
# 正负样本分布可视化
import matplotlib.pyplot as plt
import seaborn as sns
fig, axs = plt.subplots(1,2,figsize=(14,7))
# 柱状图
sns.countplot(x='Class',data=data_df,ax=axs[0])
axs[0].set_title("Frequency of each Class")
# 饼图
data_df['Class'].value_counts().plot(x=None,y=None, kind='pie', ax=axs[1],autopct='%1.2f%%')
axs[1].set_title("Percentage of each Class")
plt.show()

Bitmap

箱型图plotly# Total_Revolving_Bal字段与Attrition_Flag字段的关系(箱型图)
fig = px.box(df, color="Attrition_Flag", y="Total_Revolving_Bal", points="all",title='Total revolving balance on the credit card')
plotly.offline.iplot(fig)

Bitmap

matplotlib# 了解数值型变量的分布
fig, ax= plt.subplots(nrows= 2, ncols = 3, figsize= (14,6))
sns.boxplot(x=df["CNT_CHILDREN"], ax=ax[0][0])
sns.boxplot(x=df["AMT_INCOME_TOTAL"], ax=ax[0][1])
sns.boxplot(x=df["DAYS_BIRTH"], ax=ax[0][2])
sns.boxplot(x=df["DAYS_EMPLOYED"], ax=ax[1][0])
sns.boxplot(x=df["CNT_FAM_MEMBERS"], ax=ax[1][1])
sns.boxplot(x=df["MONTHS_BALANCE"], ax=ax[1][2])
plt.show()

Bitmap

饼图plotly# Card_Category字段统计
fig = px.pie(df1,names='Card_Category',title='Percentage of Card type',hole=0.3)
fig.update_traces(textposition='outside', textinfo='percent+label')
plotly.offline.iplot(fig)

# 可视化Marital_Status字段与Attrition_Flag字段的关系
from plotly.subplots import make_subplots
import plotly.graph_objs as go
fig = make_subplots(
    rows=2, cols=2,subplot_titles=('Total Customer','Existing Customers','Attrited Customers','Residuals'),
    vertical_spacing=0.09,
    specs=[[{"type": "pie","rowspan": 2}       ,{"type": "pie"}] ,
           [None                               ,{"type": "pie"}]            ,                                     
          ]
)

fig.add_trace(
    go.Pie(values=df1.Marital_Status.value_counts().values,
           labels=['Married','Single','Unknow', 'Divorced'],
           pull=[0,0.01,0.03,0.03],
           hole=0.3),
    row=1, col=1
)

fig.add_trace(
    go.Pie(
        labels=['Married', 'Single','Divorced', 'Unknown'],
        values=df1.query('Attrition_Flag=="Existing Customer"').Marital_Status.value_counts().values,
        pull=[0,0.01,0.05,0.05],
        hole=0.3),
    row=1, col=2
)

fig.add_trace(
    go.Pie(
        labels=['Married', 'Single','Unknown','Divorced'],
        values=df1.query('Attrition_Flag=="Attrited Customer"').Marital_Status.value_counts().values,
        pull=[0,0.01,0.05,0.05],
        hole=0.3),
    row=2, col=2
)

fig.update_layout(
    height=700,
    showlegend=True,
    title_text="<b>Martial Status<b>",
)
fig.update_traces(textposition='inside', textinfo='percent+label')
plotly.offline.iplot(fig)

Bitmap

风琴图plotlyfig = fig = px.violin(df, color="Attrition_Flag", y="Total_Trans_Ct", points="all",title='Number of transactions made in the last year')
plotly.offline.iplot(fig)

Bitmap


http://www.kler.cn/news/289909.html

相关文章:

  • 代码随想录训练营day35|46. 携带研究材料,416. 分割等和子集
  • 荆州农商行资产质量下行压力不减,参股多家银行均有股权被冻结
  • Find My轮椅|苹果Find My技术与轮椅结合,智能防丢,全球定位
  • Spark框架
  • Nginx: 使用KeepAlived配置实现虚IP在多服务器节点漂移及Nginx高可用原理
  • 12、Flink 流上的确定性之流处理详解
  • Tomcat8版本以上配置自定义400错误页面
  • ElasticSearch-基础操作
  • PDF处理技巧:如何有效处理 PDF 旋转的技巧
  • WebGIS与WebGL是什么,两者之间的关系?
  • Transformer直接预测完整数学表达式,推理速度提高多个数量级
  • ElementUI实现el-table组件的合并行功能
  • vs2017 Qt CMakeList.txt添加生成Qt LinguistTools的ts文件
  • 程序员学Python编程规范(简单明了!)
  • ESP8266下载固件→连接阿里云
  • 关于SpringMVC的理解
  • linux 内核代码学习(七)
  • 2024 第七届“巅峰极客”网络安全技能挑战赛初赛 Web方向 题解WirteUp
  • go语言自定义包并在其它地方导入
  • 什么是感知器?
  • opencv入门教程
  • 爬楼梯[简单]
  • 力扣SQL仅数据库(196~569)
  • AI图像放大工具,图片放大无所不能
  • vue通过html2canvas+jspdf生成PDF问题全解(水印,分页,截断,多页,黑屏,空白,附源码)
  • Kafka【六】Linux下安装Kafka(Zookeeper)集群
  • 【AI】前向和反向传播的关系
  • 深度学习与电网信号故障诊断:基于卷积神经网络和残差网络的应用
  • 【Grafana】Prometheus结合Grafana打造智能监控可视化平台
  • 15、VSCode自定义Markwown编辑环境