Sto usando nltk corpus movie_reviews dove ci sono molti documenti. Il mio compito è ottenere prestazioni predittive di queste revisioni con pre-elaborazione dei dati e senza pre-elaborazione. Ma c'è un problema, negli elenchi documents
e documents2
ho gli stessi documenti e ho bisogno di mescolarli per mantenere lo stesso ordine in entrambe le liste. Non posso mescolarli separatamente perché ogni volta che mischio la lista ottengo altri risultati. Questo è il motivo per cui ho bisogno di mescolare il tutto nello stesso ordine perché ho bisogno di confrontarli alla fine (dipende dall'ordine). Sto usando Python 2.7Mescola due liste contemporaneamente con lo stesso ordine
Esempio (in tempo reale sono stringhe token, ma non è parente):
documents = [(['plot : two teen couples go to a church party , '], 'neg'),
(['drink and then drive . '], 'pos'),
(['they get into an accident . '], 'neg'),
(['one of the guys dies'], 'neg')]
documents2 = [(['plot two teen couples church party'], 'neg'),
(['drink then drive . '], 'pos'),
(['they get accident . '], 'neg'),
(['one guys dies'], 'neg')]
E ho bisogno di ottenere questo risultato dopo riordino entrambe le liste:
documents = [(['one of the guys dies'], 'neg'),
(['they get into an accident . '], 'neg'),
(['drink and then drive . '], 'pos'),
(['plot : two teen couples go to a church party , '], 'neg')]
documents2 = [(['one guys dies'], 'neg'),
(['they get accident . '], 'neg'),
(['drink then drive . '], 'pos'),
(['plot two teen couples church party'], 'neg')]
ho questo codice:
def cleanDoc(doc):
stopset = set(stopwords.words('english'))
stemmer = nltk.PorterStemmer()
clean = [token.lower() for token in doc if token.lower() not in stopset and len(token) > 2]
final = [stemmer.stem(word) for word in clean]
return final
documents = [(list(movie_reviews.words(fileid)), category)
for category in movie_reviews.categories()
for fileid in movie_reviews.fileids(category)]
documents2 = [(list(cleanDoc(movie_reviews.words(fileid))), category)
for category in movie_reviews.categories()
for fileid in movie_reviews.fileids(category)]
random.shuffle(and here shuffle documents and documents2 with same order) # or somehow
@thefourtheye, Grazie mille! Ho aggiornato la mia risposta. – sshashank124
Grazie, è esattamente ciò di cui ho bisogno. –
(domanda noob) - cosa significa *? –