शुरू करेंमुफ़्त में शुरू करें

एक heuristic को classifier में बदलना

आप यह देखकर हैरान हैं कि heuristics कितनी मददगार हो सकती हैं. इसलिए आप इस heuristic को अपने-आप में एक classifier की तरह लेने का फ़ैसला करते हैं: "बहुत अधिक unique ports होना संदिग्ध है". आप यह काम इस तरह करते हैं कि हर source के unique ports की संख्या को bad source computers में इस्तेमाल हुए average unique ports के आधार पर threshold कर देते हैं — ये वे computers हैं जिनका label True है. Dataset पहले से लोड और training व test में split है, इसलिए आपके पास मेमोरी में X_train, X_test, y_train और y_test ऑब्जेक्ट्स हैं. आपके imports में accuracy_score() और numpy as np शामिल हैं. स्पष्ट करने के लिए: इस अभ्यास में आप scikit-learn का कोई classifier फिट नहीं करेंगे, बल्कि आप अपना classification नियम स्पष्ट रूप से परिभाषित करेंगे!

यह अभ्यास पाठ्यक्रम का हिस्सा है

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

पाठ्यक्रम देखें

अभ्यास निर्देश

  • X_train में से सभी bad hosts को subselect करके एक नया dataset X_train_bad बनाएँ. ध्यान दें कि y_train एक Boolean array है.
  • bad hosts के लिए unique_ports कॉलम का average निकालकर उसे avg_bad_ports में रखें.
  • अब ऐसे classifier पर विचार करें जो हर उस example को positive प्रिडिक्ट करे जिसका unique_ports, avg_bad_ports से अधिक हो. इस classifier की test डेटा पर की गई predictions को नए वैरिएबल pred_port में सेव करें.
  • accuracy_score() का उपयोग करके test डेटा पर इस classifier की accuracy निकालें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Create a new dataset X_train_bad by subselecting bad hosts
X_train_bad = ____[____]

# Calculate the average of unique_ports in bad examples
avg_bad_ports = np.____(____['unique_ports'])

# Label as positive sources that use more ports than that
pred_port = ____['unique_ports'] > ____

# Print the accuracy of the heuristic
print(____(y_test, ____))
कोड संपादित करें और चलाएँ