核心应用场景
- 疾病进展建模:慢性病状态转移预测(如糖尿病分期)
- 治疗决策优化:不同治疗方案的成本效益分析
- 生存分析:患者生存率动态预测
- 医院资源调度:患者流量预测与床位优化
Python实现示例:糖尿病进展预测模型
import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom scipy.stats import chi2_contingencySTATES = [\'Healthy\', \'Pre-diabetes\', \'Type2_Diabetes\', \'Complications\', \'Death\']N_STATES = len(STATES)def learn_transition_matrix(data): \"\"\"基于患者历史数据计算转移概率\"\"\" transition_counts = np.zeros((N_STATES, N_STATES)) for patient in data: for i in range(len(patient[\'states\'])-1): current = STATES.index(patient[\'states\'][i]) next_state = STATES.index(patient[\'states\'][i+1]) transition_counts[current][next_state] += 1 transition_matrix = transition_counts / transition_counts.sum(axis=1, keepdims=True) return np.nan_to_num(transition_matrix) clinical_data = [ { \'states\': [\'Healthy\', \'Pre-diabetes\', \'Type2_Diabetes\']}, { \'states\': [\'Pre-diabetes\', \'Healthy\', \'Pre-diabetes\', \'Type2_Diabetes\']}, ]P = learn_transition_matrix(clinical_data)print(\"Learned Transition Matrix:\\n\", pd.DataFrame(P, index=STATES, columns=STATES))class MedicalMarkovModel: def __init__(self, transition_matrix, states): self.P = transition_matrix self.states = states self.state_dict = { s: i for i, s in enumerate(states)} def simulate(self, start_state, n_steps=10): \"\"\"模拟疾病进展路径\"\"\" current_state = self.state_dict[start_state] path = [current_state] for _ in range(n_steps): probs = self.P[current_state] next_state = np.random.choice(len(self.states), p=probs) path.append(next_state) current_state = next_state return [self.states[i] for i in path] def predict_future_state(self, current_state, time_steps): \"\"\"预测未来状态概率分布\"\"\" current_idx = self.state_dict[current_state] prob_vector = np.zeros(len(self.states)) prob_vector[current_idx] = 1.0 P_n = np.linalg.matrix_power(self.P, time_steps) future_probs = prob_vector @ P_n return dict(zip(self.states, future_probs)) def cost_effectiveness_analysis(self, treatment_effect): \"\"\"治疗干预的成本效益分析\"\"\" modified_P = self.P * treatment_effect return qaly_gain, cost_savingsmodel = MedicalMarkovModel(P, STATES)patient_path = model.simulate(\'Healthy\', n_steps=15)print(\"\\nSimulated Patient Path:\", patient_path)prediction = model.predict_future_state(\'Pre-diabetes\', time_steps=5)print(\"\\n5-Year Prediction for Pre-diabetic Patient:\")for state, prob in prediction.items(): print(f\"{ state}: { prob:.2%}\")def plot_state_evolution(model, start_state, years=10): fig, ax = plt.subplots(figsize=