Пример #1
0
        public void TestToyBayesianRidgeObject()
        {
            var x = new double[, ] {
                { 1 }, { 2 }, { 6 }, { 8 }, { 10 }
            };
            var y   = new double[] { 1, 2, 6, 8, 10 };
            var clf = new BayesianRidgeRegression(computeScore: true);

            clf.Fit(x, y);
            var xTest = DenseMatrix.OfArray(new double[, ] {
                { 1 }, { 3 }, { 4 }
            });

            AssertExt.AlmostEqual(new double[] { 1, 3, 4 }, clf.Predict(xTest).Column(0).ToArray(), 1E-5);
        }
Пример #2
0
        [Ignore] //This test is ignored in scikit-learn also.
        public void TestBayesianOnDiabetes()
        {
            //raise SkipTest("XFailed Test")
            var diabetes = DiabetesDataset.Load();
            var x        = diabetes.Data;
            var y        = diabetes.Target;

            var clf = new BayesianRidgeRegression(computeScore: true);

            // Test with more samples than features
            clf.Fit(x, y);
            // Test that scores are increasing at each iteration
            Assert.AreEqual(clf.Scores.Count - 1, clf.Scores.Diff().Count(v => v > 0));

            // Test with more features than samples
            x = x.SubMatrix(0, 5, 0, x.ColumnCount);
            y = y.SubVector(0, 5);
            clf.Fit(x, y);
            // Test that scores are increasing at each iteration
            Assert.AreEqual(clf.Scores.Count - 1, clf.Scores.Diff().Count(v => v > 0));
        }