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