Esempio n. 1
0
def test_SVR():
    """
    Test Support Vector Regression
    """

    diabetes = datasets.load_diabetes()
    for clf in (svm.NuSVR(kernel='linear', nu=.4),
                svm.SVR(kernel='linear', C=10.),
                svm.sparse.NuSVR(kernel='linear', nu=.4),
                svm.sparse.SVR(kernel='linear', C=10.)):
        clf.fit(diabetes.data, diabetes.target)
        assert clf.score(diabetes.data, diabetes.target) > 0.02
Esempio n. 2
0
def test_bayesian_on_diabetes():
    """
    Test BayesianRidge on diabetes
    """
    diabetes = datasets.load_diabetes()
    X, y = diabetes.data, diabetes.target

    clf = BayesianRidge(compute_score=True)

    # Test with more samples than features
    clf.fit(X, y)
    # Test that scores are increasing at each iteration
    assert_array_equal(np.diff(clf.all_score_) > 0, True)

    # Test with more features than samples
    X = X[:5, :]
    y = y[:5]
    clf.fit(X, y)
    # Test that scores are increasing at each iteration
    assert_array_equal(np.diff(clf.all_score_) > 0, True)
Esempio n. 3
0
def test_bayesian_on_diabetes():
    """
    Test BayesianRidge on diabetes
    """
    raise nose.SkipTest("XFailed Test")
    diabetes = datasets.load_diabetes()
    X, y = diabetes.data, diabetes.target

    clf = BayesianRidge(compute_score=True)

    # Test with more samples than features
    clf.fit(X, y)
    # Test that scores are increasing at each iteration
    assert_array_equal(np.diff(clf.scores_) > 0, True)

    # Test with more features than samples
    X = X[:5, :]
    y = y[:5]
    clf.fit(X, y)
    # Test that scores are increasing at each iteration
    assert_array_equal(np.diff(clf.scores_) > 0, True)
Esempio n. 4
0
import numpy as np
from numpy.testing import (assert_array_almost_equal,
                           assert_almost_equal)

from nose.tools import assert_equal, assert_true

from ..lars import lars_path, LassoLARS, LARS
from ..coordinate_descent import Lasso

from scikits.learn import datasets

n, m = 10, 10
np.random.seed (0)
diabetes = datasets.load_diabetes()
X, y = diabetes.data, diabetes.target


def test_simple():
    """
    Principle of LARS is to keep covariances tied and decreasing
    """
    max_pred = 10
    alphas_, active, coef_path_ = lars_path(diabetes.data, diabetes.target, max_iter=max_pred, method="lar")
    for (i, coef_) in enumerate(coef_path_.T):
        res =  y - np.dot(X, coef_)
        cov = np.dot(X.T, res)
        C = np.max(abs(cov))
        eps = 1e-3
        ocur = len(cov[ C - eps < abs(cov)])
        if i < max_pred:
            assert ocur == i+1
determination (R2) without reperforming MLE, using the set of correlation
parameters found on the whole dataset.
"""
print __doc__

# Author: Vincent Dubourg <*****@*****.**>
# License: BSD style

import numpy as np
from scikits.learn import datasets
from scikits.learn.gaussian_process import GaussianProcess
from scikits.learn.cross_val import cross_val_score, KFold
from scikits.learn.metrics import r2_score

# Load the dataset from scikits' data sets
diabetes = datasets.load_diabetes()
X, y = diabetes.data, diabetes.target

# Instanciate a GP model
gp = GaussianProcess(regr='constant',
                     corr='absolute_exponential',
                     theta0=[1e-4] * 10,
                     thetaL=[1e-12] * 10,
                     thetaU=[1e-2] * 10,
                     nugget=1e-2,
                     optimizer='Welch')

# Fit the GP model to the data performing maximum likelihood estimation
gp.fit(X, y)

# Deactivate maximum likelihood estimation for the cross-validation loop
Esempio n. 6
0
"On the degrees of freedom of the lasso"
Hui Zou, Trevor Hastie, and Robert Tibshirani
Ann. Statist. Volume 35, Number 5 (2007), 2173-2192.
"""
print __doc__

# Author: Alexandre Gramfort <*****@*****.**>
# License: BSD Style.

from math import log
import numpy as np

from scikits.learn.linear_model import lars_path
from scikits.learn.datasets import load_diabetes

diabetes = load_diabetes()
X, y = diabetes.data, diabetes.target

# add garbage features
rng = np.random.RandomState(42)
X = np.c_[X, rng.randn(X.shape[0], 10)]
n_samples = X.shape[0]

# Standardize the data to avoid intercept problems
y -= np.mean(y)
X -= np.mean(X, axis=0)
X /= np.std(X, axis=0)

print "Computing regularization path using the LARS ..."
alphas, features, coefs = lars_path(X, y, method='lasso', verbose=True)