一、三维聚类的建模思路
- 目标:用BMI、首次达标孕周、Y染色体浓度等特征,对男胎孕妇进行自动分组(聚类),以便发现数据中的自然分层,为NIPT时点推荐和风险分析提供依据。
- 常用方法:K-means聚类、层次聚类(Hierarchical Clustering)等。
- 聚类特征选择 :
- BMI
- 首次达标孕周
- 首次达标时的Y染色体浓度(或可选其他特征)
二、数据准备
- 只保留男胎孕妇
- 每位孕妇只保留首次Y染色体浓度≥4%的那条记录
- 选取聚类特征并标准化(统一量纲)
三、Python实现示例(K-means三维聚类)
python
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 1. 读取和筛选数据(同前面代码,略)
# 2. 选取聚类特征
features = 首次达标[['孕妇BMI', '检测孕周', 'Y染色体浓度']].copy()
# 3. 标准化
scaler = StandardScaler()
features_scaled = scaler.fit_transform(features)
# 4. K-means聚类(假设分3组,可根据轮廓系数等方法优化K值)
k = 3
kmeans = KMeans(n_clusters=k, random_state=42)
labels = kmeans.fit_predict(features_scaled)
首次达标['聚类标签'] = labels
# 5. 三维可视化
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection='3d')
scatter = ax.scatter(首次达标['孕妇BMI'], 首次达标['检测孕周'], 首次达标['Y染色体浓度'],
c=labels, cmap='viridis', s=50)
ax.set_xlabel('孕妇BMI')
ax.set_ylabel('首次达标孕周')
ax.set_zlabel('Y染色体浓度')
plt.title('三维K-means聚类结果')
plt.colorbar(scatter, label='聚类标签')
plt.show()
# 6. 查看每个聚类的中心
centers = scaler.inverse_transform(kmeans.cluster_centers_)
for i, center in enumerate(centers):
print(f'聚类{i}中心(BMI, 孕周, 浓度):', center)
四、聚类结果解读与应用
- 每个聚类代表一类孕妇的特征组合(如高BMI+晚达标、低BMI+早达标等)。
- 可以对每个聚类分别统计最佳NIPT时点、风险等指标。
- 聚类结果可用于更个性化的NIPT时点推荐。
五、聚类数K的选择
- 可用肘部法则(Elbow Method)、轮廓系数(Silhouette Score)等方法确定最优K值。
六、写作建议
"采用K-means三维聚类方法,以孕妇BMI、首次Y染色体浓度达标孕周和达标时浓度为特征,将男胎孕妇分为3组。每组的中心特征分别为......,可据此为不同特征孕妇推荐更合理的NIPT检测时点。"