UFO डेटासेट का मॉडलिंग, भाग 2
अंत में, आप उस टेक्स्ट वेक्टर desc_tfidf का उपयोग करके एक मॉडल बनाएँगे, जिसे हमने बनाया था, और filtered_words सूची की मदद से एक फ़िल्टर्ड टेक्स्ट वेक्टर तैयार करेंगे। देखते हैं कि क्या आप टेक्स्ट के आधार पर sighting के type की भविष्यवाणी कर सकते हैं। इसके लिए आप Naive Bayes मॉडल का उपयोग करेंगे।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Machine Learning के लिए Preprocessing
अभ्यास निर्देश
- इंडेक्स में
filtered_wordsकी सूची पास करकेdesc_tfidfवेक्टर को फ़िल्टर करें। filtered_textफीचर्स औरyको स्प्लिट करें, ताकि training और test सेट्स में क्लास डिस्ट्रीब्यूशन बराबर रहे;random_stateको42रखें।nbमॉडल की.fit()का उपयोग करकेX_trainऔरy_trainपर फिट करें।nbमॉडल का.score()X_testऔरy_testपर प्रिंट करें।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Use the list of filtered words we created to filter the text vector
filtered_text = ____[:, list(____)]
# Split the X and y sets using train_test_split, setting stratify=y
X_train, X_test, y_train, y_test = ____(____.toarray(), ____, ____, random_state=42)
# Fit nb to the training sets
____
# Print the score of nb on the test sets
____