如何解释python中fitted scikitsurvival模型中.predict()的输出?

2024-06-17 08:40:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我很困惑如何解释scikit生存模型中.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:

^{pr2}$

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

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

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

predsX具有相同数量的记录,但它们的值与data_y中的值相差甚远,即使在相同的数据上进行预测时也是如此。在

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

输出:

-0.044114643249153422
121.62773722627738

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


Tags: toin模型importapidataloadscikit
2条回答

我发布了这个问题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(图书馆作者)

^{pr2}$

-帕沃帕克斯。在

在github线程中有更多的解释,尽管我并不是真的能够理解所有的内容。我需要和predict_survival_functionpredict_cumulative_hazard_function一起玩,看看我是否能得到一组关于X中最有可能存活时间的预测,这正是我真正想要的。在

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

使用X输入,可以得到输入数组的求值:

def predict(self, X, alpha=None):
    """The linear predictor of the model.
    Parameters
         
    X : array-like, shape = (n_samples, n_features)
        Test data of which to calculate log-likelihood from
    alpha : float, optional
        Constant that multiplies the penalty terms. If the same alpha was used during training, exact
        coefficients are used, otherwise coefficients are interpolated from the closest alpha values that
        were used during training. If set to ``None``, the last alpha in the solution path is used.
    Returns
       -
    T : array, shape = (n_samples,)
        The predicted decision function
    """
    X = check_array(X)
    coef = self._get_coef(alpha)
    return numpy.dot(X, coef)

定义检查数组来自另一个library。 您可以查看coxnet的代码。在

相关问题 更多 >