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

स्वचालित Recursive Feature Elimination

अब आइए इस recursive प्रक्रिया को ऑटोमेट करते हैं. अपने logistic regression एस्टीमेेटर के चारों ओर एक Recursive Feature Eliminator (RFE) रैप कीजिए और इसे वांछित फीचर्स की संख्या पास कीजिए.

सभी आवश्यक फंक्शंस और पैकेज पहले से लोड हैं और फीचर्स आपके लिए स्केल किए गए हैं.

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

Python में Dimensionality Reduction

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

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

  • LogisticRegression() एस्टीमेेटर और चुनने के लिए 3 फीचर्स के साथ RFE बनाइए.
  • फीचर्स और उनकी रैंकिंग प्रिंट कीजिए.
  • वे फीचर्स प्रिंट कीजिए जो एलिमिनेट नहीं हुए हैं.

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

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

# Create the RFE with a LogisticRegression estimator and 3 features to select
rfe = ____(estimator=____, n_features_to_select=____, verbose=1)

# Fits the eliminator to the data
rfe.fit(X_train, y_train)

# Print the features and their ranking (high = dropped early on)
print(dict(zip(X.columns, rfe.____)))

# Print the features that are not eliminated
print(X.columns[rfe.____])

# Calculates the test set accuracy
acc = accuracy_score(y_test, rfe.predict(X_test))
print(f"{acc:.1%} accuracy on test set.") 
कोड संपादित करें और चलाएँ