Ejemplo n.º 1
0
def fit_and_score_features(X, y):
    n_features = X.shape[1]
    scores = np.empty(n_features)
    m = IPCRidge()
    for j in range(n_features):
        Xj = X[:, j:j + 1]
        m.fit(Xj, y)
        scores[j] = m.score(Xj, y)
    return scores
Ejemplo n.º 2
0
    def test_fit(self):
        model = IPCRidge()
        model.fit(self.x, self.y)

        self.assertAlmostEqual(model.intercept_, 5.8673567124629571)
        expected = numpy.array([
            0.168517, -0.249717, 2.18515, 0.536795, -0.514571, 0.091203,
            0.613006, 0.480385, -0.055949, 0.238529, -0.127148, -0.144134,
            -1.625041, -0.217469
        ])
        assert_array_almost_equal(model.coef_, expected)
Ejemplo n.º 3
0
    def test_fit(make_whas500):
        whas500 = make_whas500()
        model = IPCRidge()
        model.fit(whas500.x, whas500.y)

        assert round(abs(model.intercept_ - 5.8673567124629571), 7) == 0
        expected = numpy.array([
            0.168517, -0.249717, 2.18515, 0.536795, -0.514571, 0.091203,
            0.613006, 0.480385, -0.055949, 0.238529, -0.127148, -0.144134,
            -1.625041, -0.217469
        ])
        assert_array_almost_equal(model.coef_, expected)
Ejemplo n.º 4
0
    def test_predict(make_whas500):
        whas500 = make_whas500()
        model = IPCRidge()
        model.fit(whas500.x[:400], whas500.y[:400])

        x_test = whas500.x[400:]
        y_test = whas500.y[400:]
        p = model.predict(x_test)
        assert_cindex_almost_equal(y_test['fstat'], y_test['lenfol'], -p,
                                   (0.66925817946226107, 2066, 1021, 0, 1))

        assert model.score(x_test, y_test) == 1.0 - 0.66925817946226107
Ejemplo n.º 5
0
    def test_fit(make_whas500):
        whas500 = make_whas500()
        model = IPCRidge()
        model.fit(whas500.x, whas500.y)

        assert round(abs(model.intercept_ - 5.867520370855396), 7) == 0
        expected = numpy.array([
            0.168481, -0.24962, 2.185086, 0.53682, -0.514611, 0.09124,
            0.613114, 0.480357, -0.055972, 0.238472, -0.127209, -0.144063,
            -1.625081, -0.217591
        ])
        assert_array_almost_equal(model.coef_, expected)
Ejemplo n.º 6
0
    def test_predict(self):
        model = IPCRidge()
        model.fit(self.x[:400], self.y[:400])

        x_test = self.x[400:]
        y_test = self.y[400:]
        p = model.predict(x_test)
        ci = concordance_index_censored(y_test['fstat'], y_test['lenfol'], -p)

        self.assertAlmostEqual(ci[0], 0.66925817946226107)
        self.assertEqual(ci[1], 2066)
        self.assertEqual(ci[2], 1021)
        self.assertEqual(ci[3], 0)
        self.assertEqual(ci[4], 6)

        self.assertEqual(model.score(x_test, y_test), 1.0 - ci[0])
allTarget = np.zeros((2000), dtype=[('indicator', bool), ('time', float)])

for i in range(0, 2000):
    if data[i][22] < 0:
        allTarget[i]['time'] = data[i][23]
        allTarget[i]['indicator'] = False
    else:
        allTarget[i]['time'] = data[i][22]
        allTarget[i]['indicator'] = True

trainingTargetKidney = allTarget[0:800]
testTargetKidney = allTarget[800:1000]

estimator = IPCRidge()
estimator.fit(trainingData, trainingTargetKidney)
prediction = estimator.predict(testData)

estimator = CoxPHSurvivalAnalysis()
estimator.fit(trainingData, trainingTargetStruc)
prediction0 = estimator.predict(testData)

result = concordance_index_censored(testTargetStruc["indicator"],
                                    testTargetStruc["targetValue"], prediction)
result0 = concordance_index_censored(testTargetStruc["indicator"],
                                     testTargetStruc["targetValue"],
                                     prediction0)
print(result)
print(prediction)
print(result0)
print(prediction0)
Ejemplo n.º 8
0
E = df['LapseIndicator'].apply(lambda x: True if x == 1 else False)

df2['E'] = E
df2['T'] = T

X, y = get_x_y(df2, ['E', 'T'], pos_label=True)

for c in X.columns.values:
    if c != 'AGE AT DOC':
        X[c] = X[c].astype('category')

data_x_numeric = OneHotEncoder().fit_transform(X)
#%%

estimator = IPCRidge()
estimator.fit(data_x_numeric, y)
#%%

print()
print(pd.Series(estimator.coef_, index=data_x_numeric.columns))
print()

print(estimator.score(data_x_numeric, y))
print()

scores = fit_and_score_features(data_x_numeric.values, y)
print(
    pd.Series(scores,
              index=data_x_numeric.columns).sort_values(ascending=False))
#%%