Contamination पर फिर से नज़र
आप देखते हैं कि one-class SVM में contamination पैरामीटर नहीं होता. लेकिन अब तक आप अच्छी तरह समझ चुके हैं कि false positive rate को नियंत्रित करने के लिए आपको ऐसी विधि चाहिए जिससे जितने उदाहरणों को novelty के रूप में लेबल किया जाता है, उसका अनुपात नियंत्रित हो सके. इसलिए आप scores पर threshold लगाकर प्रयोग करने का निर्णय लेते हैं. डिटेक्टर onesvm के रूप में इम्पोर्ट किया जा चुका है. आपके पास X_train, X_test, y_train, y_test, numpy np के नाम से, और confusion_matrix() भी उपलब्ध है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना
अभ्यास निर्देश
- 1-class SVM को fit करें और test डेटा को score करें.
- test डेटा में देखे गए outliers का अनुपात निकालें.
- उस अनुपात को पाने के लिए scores पर कहाँ threshold लगाना है, यह निकालने हेतु
np.quantile()का उपयोग करें. - उसी threshold से test डेटा को लेबल करें. confusion matrix प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Fit a one-class SVM detector and score the test data
nov_det = ____(X_train)
scores = ____(X_test)
# Find the observed proportion of outliers in the test data
prop = np.____(y_test==____)
# Compute the appropriate threshold
threshold = np.____(____, ____)
# Print the confusion matrix for the thresholded scores
print(confusion_matrix(y_test, ____ > ____))