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]])
Dostları ilə paylaş: