×

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.

Related Topics

Python exit commands

exit(), quit(), sys.exit(), os._exit() In this tutorial, we will study exit commands used in the Python programming language. Python is undoubtedly the choice of programmer and this is because of the in-built...

3 minutes read.

Raise Exception in Python

Most of the programmers/developers create large programs to solve complex tasks in Python. The code can be of 1000 lines and even more based on the need of the problem....

5 minutes read.

Inheritance in Python

Inheritance in Python Object-Oriented Programming provides reusable patterns to the code for restricting the redundancy in development projects. One of the basic principles of Object-Oriented Programming that helps achieve recyclable code...

8 minutes read.

How to Plot Graphs Using Python?

In this article, we are going to learn about how to plot different types of graphs using Python. We are going to use different approaches for every type of graph....

3 minutes read.

IPython Display

A command shell, often known as IPython is a software application that makes an operating system's features accessible to users or other applications. Based on the purpose and specific functioning...

6 minutes read.

Python print() function

Python print() function The print() function prints the specified message to the screen or other standard output devices. Syntax print(*objects,sep=' ',end='\n',file=sys.stdout,flush=False) Parameter objects: This function represents an object, which will be converted to a string...

1 minute read.

What are the Purposes of Python?

Python is a high-level programming language that is simple to use and easy to write, and Python is a beginner-friendly programming language. A beginner often prefers to start with Python...

6 minutes read.

CSV Module In Python

Introduction CSV stands for "comma separated values". It is the most common and simple file structure used for storing and arranging tabular data. for example; a spreadsheet or database. It stores...

5 minutes read.

Writing to Excel using Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

3 minutes read.

Python String find() method

Python String find() method The string.find() method in Python finds the first occurrence of the specified value and returns the lowest index in the string if the substring sub is found else it...

2 minutes read.

Python Switch Case

What is a Switch Case Statement? In the programming languages, a switch statement is a logical loop or syntax that tests the variable's value and compares it with multiple cases. Once...

3 minutes read.

Python Assert

Python Assert Python provides an assert statement which is used to check the logical expression. If the given logical expression is true, then it precedes for the next line; otherwise, it raises an...

2 minutes read.

How to change the names of Columns in Python

Introduction To play with huge amounts of data, in Python we require a tool. The tool which is available in Python is Pandas. Pandas is an open-source library. It is used...

3 minutes read.

Python Lexicographic Order

Python lexicographic order Before we discuss the lexicographic order in Python, we should understandwhat is lexicographic order and sort according to lexicographic order. Lexicographic order In mathematics, the generalization of the alphabetical order...

5 minutes read.

How to add 2 lists in Python?

In Python, a list is defined as a data structure that contains a sequence of elements. It can contain any kind of data type inside it but in order to concatenate two...

3 minutes read.

Copying a file from one folder to Another with Python

In this article, we shall discuss copying a file from one folder to another using python functions. A file is a collection of data or information stored on a computer....

3 minutes read.

Python Dictionary get() method

Python Dictionary get() method The dictionary.get() method returns the value of the item with the specified key. Syntax dictionary.get(keyname, value) Parameter keyname- This parameter represents the key to be searched in the dictionary. value- The parameter...

1 minute read.

Front end in python

Python : Python is an object oriented programming language which is highly interpreted and is highly interactive. Python was created by Guido van Rossum in the year 1985 – 1990 .The...

4 minutes read.

Checking whether a String Contains a Set of Characters in python

In this tutorial, we will learn how to examine or check whether a string contains any set of characters or a substring and if it contains, we will learn how...

6 minutes read.

Python sum() function

Python sum() function The sum() function in python sums start and the items of an iterable from left to right and returns the total.  Syntax sum(iterable[, start]) Parameter iterable: This parameter represents the sequence to sum. start: It is optional...

1 minute read.