पाइपलाइन का उपयोग
अब जबकि आपने हमारी पाइपलाइन परिभाषित कर ली है — यानी logistic regression को SMOTE method के साथ जोड़ना — आइए इसे डेटा पर चलाएँ। आप पाइपलाइन को ऐसे मान सकते हैं जैसे यह एक सिंगल मशीन लर्निंग मॉडल हो। हमारा डेटा X और y पहले से परिभाषित है, और पाइपलाइन पिछली एक्सरसाइज़ में दी गई है। क्या आप जानना चाहते हैं कि मॉडल के नतीजे क्या आते हैं? चलिए कोशिश करते हैं!
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Fraud Detection
अभ्यास निर्देश
- डेटा 'X' और 'y' को training और test सेट में बाँटें। टेस्ट सेट के लिए 30% डेटा अलग रखें, और
random_stateको zero पर सेट करें. - अपनी पाइपलाइन को training डेटा पर फिट करें और हमारे
X_testडेटासेट परpipeline.predict()फंक्शन चलाकर प्रेडिक्शन प्राप्त करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Split your data X and y, into a training and a test set and fit the pipeline onto the training data
X_train, X_test, y_train, y_test = ____
# Fit your pipeline onto your training set and obtain predictions by fitting the model onto the test data
pipeline.fit(____, ____)
predicted = pipeline.____(____)
# Obtain the results from the classification report and confusion matrix
print('Classifcation report:\n', classification_report(y_test, predicted))
conf_mat = confusion_matrix(y_true=y_test, y_pred=predicted)
print('Confusion matrix:\n', conf_mat)