text: # Copyright 2017 Battelle Energy Alliance, LLC
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  # http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  """
    Created on Jan 21, 2020
  
    @author: alfoa, wangc
    Ordinary least squares Linear Regression.
  
  """
  #Internal Modules (Lazy Importer)--------------------------------------------------------------------
  #Internal Modules (Lazy Importer) End----------------------------------------------------------------
  
  #External Modules------------------------------------------------------------------------------------
  #External Modules End--------------------------------------------------------------------------------
  
  #Internal Modules------------------------------------------------------------------------------------
  from SupervisedLearning.ScikitLearn import ScikitLearnBase
  from utils import InputData, InputTypes
  #Internal Modules End--------------------------------------------------------------------------------
  
  class LinearRegression(ScikitLearnBase):
    """
      Ordinary least squares Linear Regression.
    """
    info = {'problemtype':'regression', 'normalize':False}
  
    def __init__(self):
      """
        Constructor that will appropriately initialize a supervised learning object
        @ In, None
        @ Out, None
      """
      super().__init__()
      import sklearn
      import sklearn.linear_model
      self.model = sklearn.linear_model.LinearRegression
  
    @classmethod
    def getInputSpecification(cls):
      """
        Method to get a reference to a class that specifies the input data for
        class cls.
        @ In, cls, the class for which we are retrieving the specification
        @ Out, inputSpecification, InputData.ParameterInput, class to use for
          specifying input of cls.
      """
      specs = super().getInputSpecification()
      specs.description = r"""The \xmlNode{LinearRegression}
                          is an Ordinary least squares Linear Regression.
                          LinearRegression fits a linear model with coefficients $w = (w1, …, wp)$ to
                          minimize the residual sum of squares between the observed targets in the
                          dataset, and the targets predicted by the linear approximation.
                          \zNormalizationNotPerformed{LinearRegression}
                          """
      specs.addSub(InputData.parameterInputFactory("fit_intercept", contentType=InputTypes.BoolType,
                                                   descr=r"""Whether the intercept should be estimated or not. If False,
                                                    the data is assumed to be already centered.""", default=True))
      specs.addSub(InputData.parameterInputFactory("normalize", contentType=InputTypes.BoolType,
                                                   descr=r"""This parameter is ignored when fit_intercept is set to False. If True,
                                                   the regressors X will be normalized before regression by subtracting the mean and
                                                   dividing by the l2-norm.""", default=False))
      # New in sklearn version 0.24
      # specs.addSub(InputData.parameterInputFactory("positive", contentType=InputTypes.BoolType,
      #                                              descr=r"""When set to True, forces the coefficients to be positive.""", default=False))
      return specs
  
    def _handleInput(self, paramInput):
      """
        Function to handle the common parts of the distribution parameter input.
        @ In, paramInput, ParameterInput, the already parsed input.
        @ Out, None
      """
      super()._handleInput(paramInput)
      settings, notFound = paramInput.findNodesAndExtractValues(['fit_intercept','normalize'])
      # notFound must be empty
      assert(not notFound)
      self.initializeModel(settings)
  