Accuracy गणना करें
जब आप अपने डेटा को training और testing सेट में बाँट लेते हैं, तो अब आप अपने मॉडल को training डेटा पर fit कर सकते हैं और फिर test डेटा के labels को predict कर सकते हैं। इसी का अभ्यास आप इस अभ्यास में करेंगे।
अब तक आपने Logistic Regression और Decision Trees का उपयोग किया है। यहाँ आप RandomForestClassifier का उपयोग करेंगे, जिसे आप Decision Trees के एक ensemble के रूप में समझ सकते हैं, जो आमतौर पर एक अकेले Decision Tree से बेहतर प्रदर्शन करता है।
पिछले अभ्यासों में किया गया आपका काम आगे बढ़ गया है, और training तथा test सेट क्रमशः X_train, X_test, y_train, और y_test वैरिएबल में उपलब्ध हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Marketing Analytics: Python में Customer Churn की भविष्यवाणी
अभ्यास निर्देश
sklearn.ensembleसेRandomForestClassifierइम्पोर्ट करें।RandomForestClassifierकोclfनाम से instantiate करें।clfको training डेटाX_trainऔरy_trainपर fit करें।.score()मेथड का उपयोग करके testing डेटा परclfकी accuracy compute करें।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import RandomForestClassifier
# Instantiate the classifier
clf = ____
# Fit to the training data
# Compute accuracy
print(____.____(____, ____))