编辑代码

# coding:utf-8
#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
print("Hello world!   -  python.jsrun.net .")
import pandas as pd
import numpy as np

# 设定随机种子保证可重复性
np.random.seed(2023)

# 生成200例患者数据
n = 200
data = pd.DataFrame({
    "PatientID": ["PT_{:03d}".format(i) for i in range(1, n+1)],
    "Age": np.random.normal(58, 10, n).astype(int),
    "Gender": np.random.choice(["Male", "Female"], n, p=[0.7, 0.3]),
    "ChildPugh": np.random.choice(["A", "B"], n, p=[0.68, 0.32]),
    "TumorSize": np.round(np.random.normal(4.5, 2.1, n), 1),
    "EmbolicType": np.random.choice(["cTACE", "DEB-TACE"], n, p=[0.45, 0.55]),
    "MeanPressure": np.concatenate([
        np.random.normal(120, 15, int(n*0.4)),   # 正常压力区间
        np.random.normal(75, 10, int(n*0.3)),    # 低压力区间
        np.random.normal(185, 15, int(n*0.3))    # 高压力区间
    ]),
    "OscillationFreq": np.concatenate([
        np.random.normal(1.2, 0.5, int(n*0.6)),  # 低频组
        np.random.normal(3.5, 0.8, int(n*0.4))   # 高频组
    ])
})

# 根据U型关系生成PELI标签
def calculate_peli(row):
    base_risk = 0.2
    # 压力相关风险
    if row["MeanPressure"] < 82 or row["MeanPressure"] > 176:
        pressure_risk = 0.4
    else:
        pressure_risk = 0.05
    # 震荡频率风险
    freq_risk = 0.3 if row["OscillationFreq"] > 3 else 0.1
    # 综合风险
    total_risk = base_risk + pressure_risk + freq_risk
    return 1 if np.random.rand() < total_risk else 0

data["PELI"] = data.apply(calculate_peli, axis=1)

# 保存为CSV
data.to_csv("TACE_Pressure_Study_Data.csv", index=False)