# SKLearn Linear Module

• The SK learn linear module is one such module that helps to study the relationship between the independent and dependent variables.
• The linear module can be implemented by using the best line.
• The module used for using linear regression is “sklearn.linear_module.LinearRegression”.
• The linear regression module is used to minimize the sum of the squares of residual between the objects in a set by fitting a linear model.

### Parameters

• fit_intercept: Boolean, default = True
• Normalize: Boolean, default = False
• Copy_x: Boolean, default = True
• N_jobs: int default = None
• There are four parameters used by the linear regression module, they are:
• fit_intercept: Boolean, default = True
• If the fit_intercept parameter is set with false, then there will be no intercept.
• The fit_intercept parameter is used to find the intercept of a model.
• Normalize: Boolean, default = False
• If the fit_intercept is false, then the normalized parameter will be ignored.
• If the normalized parameter is defined with true, then normalization of regressor x(independent variable) is done before the normalization of regression.
• The x regressor is normalized by dividing the mean with L2 form after subtracting the mean.
• Copy_x: Boolean, default = True
• If the copy_x parameter is set to false, then the x will be overwritten.
• But for the copy_x parameter, its default value is set to true, which means the value x can be copied.
• N_jobs: int default = None
• Here the n_job parameter is used for computation.
• It is used to speed up in large problems, which is if first n_objects is greater than 1 and x is parse which is set to true.

### Attributes:

1. rank_: int: It is only used when the x is denser. Which is used to find the rank of the x matrix?
2. Singular_: array of shape (min (x, y)): It is only used when the x is denser. Which is used to find the singular values of the x matrix?
3. Coef_: array of shape (n_features,): In regression problems are the estimated coefficients.
If there are many targets in fitting,it is a 2d array when only 1 target is given, which is a 1 d array of length.
4. Intercept_:array of shape(n_targets,): If the fit_intercept is equal to false, then it is set to 0.0, It is an independent object in the model, which is linear.
5. n_features_in_: int: It is no of the features found in fit.
6. Feature_names_in_:ndarray of shape(n_features_in_,): It is no of the features found in fit.If x has only all strings.

Example:

``````>>> import numpy as np
>>> from sklearn.linear_model import Linearregression
>>> x = np.array([[1, 1], [1, 2], [2, 2], [2, 3]] )
>>> y = np.dot (x, np.array ([ 1, 2] )) +3
>>>regr = linearregression( ).fit (x, y)
>>>Regr.score (x, y)
1.0
>>>Regr.coef_
array ([1., 2.])
>>>regr.intercept_
3.0 . . .
>>>regr.predict (np.array([[3, 5]]))
array ([16. ])``````

### Methods:

fit(x, y, sample_weight = none)

• The parameters used are x, y, and sample_weight.
• Here x means training data.
• Y means target values. It is sometimes cast to x if needed.
• Sample_weight means the individual weight of every sample. Its default value is None.
• This method returns an estimator that is fitted.

Get_params (deep = true)

• The parameters used are deep.
• The deep means if it is set to true, then it returns the estimator and subobjects that are contained.
• The Deep default value is set to true.
• This method returns parameter which are mapped to values.

Predict(x)

• The parameters used are x;
• Here the x means samples.
• This method returns values that are predicted.

Scores(x, y, sample_weight = none)

• The parameters used in this method are x, y, andsample_weight.
• x means test samples.
• Here y means values of x which are true.
• Here sample_weight means sample weights.
• This method returns the score:float.
R2 of self. Predict with respect to y.
• Here the r2 is used when the score o the regressor is called. That is when the regressor uses multioutput = “uniform_average”.

Set_params( **params)

• This method is used to work on simple estimators along with objects which are nested.
• It can be possible to update the component of the nested object because its parameters in the form of < component >__< parameter >
• The parameter used is **params.
• Params mean estimator parameters.
• This method returns the estimator instance.