में scikit सीखने 0.16 और उसके बाद वाले एक लॉग-रेखीय मॉडल (यानी MAXENT वर्गीकारक, multiclass रसद प्रतिगमन) को प्रशिक्षित करने के लिए sklearn.linear_model.LogisticRegression
multinomial
विकल्प का उपयोग कर सकते हैं। वर्तमान में multinomial
विकल्प 'lbfgs' और 'newton-cg' solvers द्वारा supported only है।
आइरिस डेटा सेट के साथ उदाहरण (4 सुविधाओं, 3 वर्गों, 150 नमूने):
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model, datasets
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
# Import data
iris = datasets.load_iris()
X = iris.data # features
y_true = iris.target # labels
# Look at the size of the feature matrix and the label vector:
print('iris.data.shape: {0}'.format(iris.data.shape))
print('iris.target.shape: {0}\n'.format(iris.target.shape))
# Instantiate a MaxEnt model
logreg = linear_model.LogisticRegression(C=1e5, multi_class='multinomial', solver='lbfgs')
# Train the model
logreg.fit(X, y_true)
print('logreg.coef_: \n{0}\n'.format(logreg.coef_))
print('logreg.intercept_: \n{0}'.format(logreg.intercept_))
# Use the model to make predictions
y_pred = logreg.predict(X)
print('\ny_pred: \n{0}'.format(y_pred))
# Assess the quality of the predictions
print('\nconfusion_matrix(y_true, y_pred):\n{0}\n'.format(confusion_matrix(y_true, y_pred)))
print('classification_report(y_true, y_pred): \n{0}'.format(classification_report(y_true, y_pred)))
sklearn.linear_model.LogisticRegression
के लिए multinomial
विकल्प was introduced in version 0.16:
- में
multi_class="multinomial"
विकल्प जोड़ें: वर्ग : linear_model.LogisticRegression
लॉजिस्टिक रिग्रेशन सॉल्वर को लागू करने के लिए जो क्रॉस-एन्ट्रॉपी या बहुआयामी हानि को कम करता हैडिफ़ॉल्ट वन-बनाम-रेस्ट सेटिंग के बजाय। lbfgs
और newton-cg
सॉल्वर का समर्थन करता है। Lars Buitinck
_ और Manoj Kumar
_ द्वारा। साइमन वू द्वारा सॉल्वर विकल्प newton-cg
।
स्रोत
2015-10-28 16:37:38