Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created January 22, 2021 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyishaR/128e54959bd677549e8504180c905b7e to your computer and use it in GitHub Desktop.
Save AyishaR/128e54959bd677549e8504180c905b7e to your computer and use it in GitHub Desktop.
x = np.random.randint(0, Xtest.shape[0] - 1)
sentence = test_df['Message'].values[x]
print("Sentence: ", sentence)
cleaned_sentence = []
sentence = removeURL(sentence)
sentence = removeHTML(sentence)
sentence = onlyAlphabets(sentence)
sentence = sentence.lower()
sentence = removeRecurring(sentence)
for word in sentence.split():
#if word not in stop:
stemmed = sno.stem(word)
cleaned_sentence.append(stemmed)
sentence = [' '.join(cleaned_sentence)]
print("\nCleaned sentence: ", sentence[0])
sentence = cv.transform(sentence)
sentence = tfidf.transform(sentence)
print("\nTrue value: ", columns[test_df['Category'].values[x]])
pred = model.predict(sentence.toarray())[0][0]
print("\nPredicted value: ", columns[int(pred>0.5)], "(", pred, "-->", (pred>0.5).astype('int'), ")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment