Modeling the UFO dataset, part 2
Infine, costruirai un modello usando il vettore di testo che abbiamo creato, desc_tfidf, utilizzando la lista filtered_words per creare un vettore di testo filtrato. Vediamo se riesci a prevedere il type dell’avvistamento in base al testo. Userai un modello Naive Bayes per questo.
Questo esercizio fa parte del corso
Preprocessing per il Machine Learning in Python
Istruzioni dell'esercizio
- Filtra il vettore
desc_tfidfpassando una lista difiltered_wordsnell’indice. - Suddividi le caratteristiche
filtered_textey, garantendo una distribuzione di classi equilibrata nei set di training e test; usarandom_statepari a42. - Usa
.fit()del modellonbper adattareX_trainey_train. - Stampa il
.score()del modellonbsui setX_testey_test.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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
____