Least-squares approximation =========================== The following description is taken from scikit-learn version 0.18.2 [1]_. The Least Squares method fits a linear model with coefficients :math:`{\bf \beta} = \left(\beta_0, \beta_1,\dotsc,\beta_{nx}\right)` to minimize the residual sum of squares between the observed responses in the dataset, and the responses predicted by the linear approximation. Mathematically it solves a problem of the form: .. math :: \min_\limits{{\bf \beta}}||{\bf X\beta-y}||_2^2, where :math:`{\bf X} = \left(1,{{\bf x}^{(1)}}^T,\dots,{{\bf x}^{(nt)}}^T\right)^T` with dimensions (:math:`nt\times nx+1`). .. [1] http://scikit-learn.org/stable/modules/linear_model.html Usage ----- .. code-block:: python import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import LS xt = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) yt = np.array([0.0, 1.0, 1.5, 0.9, 1.0]) sm = LS() sm.set_training_values(xt, yt) sm.train() num = 100 x = np.linspace(0.0, 4.0, num) y = sm.predict_values(x) plt.plot(xt, yt, "o") plt.plot(x, y) plt.xlabel("x") plt.ylabel("y") plt.legend(["Training data", "Prediction"]) plt.show() :: ___________________________________________________________________________ LS ___________________________________________________________________________ Problem size # training points. : 5 ___________________________________________________________________________ Training Training ... Training - done. Time (sec): 0.0004039 ___________________________________________________________________________ Evaluation # eval points. : 100 Predicting ... Predicting - done. Time (sec): 0.0000441 Prediction time/pt. (sec) : 0.0000004 .. figure:: ls_Test_test_ls.png :scale: 80 % :align: center Options ------- .. list-table:: List of options :header-rows: 1 :widths: 15, 10, 20, 20, 30 :stub-columns: 0 * - Option - Default - Acceptable values - Acceptable types - Description * - print_global - True - None - ['bool'] - Global print toggle. If False, all printing is suppressed * - print_training - True - None - ['bool'] - Whether to print training information * - print_prediction - True - None - ['bool'] - Whether to print prediction information * - print_problem - True - None - ['bool'] - Whether to print problem information * - print_solver - True - None - ['bool'] - Whether to print solver information * - data_dir - None - None - ['str'] - Directory for loading / saving cached data; None means do not save or load