# scikit-learn/scikit-learn

FIX: updating doctests in gaussian_process.rst and linear_model.rst

 @@ -14,7 +14,7 @@ been extended to *probabilistic classification*, but in the present implementation, this is only a post-processing of the *regression* exercise. The advantages of Gaussian Processes for Machine Learning are: - + - The prediction interpolates the observations (at least for regular correlation models). @@ -65,19 +65,19 @@ parameters or alternatively it uses the given parameters. >>> import numpy as np >>> from scikits.learn import gaussian_process - >>> def f(x): + >>> def f(x): ... return x * np.sin(x) >>> X = np.atleast_2d([1., 3., 5., 6., 7., 8.]).T >>> y = f(X).ravel() >>> x = np.atleast_2d(np.linspace(0, 10, 1000)).T >>> gp = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1) - >>> gp.fit(X, y) # doctest: +ELLIPSIS - GaussianProcess(normalize=True, theta0=array([[ 0.01]]), - optimizer='fmin_cobyla', verbose=False, storage_mode='full', - nugget=2.2204460492503131e-15, thetaU=array([[ 0.1]]), - regr=, random_start=1, - corr=, beta0=None, - thetaL=array([[ 0.0001]])) + >>> gp.fit(X, y) # doctest: +ELLIPSIS + GaussianProcess(beta0=None, corr=, + normalize=True, nugget=2.22...-15, + optimizer='fmin_cobyla', random_start=1, + regr=, storage_mode='full', + theta0=array([[ 0.01]]), thetaL=array([[ 0.0001]]), + thetaU=array([[ 0.1]]), verbose=False) >>> y_pred, sigma2_pred = gp.predict(x, eval_MSE=True) .. topic:: Other examples @@ -266,18 +266,18 @@ Processes for Machine Learning, please refer to the references below: * DACE, A Matlab Kriging Toolbox _ S Lophaven, HB Nielsen, J Sondergaard 2002 - + * Screening, predicting, and computer experiments _ WJ Welch, RJ Buck, J Sacks, HP Wynn, TJ Mitchell, and MD Morris Technometrics 34(1) 15--25, 1992 - + * Gaussian Processes for Machine Learning _ CE Rasmussen, CKI Williams MIT Press, 2006 (Ed. T Diettrich) - + * The design and analysis of computer experiments _ TJ Santner, BJ @@ -331,4 +331,4 @@ toolbox. * DACE, A Matlab Kriging Toolbox _ S Lophaven, HB Nielsen, J Sondergaard 2002, - +
 @@ -20,6 +20,7 @@ Across the module, we designate the vector :math:w = (w_1, To perform classification with generalized linear models, see :ref:Logistic_regression. + .. _ordinary_least_squares: Ordinary Least Squares @@ -37,17 +38,15 @@ responses predicted by the linear approximation. :class:LinearRegression will take in its fit method arrays X, y and will store the coefficients :math:w of the linear model in its -coef\_ member. - +coef\_ member:: >>> from scikits.learn import linear_model >>> clf = linear_model.LinearRegression() >>> clf.fit ([[0, 0], [1, 1], [2, 2]], [0, 1, 2]) - LinearRegression(fit_intercept=True) + LinearRegression(fit_intercept=True, normalize=False, overwrite_X=False) >>> clf.coef_ array([ 0.5, 0.5]) - However, coefficient estimates for Ordinary Least Squares rely on the independence of the model terms. When terms are correlated and the columns of the design matrix :math:X have an approximate linear @@ -96,12 +95,13 @@ of shrinkage and thus the coefficients become more robust to collinearity. As with other linear models, :class:Ridge will take in its fit method arrays X, y and will store the coefficients :math:w of the linear model in -its coef\_ member. +its coef\_ member:: >>> from scikits.learn import linear_model >>> clf = linear_model.Ridge (alpha = .5) >>> clf.fit ([[0, 0], [0, 0], [1, 1]], [0, .1, 1]) - Ridge(alpha=0.5, tol=0.001, fit_intercept=True) + Ridge(alpha=0.5, fit_intercept=True, normalize=False, overwrite_X=False, + tol=0.001) >>> clf.coef_ array([ 0.34545455, 0.34545455]) >>> clf.intercept_ #doctest: +ELLIPSIS @@ -131,15 +131,15 @@ Setting alpha: generalized Cross-Validation :class:RidgeCV implements ridge regression with built-in cross-validation of the alpha parameter. The object works in the same way as GridSearchCV except that it defaults to Generalized Cross-Validation -(GCV), an efficient form of leave-one-out cross-validation. +(GCV), an efficient form of leave-one-out cross-validation:: >>> from scikits.learn import linear_model >>> clf = linear_model.RidgeCV(alphas=[0.1, 1.0, 10.0]) - >>> clf.fit ([[0, 0], [0, 0], [1, 1]], [0, .1, 1]) # doctest: +SKIP - RidgeCV(alphas=[0.1, 1.0, 10.0], loss_func=None, cv=None, score_func=None, - fit_intercept=True) - >>> clf.best_alpha # doctest: +SKIP - 0.10000000000000001 + >>> clf.fit([[0, 0], [0, 0], [1, 1]], [0, .1, 1]) + RidgeCV(alphas=[0.1, 1.0, 10.0], cv=None, fit_intercept=True, loss_func=None, + normalize=False, score_func=None) + >>> clf.best_alpha # doctest: +ELLIPSIS + 0.1... .. topic:: References @@ -172,13 +172,13 @@ parameter vector. The implementation in the class :class:Lasso uses coordinate descent as the algorithm to fit the coefficients. See :ref:least_angle_regression -for another implementation. +for another implementation:: >>> clf = linear_model.Lasso(alpha = 0.1) - >>> clf.fit ([[0, 0], [1, 1]], [0, 1]) - Lasso(precompute='auto', alpha=0.1, max_iter=1000, tol=0.0001, - fit_intercept=True) - >>> clf.predict ([[1, 1]]) + >>> clf.fit([[0, 0], [1, 1]], [0, 1]) + Lasso(alpha=0.1, fit_intercept=True, max_iter=1000, normalize=False, + overwrite_X=False, precompute='auto', tol=0.0001) + >>> clf.predict([[1, 1]]) array([ 0.8]) Also useful for lower-level tasks is the function :func:lasso_path that @@ -323,9 +323,10 @@ function of the norm of its coefficients. >>> from scikits.learn import linear_model >>> clf = linear_model.LassoLars(alpha=.1) - >>> clf.fit ([[0, 0], [1, 1]], [0, 1]) # doctest: +ELLIPSIS - LassoLars(normalize=True, verbose=False, fit_intercept=True, max_iter=500, - eps=..., precompute='auto', alpha=0.1) + >>> clf.fit ([[0, 0], [1, 1]], [0, 1]) # doctest: +ELLIPSIS + LassoLars(alpha=0.1, eps=..., fit_intercept=True, + max_iter=500, normalize=True, overwrite_X=False, precompute='auto', + verbose=False) >>> clf.coef_ array([ 0.71715729, 0. ]) @@ -458,24 +459,24 @@ By default :math:\alpha_1 = \alpha_2 = \lambda_1 = \lambda_2 = 1.e^{-6}, *i.e :align: center -*Bayesian Ridge Regression* is used for regression: +*Bayesian Ridge Regression* is used for regression:: >>> from scikits.learn import linear_model >>> X = [[0., 0.], [1., 1.], [2., 2.], [3., 3.]] >>> Y = [0., 1., 2., 3.] >>> clf = linear_model.BayesianRidge() >>> clf.fit (X, Y) - BayesianRidge(n_iter=300, verbose=False, lambda_1=1e-06, lambda_2=1e-06, - fit_intercept=True, alpha_2=1e-06, tol=0.001, alpha_1=1e-06, - compute_score=False) + BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False, + fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06, n_iter=300, + normalize=False, overwrite_X=False, tol=0.001, verbose=False) After being fitted, the model can then be used to predict new values:: >>> clf.predict ([[1, 0.]]) array([ 0.50000013]) -The weights :math:\beta of the model can be access: +The weights :math:\beta of the model can be access:: >>> clf.coef_ array([ 0.49999993, 0.49999993])