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_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.º 3
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])
Ejemplo n.º 4
0
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))
#%%

from sklearn.feature_selection import SelectKBest
from sklearn.pipeline import Pipeline

pipe = Pipeline([('encode', OneHotEncoder()),
                 ('select', SelectKBest(fit_and_score_features, k=3)),
                 ('model', IPCRidge())])