Пример #1
0
y['bio_rec_6_delay'] = data[['bio_rec_6_delay']].to_numpy().ravel()

nTest = 38
auc = np.zeros((len(tx), 3))
meanAuc = np.zeros((N, len(tx)))
cph = CoxPHSurvivalAnalysis()
sss = StratifiedShuffleSplit(n_splits=N, test_size=nTest)

for i, x in enumerate(tx):
    x = x.to_numpy()
    j = 0
    for train, test in sss.split(x, y['bio_rec_6']):
        xtrain, ytrain = x[train], y[train]
        xtest, ytest = x[test], y[test]
        cph.fit(xtrain, ytrain)
        ypred = cph.predict(xtrain)
        time = np.linspace(
            np.min(ytrain['bio_rec_6_delay']) + 1,
            np.max(ytrain['bio_rec_6_delay']) - 1, 3)
        auc[i, :], meanAuc[j,
                           i] = cumulative_dynamic_auc(ytrain, ytrain, ypred,
                                                       time)
        j += 1

meanAuc = pd.DataFrame(data=meanAuc,
                       columns=[
                           '4_feat.', "Prediction 1", 'Prediction 2',
                           'Prediction 3', 'Prediction 4'
                       ])
meanMeanAuc = meanAuc.mean(axis=0)
stdMeanAuc = meanAuc.std(axis=0)
Пример #2
0
        if model_name == 'NN':
            model = MLPClassifier(hidden_layer_sizes=(100, 10))

        if model_name == 'randomforest':
            model = RandomForestClassifier(n_estimators=1000)

        if model_name == 'gbm':
            model = GradientBoostingClassifier()

        if model_name == 'xgb':
            model = XGBRegressor()

        ## Train and Predict
        if (model_name == 'linearregression' or model_name == 'xgb'):
            model.fit(X_train, Y_train)
            Predict = model.predict(X_test)

        elif (model_name == 'svmlin'):
            model.fit(X_train, Y_train)
            Predict = model.decision_function(X_test)

        elif (model_name == 'coxregression'):
            if data_name == 'maggic':
                model.fit(Train_All,
                          duration_col='days_to_fu',
                          event_col='death_all')
                Predict = model.predict_partial_hazard(X_test)
            elif (data_name == 'heart_trans' or 'heart_wait'):
                model.fit(Train_All,
                          duration_col="'Survival'",
                          event_col="'Censor'")