python图像类型分类汇总

news2024/9/24 23:28:55
图型所在包样例例图
热图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.coloradmin.cn/o/2093404.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Leetcode 404-左叶子之和

题目 给定二叉树的根节点 root &#xff0c;返回所有左叶子之和。 题解 二叉树的题目&#xff0c;如果需要返回某个值&#xff0c;可以分左右子树递归计算&#xff0c;最后sumleftright 递归三部曲&#xff1a; 确定递归函数的参数和返回值 判断一个树的左叶子节点之和&…

函数式接口实现策略模式

函数式接口实现策略模式 1.案例背景 我们在日常开发中&#xff0c;大多会写if、else if、else 这样的代码&#xff0c;但条件太多时&#xff0c;往往嵌套无数层if else,阅读性很差&#xff0c;比如如下案例&#xff0c;统计学生的数学课程的成绩&#xff1a; 90-100分&#…

微分方程(Blanchard Differential Equations 4th)中文版Section6.1

拉普拉斯变换 积分变换 在本章中&#xff0c;我们研究了一种工具——拉普拉斯变换&#xff0c;用于解微分方程。拉普拉斯变换是众多不同类型的积分变换之一。一般来说&#xff0c;积分变换解决的问题是&#xff1a;一个给定的函数 y ( t ) y(t) y(t) 在多大程度上“像”一个…

温馨网站练习运用

第二次与团队一起制作网页虽然不进行商用&#xff0c;但是练习一下还是好的&#x1f60a;&#x1f60a; 我主要负责后端部分&#xff0c;该项目用了SpringBoot框架、SpringSecurity的安全框架、结合MyBatis-Plus的数据库查询。如果想看看&#xff0c;网站&#xff1a;温馨网登…

Python基础性知识(中部分)

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言1、Python中的语句1.1 顺序语句1.2 条件语句1.3 循环语句1.3.1 while循环1.3.2 for循环1.3.3 break与continue语句 1.4 综合三大语句制作小游戏--人生重开模拟器…

opencv之形态学

文章目录 1. 什么是形态学2. 形态学操作2.1 腐蚀2.2 膨胀2.3 通用形态学函数2.4 开运算2.5 闭运算2.6 形态学梯度运算2.7 礼帽运算2.8 黑帽运算 1. 什么是形态学 在图像处理领域&#xff0c;形态学是一种基于形状的图像分析技术&#xff0c;用于提取和处理图像的形态特征。这包…

存储架构模式-分片架构和分区架构

分片架构 分片架构就可以解决主从复制存在的问题&#xff0c;如果主机能够承担写的性能&#xff0c;那么主从就够了&#xff0c;如果不能&#xff0c;那么就需要分片架构了。 分片架构设计核心 分片架构设计核心-分片规则 案例1&#xff1a;不合理&#xff0c;因为不同年龄是不…

echarts组件——饼图

echarts组件——饼图 饼图&#xff0c;环形图 组件代码 <template><div :class"classname" :style"{height:height,width:width}" /> </template><script> // 环形图 import * as echarts from echarts require(echarts/them…

计算机毕业设计PySpark+Scrapy农产品推荐系统 农产品爬虫 农产品商城 农产品大数据 农产品数据分析可视化 PySpark Hadoop

(1)能够根据计算机软硬件知识和数学知识给出复杂工程设计的基本思路和解决方案&#xff1b;在考虑社会、健康、安全、法律、文化以及环境等因素下可对设计方案及软硬件系统等在技术、经济等方面进行评价&#xff0c;确认其可行性&#xff1b; (2)能够建立软硬件系统、应用数学、…

【鸿蒙开发】02 复刻学习文档之待办列表

文章目录 一、前言叨叨二、创建应用三、项目初始化及代码分析1. 应用启动入口2. 解读Demo代码并Copy3、常量数据及静态资源文件AppStore下的resourcesentry下的resources 四、效果展示 一、前言叨叨 在考试内容看完之后&#xff0c;并且获取到了高级认证&#xff0c;但是在真正…

linux系统中USB模块鼠标驱动实现

各位开发者大家好,今天主要给大家分享一下,Linux系统中使用libusb的方法以及鼠标驱动实现。 第一:libusb概述 参考网址:* libusb GIT仓库:https://github.com/libusb/libusb.git * libusb 官网:https://libusb.info/ * libusb API接口:https://libusb.sourceforge.io/…

python中logging库使用

文章目录 1、前言2、日志的等级3、logging的基本应用4、logging的进阶应用5、logging的高阶应用6、简单调用7、参考 1、前言 编程代码中&#xff0c;日志的合理使用&#xff0c;能够很好地监控代码的运行过程&#xff1b;在业务部署中&#xff0c;通过日志的记录情况&#xff0…

5G NR 辅同步信号SSS介绍 MATLAB实现

5G NR辅同步信号SSS&#xff0c;和PSS一起包含了小区的全部ID信息&#xff0c;跟NBIOT 和LTE不一样&#xff0c;PSS和SSS并不携带任何的帧信息&#xff0c;只携带帧头同步信息&#xff0c;所以搜索完成PSS和SSS并不知道当前的slot号和帧号&#xff0c;在5G NR中&#xff0c;PSS…

Clion 使用

1. 使用CLion进行ROS开发 安装基本的ROS环境 ROS环境的安装请参考安装ROS。 安装CLion 下载CLion Linux的下载地址如下&#xff1a;CLion 解压CLion 将下载的CLion复制到/opt目录下&#xff08;你可以解压到适合自己的文件夹&#xff0c;只要保证后续使用的路径一致即可…

黑神话悟空-用签名检查以允许加载 mod .pak(安装MOD可以不用再使用“ -fileopenlog “命令)

安装 下载并解压到 BlackMythWukong\b1\Binaries\Win64 位置参考&#xff1a; 安装此 mod 后&#xff0c;再安装.pak类型MOD时就可以不再使用" -fileopenlog "命令也可以生效了.因为该命令可能会导致在具有常规 HDD 的低配置计算机上卡顿。 下载地址&#xff1a;h…

macos 10.15 Catalina 可用docker最新版本 Docker Desktop 4.15.0 (93002) 下载地址与安装方法

按照docker官方的4.16.0版本发行日志"4.16.0: (2023-01-12 Minimum OS version to install or update Docker Desktop on macOS is now macOS Big Sur (version 11) or later.)" , 这个4.16.0版本就必须要求最低版本os为 11版本, 所以 旧版本的macos 10.15 Catalina …

为了支持XR,3GPP R18都做了哪些增强?

这篇是R18 XR enhancement的第二篇,主要看下从NAS->L3->L2->L1针对XR都做了哪些增强。 1 PDU set QoS 在UL和DL中,XR-Awareness有助于优化gNB无线资源调度,但是这里就依赖于 PDU set和data burst。这两个东西是什么意思?其实PDU set就是由一个或多个 PDU组成,这…

【 OpenHarmony 系统应用源码解析 】-- Launcher 桌面布局

前言 阅读本篇文章之前&#xff0c;有几个需要说明一下&#xff1a; 调试设备&#xff1a;平板&#xff0c;如果你是开发者手机&#xff0c;一样可以加 Log 调试&#xff0c;源码仍然是手机和平板一起分析&#xff1b;文章中的 Log 信息所显示的数值可能跟你的设备不一样&…

C语言中的“#”和“##”

目录 开头1.什么是#?2.什么是##?3.#和##的实际应用输出变量的名字把两个符号连接成一个符号输出根据变量的表达式…… 下一篇博客要说的东西 开头 大家好&#xff0c;我叫这是我58。在今天&#xff0c;我们要学一下关于C语言中的#和##的一些知识。 1.什么是#? #&#xff0…

Datawhale X 李宏毅苹果书 AI夏令营-深度学入门task2:线性模型

1.线性模型 把输入的特征 x 乘上一个权重&#xff0c;再加上一个偏置就得到预测的结果&#xff0c;这样的模型称为线性模型&#xff08;linear model&#xff09; 2.分段线性模型 线性模型也许过于简单&#xff0c;x1 跟 y 可能中间有比较复杂的关系。线性模型有很大的限制&…