예제 #1
0
def test_get_basis_matrix_for_array():
    gam = psgam.PSplineGAM(num_percentiles=5)

    arr = np.random.uniform(size=(100, 2))

    gam.feature_names = ['feature_0', 'feature_1']
    gam._create_knots_dict(arr, gam.num_percentiles)

    knots0 = ps._get_percentiles(arr[:, 0], num_percentiles=5)
    knots1 = ps._get_percentiles(arr[:, 1], num_percentiles=5)

    basis = gam._get_basis_for_array(arr)

    np.testing.assert_array_equal(basis[:, :, 0], ps._get_basis_vector(arr[:, 0], knots0, with_intercept=False))
    np.testing.assert_array_equal(basis[:, :, 1], ps._get_basis_vector(arr[:, 1], knots1, with_intercept=False))
예제 #2
0
def test_get_basis_matrix_for_array():
    gam = psgam.PSplineGAM(num_percentiles=5)

    arr = np.random.uniform(size=(100, 2))

    gam.feature_names = ['feature_0', 'feature_1']
    gam._create_knots_dict(arr, gam.num_percentiles)

    knots0 = ps._get_percentiles(arr[:, 0], num_percentiles=5)
    knots1 = ps._get_percentiles(arr[:, 1], num_percentiles=5)

    basis = gam._get_basis_for_array(arr)

    np.testing.assert_array_equal(
        basis[:, :, 0],
        ps._get_basis_vector(arr[:, 0], knots0, with_intercept=False))
    np.testing.assert_array_equal(
        basis[:, :, 1],
        ps._get_basis_vector(arr[:, 1], knots1, with_intercept=False))
예제 #3
0
def test_flatten_basis_matrix_for_regression():
    gam = psgam.PSplineGAM(num_percentiles=2)

    arr = np.random.uniform(size=(4, 3))

    gam.feature_names = ['feature_0', 'feature_1', 'feature_2']
    gam._create_knots_dict(arr, gam.num_percentiles)

    knots0 = ps._get_percentiles(arr[:, 0], num_percentiles=2)
    knots1 = ps._get_percentiles(arr[:, 1], num_percentiles=2)
    knots2 = ps._get_percentiles(arr[:, 2], num_percentiles=2)

    dim0_basis = ps._get_basis_vector(arr[:, 0], knots0, with_intercept=False)
    dim1_basis = ps._get_basis_vector(arr[:, 1], knots1, with_intercept=False)
    dim2_basis = ps._get_basis_vector(arr[:, 2], knots2, with_intercept=False)

    manual_concat = np.asarray([np.asarray([1.0] + vec_0.tolist() + vec_1.tolist() + vec_2.tolist()) for vec_0, vec_1, vec_2 in zip(dim0_basis, dim1_basis, dim2_basis)])

    base_set = gam._flatten_basis_for_fitting(arr)

    np.testing.assert_array_equal(base_set, manual_concat)
예제 #4
0
 def _create_knots_dict(self, data, num_percentiles):
     self._knots = {feat: _get_percentiles(data[:, self._get_index_for_feature(feat)], num_percentiles=num_percentiles) for feat in self.feature_names}