Scikit-Learn



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə57/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   53   54   55   56   57   58   59   60   ...   124
sklearn

SGDClassifier

Furthermore, it doesn’t have ‘class_weight’ and 
‘n_jobs’ parameters. 
Attributes
Attributes of 
SGDRegressor
 
are also same as that were of 
SGDClassifier
 
module.
Rather it has three extra attributes as follows: 

average_coef_
: array, shape(n_features,) 
As name suggest, it provides the average weights assigned to the features.

average_intercept_
: array, shape(1,) 
As name suggest, it provides the averaged intercept term. 

t_
: int
It provides the number of weight updates performed during the training phase. 
Note:
the attributes average_coef_ and average_intercept_ will work after enabling 
parameter ‘average’ to True. 
Implementation Example 
Following Python script uses 
SGDRegressor
linear model

import numpy as np 
from sklearn import linear_model 
n_samples, n_features = 10, 5 
rng = np.random.RandomState(0) 
y = rng.randn(n_samples) 
X = rng.randn(n_samples, n_features) 
SGDReg 
=linear_model.SGDRegressor(max_iter=1000,penalty="elasticnet",loss='huber',tol=
1e-3, average=True) 
SGDReg.fit(X, y) 
Output 
SGDRegressor(alpha=0.0001, average=True, early_stopping=False, epsilon=0.1, 
eta0=0.01, fit_intercept=True, l1_ratio=0.15, 
learning_rate='invscaling', loss='huber', max_iter=1000, 
n_iter=None, n_iter_no_change=5, penalty='elasticnet', power_t=0.25, 
random_state=None, shuffle=True, tol=0.001, validation_fraction=0.1, 


Scikit-Learn
63 
verbose=0, warm_start=False)
Now, once fitted, we can get the weight vector with the help of following python script: 
SGDReg.coef_ 
Output 
array([-0.00423314, 0.00362922, -0.00380136, 0.00585455, 0.00396787]) 
Similarly, we can get the value of intercept with the help of following python script: 
SGReg.intercept_ 
Output 
array([0.00678258]) 
We can get the number of weight updates during training phase with the help of the 
following python script: 
SGDReg.t_ 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   53   54   55   56   57   58   59   60   ...   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ə