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

आपकी पहली pipeline — फिर से!

Arrhythmia स्टार्टअप में आपका मासिक रिव्यू आने वाला है, और उसके हिस्से के रूप में एक एक्सपर्ट Python प्रोग्रामर आपका कोड रिव्यू करेंगे. आप best practices अपनाकर सफाई करने का निर्णय लेते हैं और अपनी feature selection और random forest classification वाली स्क्रिप्ट को एक pipeline से बदलते हैं. आप X_train और y_train नाम के training डेटासेट का उपयोग कर रहे हैं, और कई मॉड्यूल्स: feature selection के लिए RandomForestClassifier, SelectKBest() और f_classif(), साथ ही GridSearchCV और Pipeline.

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

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

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

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

  • sample कोड में दिए गए feature selector और एक random forest classifier के साथ एक pipeline बनाइए. पहली स्टेप का नाम feature_selection रखिए.
  • params में दो key-value पेयर्स जोड़िए: selector में features की संख्या k के लिए 10 और 20, और forest में n_estimators के लिए 2 और 5.
  • दिए गए pipeline और parameter grid के साथ एक GridSearchCV ऑब्जेक्ट initialize कीजिए.
  • ऑब्जेक्ट को डेटा पर fit कीजिए और best performing पैरामीटर कॉम्बिनेशन प्रिंट कीजिए.

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

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

# Create pipeline with feature selector and classifier
pipe = ___([
    (___, SelectKBest(f_classif)),
    ('clf', ___(random_state=2))])

# Create a parameter grid
params = {
   'feature_selection__k':___,
    ___:[2, 5]}

# Initialize the grid search object
grid_search = ___(___, ___=params)

# Fit it to the data and print the best value combination
print(grid_search.fit(___, ___).___)
कोड संपादित करें और चलाएँ