示例#1
0
    def test_regression_fit(self):

        x_basis = Monomial(n_basis=7)
        x_fd = FDataBasis(x_basis, np.identity(7))

        beta_basis = Fourier(n_basis=5)
        beta_fd = FDataBasis(beta_basis, [1, 1, 1, 1, 1])
        y = [
            1.0000684777229512, 0.1623672257830915, 0.08521053851548224,
            0.08514200869281137, 0.09529138749665378, 0.10549625973303875,
            0.11384314859153018
        ]

        scalar = LinearScalarRegression([beta_basis])
        scalar.fit([x_fd], y)
        np.testing.assert_array_almost_equal(scalar.beta_[0].coefficients,
                                             beta_fd.coefficients)
示例#2
0
    def test_regression_predict_multiple_explanatory(self):
        y = [1, 2, 3, 4, 5, 6, 7]

        x0 = FDataBasis(Constant(domain_range=(0, 1)), np.ones((7, 1)))
        x1 = FDataBasis(Monomial(n_basis=7), np.identity(7))

        beta0 = Constant(domain_range=(0, 1))
        beta1 = BSpline(domain_range=(0, 1), n_basis=5)

        scalar = LinearScalarRegression([beta0, beta1])

        scalar.fit([x0, x1], y)

        betas = scalar.beta_

        np.testing.assert_array_almost_equal(betas[0].coefficients.round(4),
                                             np.array([[32.6518]]))

        np.testing.assert_array_almost_equal(
            betas[1].coefficients.round(4),
            np.array([[-28.6443, 80.3996, -188.587, 236.5832, -481.3449]]))