2022高教社杯全国大学生数学建模竞赛C题 问题三&问题四 Python代码

问题3

在这里插入图片描述

3.1 对附件表单 3 中未知类别玻璃文物的化学成分进行分析,鉴别其所属类型

d3 = d3.fillna(0)
prediction = ["高钾" if i <= 5.46 else '铅钡' for i in d3['氧化铅(PbO)']]
d3['玻璃类型预测'] = prediction

print('鉴别出的玻璃类型如下:')
d3.iloc[:,[0,16]]
鉴别出的玻璃类型如下:
文物编号玻璃类型预测
0A1高钾
1A2铅钡
2A3铅钡
3A4铅钡
4A5铅钡
5A6高钾
6A7高钾
7A8铅钡

3.2 对分类结果的敏感性进行分析

from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
import matplotlib.pyplot as plt

df = d3.iloc[:,2:16]
linkage_data = linkage(df, method='ward', metric='euclidean')
dendrogram(linkage_data, labels=list(d3.iloc[:,0]))
plt.show()

在这里插入图片描述

from sklearn.cluster import AgglomerativeClustering
hierarchical_cluster = AgglomerativeClustering(n_clusters=2, affinity='euclidean', linkage='ward')
labels = hierarchical_cluster.fit_predict(df)
labels
array([1, 0, 0, 0, 0, 1, 1, 0])

当我们对样本进行层次聚类时,得到的聚类簇与鉴别出的玻璃类型相一致

问题4

4.1 针对不同类别的玻璃文物样品,分析其化学成分之间的关联关系

绘图
散点图
import seaborn as sns
sns.pairplot(d12.iloc[:,[2] + list(range(6,20))], hue='类型')
<seaborn.axisgrid.PairGrid at 0x7f10e313dbe0>

在这里插入图片描述

相关系数图
import numpy as np
np.bool = np.bool_
cor = round(d12_Pb.corr(), 2)
fig = px.imshow(cor, text_auto=True, title='铅钡玻璃')
# set figute size
fig.update_layout(autosize=False, width=600, height=600)
# center title
fig.update_layout(title_x=0.5)
fig.show()

在这里插入图片描述

import numpy as np
np.bool = np.bool_
cor = round(d12_K.corr(), 2)
fig = px.imshow(cor, text_auto=True, title='高钾玻璃')
# set figute size
fig.update_layout(autosize=False, width=600, height=600)
# center title
fig.update_layout(title_x=0.5)
fig.show()

在这里插入图片描述
相关阅读:
2022高教社杯全国大学生数学建模竞赛C题 问题二(1) Python代码
2023高教社杯全国大学生数学建模竞赛C题 Python代码
2021高教社杯全国大学生数学建模竞赛C题 问题一&问题二 Python代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值