daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. keywords = ["python guide",
  2.             "machine learning python",
  3.             "python scikit learn",
  4.             "python how to",
  5.             "python crash course"]
  6.    
  7. from sklearn.feature_extraction.text import CountVectorizer
  8. cv = CountVectorizer(ngram_range=(1,1))
  9. X = cv.fit_transform(keywords)
  10. Xc = (X.T * X)
  11. Xc.setdiag(0)
  12. print(Xc.toarray())
  13.    
  14. [[0 1 0 0 0 0 0 1 0 0]
  15.  [1 0 0 0 0 0 0 1 0 0]
  16.  [0 0 0 0 0 0 0 1 0 0]
  17.  [0 0 0 0 0 0 0 1 0 1]
  18.  [0 0 0 0 0 0 0 1 1 0]
  19.  [0 0 0 0 0 0 1 1 0 0]
  20.  [0 0 0 0 0 1 0 1 0 0]
  21.  [1 1 1 1 1 1 1 0 1 1]
  22.  [0 0 0 0 1 0 0 1 0 0]
  23.  [0 0 0 1 0 0 0 1 0 0]]
  24.    
  25. keyword = {
  26.     "python guide": 200,
  27.     "machine learning python": 50,
  28.     "python scikit learn": 20,
  29.     "python how to": 80,
  30.     "python crash course": 100,
  31.     }
  32.    
  33. [[0 100 0 0 0 0 0 100 0 0]
  34.  [100 0 0 0 0 0 0 100 0 0]
  35.  [0 0 0 0 0 0 0 200 0 0]
  36.  [0 0 0 0 0 0 0 80 0 20]
  37.  [0 0 0 0 0 0 0 20 20 0]
  38.  [0 0 0 0 0 0 50 50 0 0]
  39.  [0 0 0 0 0 50 0 50 0 0]
  40.  [100 100 200 80 20 50 50 0 20 80]
  41.  [0 0 0 0 20 0 0 20 0 0]
  42.  [0 0 0 80 0 0 0 80 0 0]]
RAW Paste Data
Top