Scikit-Learn


Attributes  Followings table consist the attributes used by  ElasticNet



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə46/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   42   43   44   45   46   47   48   49   ...   124
sklearn

Attributes 
Followings table consist the attributes used by 
ElasticNet
module: 
Attributes 
Description 
coef_
: array, shape (n_tasks, n_features) 
This attribute provides the weight vectors.
intercept_
: array, shape (n_tasks) 
It represents the independent term in decision 
function. 
n_iter_
: int
It gives the number of iterations run by the 
coordinate descent solver to reach the specified 
tolerance.
Implementation Example 
Following Python script uses 
ElasticNet
linear model which further uses coordinate 
descent as the algorithm to fit the coefficients: 
from sklearn import linear_model 
ENreg = linear_model.ElasticNet(alpha=0.5,random_state=0) 


Scikit-Learn
50 
ENreg.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2]) 
Output 
ElasticNet(alpha=0.5, copy_X=True, fit_intercept=True, l1_ratio=0.5, 
max_iter=1000, normalize=False, positive=False, precompute=False, 
random_state=0, selection='cyclic', tol=0.0001, warm_start=False) 
Now, once fitted, the model can predict new values as follows: 
ENregReg.predict([[0,1]])
Output 
array([0.73686077]) 
For the above example, we can get the weight vector with the help of following python 
script: 
ENreg.coef_ 
Output 
array([0.26318357, 0.26313923]) 
Similarly, we can get the value of intercept with the help of following python script: 
ENreg.intercept_ 
Output 
0.47367720941913904 
We can get the total number of iterations to get the specified tolerance with the help of 
following python script: 
ENreg.n_iter_ 
Output 
15 
We can change the values of alpha (towards 1) to get better results from the model.
Let us see same example with alpha = 1. 
from sklearn import linear_model 
ENreg = linear_model.ElasticNet(alpha=1,random_state=0) 
ENreg.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2]) 


Scikit-Learn
51 
Output 
ElasticNet(alpha=1, copy_X=True, fit_intercept=True, l1_ratio=0.5, 
max_iter=1000, normalize=False, positive=False, precompute=False, 
random_state=0, selection='cyclic', tol=0.0001, warm_start=False) 
#Predicting new values 
ENreg.predict([[1,0]]) 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   42   43   44   45   46   47   48   49   ...   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ə