Коэффициенты - это атрибуты объекта оценки - который вы создали при создании экземпляра класса Logistic Regression - так что вы можете получить к ним доступ обычным способом Python:
>>> import numpy as NP
>>> from sklearn import datasets
>>> from sklearn import datasets as DS
>>> digits = DS.load_digits()
>>> D = digits.data
>>> T = digits.target
>>> # instantiate an estimator instance (classifier) of the Logistic Reg class
>>> clf = LR()
>>> # train the classifier
>>> clf.fit( D[:-1], T[:-1] )
LogisticRegression(C=1.0, dual=False, fit_intercept=True,
intercept_scaling=1, penalty='l2', tol=0.0001)
>>> # attributes are accessed in the normal python way
>>> dx = clf.__dict__
>>> dx.keys()
['loss', 'C', 'dual', 'fit_intercept', 'class_weight_label', 'label_',
'penalty', 'multi_class', 'raw_coef_', 'tol', 'class_weight',
'intercept_scaling']
Так вот как получить коэффициенты , но если вы собираетесь использовать их только для прогнозирования, более прямым способом является использование метода оценки прогнозирования :
>>> # instantiate the L/R classifier, passing in norm used for penalty term
>>> # and regularization strength
>>> clf = LR(C=.2, penalty='l1')
>>> clf
LogisticRegression(C=0.2, dual=False, fit_intercept=True,
intercept_scaling=1, penalty='l1', tol=0.0001)
>>> # select some "training" instances from the original data
>>> # [of course the model should not have been trained on these instances]
>>> test = NP.random.randint(0, 151, 5)
>>> d = D[test,:] # random selected data points w/o class labels
>>> t = T[test,:] # the class labels that correspond to the points in d
>>> # generate model predictions for these 5 data points
>>> v = clf.predict(d)
>>> v
array([0, 0, 2, 0, 2], dtype=int32)
>>> # how well did the model do?
>>> percent_correct = 100*NP.sum(t==v)/t.shape[0]
>>> percent_correct
100