Scikit-Learn


Attributes  Following table consists the attributes used by  Linear Regression



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə30/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   26   27   28   29   30   31   32   33   ...   124
sklearn

Attributes 
Following table consists the attributes used by 
Linear Regression
module: 
Attributes 
Description 


Scikit-Learn
33 
coef_

array, 
shape(n_features,) 
or 
(n_targets, n_features) 
It is used to estimate the coefficients for the linear 
regression problem. It would be a 2D array of 
shape (n_targets, n_features) if multiple targets 
are passed during fit. Ex. (y 2D). On the other 
hand, it would be a 1D array of length (n_features) 
if only one target is passed during fit. 
Intercept_
: array 
This is an independent term in this linear model. 
Implementation Example 
First, import the required packages: 
import numpy as np 
from sklearn.linear_model import LinearRegression 
Now, provide the values for independent variable X: 
X = np.array([[1,1],[1,2],[2,2],[2,3]]) 
Next, the value of dependent variable y can be calculated as follows:
y = np.dot(X, np.array([1,2])) + 3 
Now, create a linear regression object as follows:
regr = LinearRegression(fit_intercept=True, normalize = True, copy_X=True, 
n_jobs=2).fit(X,y) 
Use predict() method to predict using this linear model as follows: 
regr.predict(np.array([[3,5]])) 
Output 
array([16.]) 
To get the coefficient of determination of the prediction we can use Score() method as 
follows: 
regr.score(X,y) 
Output 
1.0 
We can estimate the coefficients by using attribute named ‘coef’ as follows: 
regr.coef

Output 


Scikit-Learn
34 
array([1., 2.]) 
We can calculate the intercept i.e. the expected mean value of Y when all X = 0 by using 
attribute named ‘intercept’ as follows: 
In [24]: regr.intercept

Output 
3.0000000000000018 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   26   27   28   29   30   31   32   33   ...   124




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə