Feature selection के साथ Naive Bayes ट्रेन करना
अब आप Chapter 3 के अंत में चलाए गए Naive Bayes टेक्स्ट क्लासिफिकेशन मॉडल को फिर से चलाएँगे, लेकिन पिछले अभ्यास में चुने गए सेलेक्शन के साथ: volunteer डेटासेट के title और category_desc कॉलम.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Machine Learning के लिए Preprocessing
अभ्यास निर्देश
filtered_textटेक्स्ट वेक्टर औरyलेबल (जोcategory_descलेबल हैं) परtrain_test_split()का उपयोग करें, और असमान class distribution के कारणyसेट कोstratifyपैरामीटर में पास करें.nbNaive Bayes मॉडल कोX_trainऔरy_trainपर फिट करें.- टेस्ट सेट accuracy को
nbके लिए कैलकुलेट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Split the dataset according to the class distribution of category_desc
X_train, X_test, y_train, y_test = ____(____.toarray(), ____, stratify=____, random_state=42)
# Fit the model to the training data
nb.____
# Print out the model's accuracy
print(nb.____)