Scikit-Learn



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə37/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   33   34   35   36   37   38   39   40   ...   124
sklearn

Attributes 
Description 
coef_

array, 
shape(n_features,) 
or 
(n_target, n_features) 
This attribute provides the weight vectors.
intercept_
: float | array, shape = 
(n_targets) 
It represents the independent term in decision 
function. 
 
n_iter_
: array or None, shape (n_targets) 
Available for only ‘sag’ and ‘lsqr’ solver, returns the 
actual number of iterations for each target.
Implementation Example 
Following Python script provides a simple example of implementing Ridge Regression. We 
are using 15 samples and 10 features. The value of alpha is 0.5 in our case. There are two 
methods namely 
fit()
and 
score()
used to fit this model and calculate the score 
respectively. 
from sklearn.linear_model import Ridge 
import numpy as np 
n_samples, n_features = 15, 10 
rng = np.random.RandomState(0) 
y = rng.randn(n_samples) 


Scikit-Learn
40 
X = rng.randn(n_samples, n_features) 
rdg = Ridge(alpha=0.5) 
rdg.fit(X, y)
rdg.score(X,y) 
Output 
0.76294987 
The output shows that the above Ridge Regression model gave the score of around 76 
percent. For more accuracy, we can increase the number of samples and features. 
For the above example, we can get the weight vector with the help of following python 
script: 
rdg.coef_ 
Output 
array([ 0.32720254, -0.34503436, -0.2913278 , 0.2693125 , -0.22832508, 
-0.8635094 , -0.17079403, -0.36288055, -0.17241081, -0.43136046]) 
Similarly, we can get the value of intercept with the help of following python script: 
rdg.intercept_ 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   33   34   35   36   37   38   39   40   ...   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ə