gpt4 book ai didi

python - 如何从 python 中的拟合 scikit 生存模型解释 .predict() 的输出?

转载 作者:太空狗 更新时间:2023-10-29 20:28:56 26 4
gpt4 key购买 nike

我很困惑如何从 scikit-survival 中的拟合 CoxnetSurvivalAnalysis 模型解释 .predict 的输出。我已经通读了笔记本Intro to Survival Analysis in scikit-survival和 API 引用,但找不到解释。以下是导致我感到困惑的最小示例:

import pandas as pd
from sksurv.datasets import load_veterans_lung_cancer
from sksurv.linear_model import CoxnetSurvivalAnalysis

# load data
data_X, data_y = load_veterans_lung_cancer()

# one-hot-encode categorical columns in X
categorical_cols = ['Celltype', 'Prior_therapy', 'Treatment']

X = data_X.copy()
for c in categorical_cols:
dummy_matrix = pd.get_dummies(X[c], prefix=c, drop_first=False)
X = pd.concat([X, dummy_matrix], axis=1).drop(c, axis=1)

# display final X to fit Cox Elastic Net model on
del data_X
print(X.head(3))

所以这是进入模型的 X:

   Age_in_years  Celltype  Karnofsky_score  Months_from_Diagnosis  \
0 69.0 squamous 60.0 7.0
1 64.0 squamous 70.0 5.0
2 38.0 squamous 60.0 3.0

Prior_therapy Treatment
0 no standard
1 yes standard
2 no standard

...继续拟合模型并生成预测:

# Fit Model
coxnet = CoxnetSurvivalAnalysis()
coxnet.fit(X, data_y)

# What are these predictions?
preds = coxnet.predict(X)

preds 具有与 X 相同的记录数,但它们的值与 data_y 中的值有很大不同,即使在他们适合的相同数据。

print(preds.mean()) 
print(data_y['Survival_in_days'].mean())

输出:

-0.044114643249153422
121.62773722627738

那么 preds 到底是什么?显然 .predict 在这里的意思与 scikit-learn 中的意思很不一样,但我不知道是什么。 API Reference说它返回“预测的决策函数”,但这是什么意思?对于给定的 X,我如何获得 yhat 月的预测估计值?我是生存分析的新手,所以我显然遗漏了一些东西。

最佳答案

我发布了这个问题 on github ,尽管作者将问题重命名为问题。

我对 predict 输出的内容做了一些有用的解释,但仍然不确定如何获得一组预测的生存时间,这才是我真正想要的。这是来自该 github 线程的一些有用的解释:

predictions are risk scores on an arbitrary scale, which means you can 
usually only determine the sequence of events, but not their exact time.

-sebp(库作者)

It [predict] returns a type of risk score. Higher value means higher
risk of your event (class value = True)...You were probably looking
for a predicted time. You can get the predicted survival function with
estimator.predict_survival_function as in the example 00
notebook...EDIT: Actually, I’m trying to extract this but it’s been a
bit of a pain to munge

-pavopax。

github 线程中有更多解释,但我并不能完全理解所有解释。我需要尝试使用 predict_survival_functionpredict_cumulative_hazard_function 看看我是否可以在 X 中逐行得出一组最有可能生存时间的预测,这才是我真正想要的。

我不会在这里接受这个答案,以防其他人有更好的答案。

关于python - 如何从 python 中的拟合 scikit 生存模型解释 .predict() 的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47274356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com