def test_generic_smoother(): x, y, poly = multivariate_sample_data() alphas = [0.4, 0.7] weights = [1, 1] # noqa: F841 gs = GenericSmoothers(poly.x, poly.smoothers) gam_gs = GLMGam(y, smoother=gs, alpha=alphas) gam_gs_res = gam_gs.fit() gam_poly = GLMGam(y, smoother=poly, alpha=alphas) gam_poly_res = gam_poly.fit() assert_allclose(gam_gs_res.params, gam_poly_res.params)
def _split_train_test_smoothers(x, smoother, train_index, test_index): """split smoothers in test and train sets and create GenericSmoothers Note: this does not take exog_linear into account """ train_smoothers = [] test_smoothers = [] for smoother in smoother.smoothers: train_basis = smoother.basis[train_index] train_der_basis = smoother.der_basis[train_index] train_der2_basis = smoother.der2_basis[train_index] train_cov_der2 = smoother.cov_der2 # TODO: Double check this part. cov_der2 is calculated with all data train_x = smoother.x[train_index] train_smoothers.append( UnivariateGenericSmoother(train_x, train_basis, train_der_basis, train_der2_basis, train_cov_der2, smoother.variable_name + ' train')) test_basis = smoother.basis[test_index] test_der_basis = smoother.der_basis[test_index] test_der2_basis = smoother.der2_basis[test_index] test_cov_der2 = smoother.cov_der2 # TODO: Double check this part. cov_der2 is calculated with all data test_x = smoother.x[test_index] test_smoothers.append( UnivariateGenericSmoother(test_x, test_basis, test_der_basis, train_der2_basis, test_cov_der2, smoother.variable_name + ' test')) train_multivariate_smoothers = GenericSmoothers(x[train_index], train_smoothers) test_multivariate_smoothers = GenericSmoothers(x[test_index], test_smoothers) return train_multivariate_smoothers, test_multivariate_smoothers