मॉडल के प्रदर्शन का आकलन

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

David Cecchini

Data Scientist

Accuracy बहुत जानकारीपूर्ण नहीं है

20 क्लास का टास्क, 80% accuracy. क्या मॉडल अच्छा है?

  • क्या यह सभी क्लास सही वर्गीकृत कर पाता है?
  • क्या हर क्लास के लिए accuracy समान है?
  • क्या मॉडल majority क्लास पर overfit कर रहा है?

मुझे अंदाज़ा नहीं!

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

Confusion matrix

हर क्लास के लिए true और predicted जाँचें

कन्फ्यूज़न मैट्रिक्स दिखाता है, जहाँ true और predicted लेबल में अंतर हैं

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

Precision

Precision

$$\text{Precision}_{\text{class}} = \frac{\text{Correct}_{\text{class}}}{\text{Predicted}_{\text{class}}}$$

उदाहरण में:

$$ \text{Precision}_{\text{sci.space}} = \frac{76}{76+7+9} = 0.83 $$ $$ \text{Precision}_{\text{alt.atheism}} = \frac{1}{2+1+0} = 0.33 $$ $$ \text{Precision}_{\text{soc.religion.christian}} = \frac{3}{0+2+3} = 0.60 $$

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

Recall

Recall

$$\text{Recall}_{\text{class}} = \frac{\text{Correct}_{class}}{N_\text{class}}$$

उदाहरण में:

$$ \text{Recall}_{\text{sci.space}} = \frac{76}{76+2+0} = 0.97 $$ $$ \text{Recall}_{\text{alt.atheism}} = \frac{1}{7+1+2} = 0.10 $$ $$ \text{Recall}_{\text{soc.religion.christian}} = \frac{3}{9+0+3} = 0.25 $$

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

F1-Score

F1-Score

$$\text{F1 score} = 2 * \frac{\text{precision}_{\text{class}} * \text{recall}_{\text{class}}}{\text{precision}_{\text{class}} + \text{recall}_{\text{class}}}$$

उदाहरण में:

$$ f1score_{sci.space} = 2 \frac{0.83 * 0.97}{0.83 + 0.97} = 0.89 $$ $$ f1score_{alt.atheism} = 2 \frac{033 * 0.10}{033 + 0.10} = 0.15 $$ $$ f1score_{soc.religion.christian} = 2 \frac{060 * 0.25}{060 + 0.25} = 0.35 $$

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

Sklearn confusion matrix

from sklearn.metrics import confusion_matrix

# कन्फ्यूज़न मैट्रिक्स बनाएँ confusion_matrix(y_true, y_pred)

आउटपुट:

array([[76,  2,  0],
       [ 7,  1,  2],
       [ 9,  0,  3]], dtype=int64)
Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

परफॉर्मेंस मेट्रिक्स

sklearn से मेट्रिक्स

# sklearn के फंक्शन
from sklearn.metrics import confusion_matrix
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

परफॉर्मेंस मेट्रिक्स

# Accuracy
print(accuracy_score(y_true, y_pred))
$ 0.80

average=None को precision, recall और f1 score फंक्शन में जोड़ें

print(precision_score(y_true, y_pred, average=None))
print(recall_score(y_true, y_pred, average=None))
print(f1_score(y_true, y_pred, average=None))
$ array([0.83, 0.33, 0.60])
$ array([0.97, 0.10, 0.25])
$ array([0.89, 0.15, 0.35])
Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

क्लासिफिकेशन रिपोर्ट

एक ही फंक्शन से सब मेट्रिक्स:

lab_names = ['sci.space', 'alt.atheism', 'soc.religion.christian']
print(classification_report(y_true, y_pred, target_names=lab_names))
                        precision    recall  f1-score   support

             sci.space       0.83      0.97      0.89        78
           alt.atheism       0.33      0.10      0.15        10
soc.religion.christian       0.60      0.25      0.35        12

             micro avg       0.80      0.80      0.80       100
             macro avg       0.59      0.44      0.47       100
          weighted avg       0.75      0.80      0.76       100
Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

अभ्यास करते हैं!

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

Preparing Video For Download...