2015-10-20 5 views
6

के लिए एनएलपी लॉग रैखिक मॉडल को प्रशिक्षित करना सीखें मुझे आश्चर्य है कि नाम-इकाई पहचान (एनईआर) के लिए एनएलपी लॉग रैखिक मॉडल को प्रशिक्षित करने के लिए sklearn.linear_model.LogisticRegression का उपयोग कैसे करें।विज्ञान का उपयोग करना- एनईआर

साथ

enter image description here

:

के लिए एक विशिष्ट लॉग-रेखीय मॉडल के रूप में निम्नानुसार एक सशर्त संभावना को परिभाषित करता है

  • x: वर्तमान शब्द
  • y: एक शब्द के वर्ग
  • एफ: फीचर वेक्टर फ़ंक्शन, जो एक शब्द x और कक्षा y को स्केलर के वेक्टर में मैप करता है।
  • वी: सुविधा वजन वेक्टर

कर सकते हैं sklearn.linear_model.LogisticRegression ट्रेन ऐसे मॉडल?

मुद्दा यह है कि विशेषताएं कक्षा पर निर्भर करती हैं।

उत्तर

6

में scikit सीखने 0.16 और उसके बाद वाले एक लॉग-रेखीय मॉडल (यानी MAXENT वर्गीकारक, multiclass रसद प्रतिगमन) को प्रशिक्षित करने के लिए sklearn.linear_model.LogisticRegressionmultinomial विकल्प का उपयोग कर सकते हैं। वर्तमान में 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
संबंधित मुद्दे

 संबंधित मुद्दे