目录
问题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]]
鉴别出的玻璃类型如下:
文物编号 | 玻璃类型预测 | |
---|---|---|
0 | A1 | 高钾 |
1 | A2 | 铅钡 |
2 | A3 | 铅钡 |
3 | A4 | 铅钡 |
4 | A5 | 铅钡 |
5 | A6 | 高钾 |
6 | A7 | 高钾 |
7 | A8 | 铅钡 |
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代码