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

Voting Classifier

अब आइए तीन मशीन लर्निंग मॉडल्स को एक में जोड़ें, ताकि पहले वाले Random Forest fraud detection मॉडल को बेहतर बनाया जा सके. आप हमारे सामान्य Random Forest मॉडल को, पिछले अभ्यास वाली Logistic Regression के साथ, और एक सरल Decision Tree के साथ जोड़ेंगे. एन्सेम्बल मॉडल का तुरंत परिणाम देखने के लिए आप शॉर्टकट get_model_results() का उपयोग कर सकते हैं.

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

Python में Fraud Detection

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

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

  • Voting Classifier पैकेज इम्पोर्ट करें.
  • तीनों मॉडल्स परिभाषित करें; पहले वाला Logistic Regression लें, पिछले अभ्यासों का Random Forest लें और balanced class weights वाला Decision Tree लें.
  • तीनों क्लासिफायर्स को उनके संबंधित लेबल्स के साथ इनपुट करके एन्सेम्बल मॉडल परिभाषित करें.

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

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

# Import the package
from sklearn.ensemble import ____

# Define the three classifiers to use in the ensemble
clf1 = LogisticRegression(class_weight={0:1, 1:15}, random_state=5)
clf2 = ____(class_weight={0:1, 1:12}, criterion='gini', max_depth=8, max_features='log2',
            min_samples_leaf=10, n_estimators=30, n_jobs=-1, random_state=5)
clf3 = DecisionTreeClassifier(random_state=5, class_weight="____")

# Combine the classifiers in the ensemble model
ensemble_model = ____(estimators=[('lr', ____), ('rf', ____), ('dt', ____)], voting='hard')

# Get the results 
get_model_results(X_train, y_train, X_test, y_test, ensemble_model)
कोड संपादित करें और चलाएँ