Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Article 1. It is not good to eat pizza after midnight
  2. Article 2. I wouldn't survive a day withouth stackexchange
  3. Article 3. All of these are just random phrases
  4. Article 4. To prove if my experiment works.
  5. Article 5. The red dog jumps over the lazy fox
  6.  
  7. from sklearn.feature_extraction.text import CountVectorizer
  8. vectorizer = CountVectorizer(min_df=1)
  9.  
  10. n=0
  11. while n < 5:
  12. n = n + 1
  13. a = ('Article %(number)s' % {'number': n})
  14. print(a)
  15. with open("LISR2.txt") as openfile:
  16. for line in openfile:
  17. if a in line:
  18. X=line
  19. print(vectorizer.fit_transform(X))
  20.  
  21. ValueError: Iterable over raw text documents expected, string object received.
  22.  
  23. X=("It is not good to eat pizza","I wouldn't survive a day", "All of these")
  24.  
  25. print(vectorizer.fit_transform(X))
  26.  
  27. (0, 8) 1
  28. (0, 2) 1
  29. (0, 11) 1
  30. (0, 3) 1
  31. (0, 6) 1
  32. (0, 4) 1
  33. (0, 5) 1
  34. (1, 1) 1
  35. (1, 9) 1
  36. (1, 12) 1
  37. (2, 10) 1
  38. (2, 7) 1
  39. (2, 0) 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement