Scikit-Learn


Attributes  Following table consist the attributes used by  SGDClassifier



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

Attributes 
Following table consist the attributes used by 
SGDClassifier 
module: 


Scikit-Learn
60 
Attributes 
Description 
coef_
: array, shape (1, n_features) if 
n_classes==2, else (n_classes, n_features) 
This attribute provides the weight assigned to the 
features.
intercept_

array, 
shape 
(1,) 
if 
n_classes==2, else (n_classes,) 
It represents the independent term in decision 
function. 
n_iter_:
 int
It gives the number of iterations to reach the 
stopping criterion.
Implementation Example 
Like other classifiers, Stochastic Gradient Descent (SGD) has to be fitted with following 
two arrays: 

An array X holding the training samples. It is of size [n_samples, n_features]. 

An array Y holding the target values i.e. class labels for the training samples. It is 
of size [n_samples].
Following Python script uses SGDClassifier linear model

import numpy as np 
from sklearn import linear_model 
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) 
Y = np.array([1, 1, 2, 2]) 
SGDClf = linear_model.SGDClassifier(max_iter=1000, tol=1e-
3,penalty="elasticnet") 
SGDClf.fit(X, Y) 
Output 
SGDClassifier(alpha=0.0001, average=False, class_weight=None, 
early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True, 
l1_ratio=0.15, learning_rate='optimal', loss='hinge', max_iter=1000, 
n_iter=None, n_iter_no_change=5, n_jobs=None, penalty='elasticnet', 
power_t=0.5, random_state=None, shuffle=True, tol=0.001, 
validation_fraction=0.1, verbose=0, warm_start=False)
Now, once fitted, the model can predict new values as follows: 
SGDClf.predict([[2.,2.]])

Yüklə 1,92 Mb.

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