लॉस फंक्शन भाग I

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Dr. Chris Anagnostopoulos

Honorary Associate Professor

KDD '99 कप डेटासेट

kdd.iloc[0]
kdd.iloc[0]
duration                         51
protocol_type                   tcp
service                        smtp
flag                             SF
src_bytes                      1169
dst_bytes                       332
land                              0
...
dst_host_rerror_rate              0
dst_host_srv_rerror_rate          0
label                          good
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

फॉल्स पॉज़िटिव बनाम फॉल्स नेगेटिव

लेबल को बाइनरी बनाएँ:

kdd['label'] = kdd['label'] == 'bad'

Gaussian Naive Bayes क्लासिफायर फिट करें:

clf = GaussianNB().fit(X_train, y_train)
predictions = clf.predict(X_test)
results = pd.DataFrame({
    'actual': y_test,
    'predicted': predictions
})

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

फॉल्स पॉज़िटिव बनाम फॉल्स नेगेटिव

लेबल को बाइनरी बनाएँ:

kdd['label'] = kdd['label'] == 'bad'

Gaussian Naive Bayes क्लासिफायर फिट करें:

clf = GaussianNB().fit(X_train, y_train)
predictions = clf.predict(X_test)
results = pd.DataFrame({
    'actual': y_test,
    'predicted': predictions
})

लेबल और प्रेडिक्शन के चार संयोजन होते हैं: दोनों True, दोनों False, लेबल True व प्रेडिक्शन False, और लेबल False व प्रेडिक्शन True. अंतिम संयोजन यहाँ हाइलाइट है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

फॉल्स पॉज़िटिव बनाम फॉल्स नेगेटिव

लेबल को बाइनरी बनाएँ:

kdd['label'] = kdd['label'] == 'bad'

Gaussian Naive Bayes क्लासिफायर फिट करें:

clf = GaussianNB().fit(X_train, y_train)
predictions = clf.predict(X_test)
results = pd.DataFrame({
    'actual': y_test,
    'predicted': predictions
})

अब, लेबल True और प्रेडिक्शन False का संयोजन हाइलाइट है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

फॉल्स पॉज़िटिव बनाम फॉल्स नेगेटिव

लेबल को बाइनरी बनाएँ:

kdd['label'] = kdd['label'] == 'bad'

Gaussian Naive Bayes क्लासिफायर फिट करें:

clf = GaussianNB().fit(X_train, y_train)
predictions = clf.predict(X_test)
results = pd.DataFrame({
    'actual': y_test,
    'predicted': predictions
})

वे दो केस जहाँ प्रेडिक्शन लेबल से मेल खाता है, अब हाइलाइट हैं.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

कंफ्यूज़न मैट्रिक्स

conf_mat = confusion_matrix(
    ground_truth, predictions)
array([[9477,   19],
       [ 397, 2458]])
tn, fp, fn, tp = conf_mat.ravel()
(fp, fn)
(19, 397)

एक कंफ्यूज़न मैट्रिक्स, जो इस डेटासेट के लिए ऊपर बताए चारों संयोजनों की गणना दिखाता है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

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

accuracy = 1-(fp + fn)/len(ground_truth)

recall = tp/(tp+fn)
fpr = fp/(tn+fp)
precision = tp/(tp+fp)
f1 = 2*(precision*recall)/(precision+recall)
accuracy_score(ground_truth, predictions)
recall_score(ground_truth, predictions)
precision_score(ground_truth, predictions)
f1_score(ground_truth, predictions)
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

फॉल्स पॉज़िटिव बनाम फॉल्स नेगेटिव

क्लासिफायर A:

tn, fp, fn, tp = confusion_matrix(
    ground_truth, predictions_A).ravel()
(fp,fn)
(3, 3)
cost = 10 * fp + fn
33

क्लासिफायर B:

tn, fp, fn, tp = confusion_matrix(
    ground_truth, predictions_B).ravel()
(fp,fn)
(0, 26)

cost = 10 * fp + fn
26
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

कौन-सा क्लासिफायर बेहतर है?

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Preparing Video For Download...