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

मैनुअल Recursive Feature Elimination

अब जब हमने एक डायबिटीज क्लासिफायर बना लिया है, तो देखते हैं कि क्या हम फीचर्स की संख्या घटा सकते हैं, बिना मॉडल की accuracy पर ज़्यादा असर डाले.

कोड की दूसरी पंक्ति में ओरिजिनल DataFrame से फीचर्स चुने गए हैं. इस चयन को समायोजित करें.

StandardScaler() का एक इंस्टेंस scaler नाम से और LogisticRegression() का एक इंस्टेंस lr नाम से पहले से परिभाषित है.

सभी ज़रूरी फंक्शन और पैकेज भी पहले से लोड कर दिए गए हैं.

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

Python में Dimensionality Reduction

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

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

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

# Remove the feature with the lowest model coefficient
X = diabetes_df[['pregnant', 'glucose', 'diastolic', 'triceps', 'insulin', 'bmi', 'family', 'age']]

# Performs a 25-75% train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)

# Scales features and fits the logistic regression model
lr.fit(scaler.fit_transform(X_train), y_train)

# Calculates the accuracy on the test set and prints coefficients
acc = accuracy_score(y_test, lr.predict(scaler.transform(X_test)))
print(f"{acc:.1%} accuracy on test set.") 
print(dict(zip(X.columns, abs(lr.coef_[0]).round(2))))
कोड संपादित करें और चलाएँ