Scikit-Learn


ElasticNet, MultiTaskElasticNet



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

ElasticNet, MultiTaskElasticNet
doesn’t have 
precompute
attribute.
Implementation Example 
To show the difference, we are implementing the same example as we did in Multi-task 
Lasso: 
from sklearn import linear_model 
MTENReg = linear_model.MultiTaskElasticNet(alpha=0.5) 
MTENReg.fit([[0,0], [1, 1], [2, 2]], [[0, 0],[1,1],[2,2]]) 
Output 
MultiTaskElasticNet(alpha=0.5, copy_X=True, fit_intercept=True, l1_ratio=0.5, 
max_iter=1000, normalize=False, random_state=None, 
selection='cyclic', tol=0.0001, warm_start=False) 
#Predicting new values 
MTENReg.predict([[1,0]]) 
Output 
array([[0.69056563, 0.69056563]]) 
#weight vectors 


Scikit-Learn
53 
MTENReg.coef_ 
Output 
array([[0.30943437, 0.30938224], 
[0.30943437, 0.30938224]]) 
#Calculating intercept 
MTENReg.intercept_ 
Output 
array([0.38118338, 0.38118338]) 
#Calculating number of iterations 
MTENReg.n_iter_ 
Output 
15 


Scikit-Learn
54 
This chapter focusses on the polynomial features and pipelining tools in Sklearn. 
Introduction to Polynomial Features 
Linear models trained on non-linear functions of data generally maintains the fast 
performance of linear methods. It also allows them to fit a much wider range of data. 
That’s the reason in machine learning such linear models, that are trained on nonlinear 
functions, are used.
One such example is that a simple linear regression can be extended by constructing 
polynomial features from the coefficients.
Mathematically, suppose we have standard linear regression model then for 2-D data it 
would look like this: 
𝑌 = 𝑤
0
+ 𝑤
1
𝑥
1
+ 𝑤
2
𝑥
2
Now, we can combine the features in second-order polynomials and our model will look 
like as follows: 
𝑌 = 𝑤
0
+ 𝑤
1
𝑥
1
+ 𝑤
2
𝑥
2
+ 𝑤
3
𝑥
1
𝑥
2
+ 𝑤
4
𝑥
1
2
+ 𝑤
5
𝑥
2
2
The above is still a linear model. Here, we saw that the resulting polynomial regression is 
in the same class of linear models and can be solved similarly.
To do so, scikit-learn provides a module named 

Yüklə 1,92 Mb.

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