Advertisement
Guest User

Untitled

a guest
May 27th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri May 27 15:24:16 2016
  4.  
  5. @author: SeanEaster
  6. """
  7.  
  8. from sklearn.decomposition import LatentDirichletAllocation as LDA
  9. from sklearn.datasets import load_digits
  10. from sklearn.linear_model import LogisticRegression
  11. from sklearn.cross_validation import train_test_split
  12. from sklearn.metrics import confusion_matrix
  13.  
  14. import numpy as np
  15.  
  16. digits = load_digits()
  17.  
  18. images = digits['images']
  19. images = [image.reshape((1,-1)) for image in images]
  20. images = np.concatenate(tuple(images), axis = 0)
  21.  
  22. lda = LDA(n_topics = 16)
  23.  
  24. X = lda.fit_transform(images)
  25. Y = digits['target']
  26.  
  27. xTrain, xTest, yTrain, yTest = train_test_split(X,Y,test_size =.2, random_state=9)
  28.  
  29. classifier = LogisticRegression(C = 1e5) # Choice of C here is arbitrary; in practice, cross validate
  30. classifier.fit(X,Y)
  31. print confusion_matrix(yTest, classifier.predict(xTest))
  32.  
  33. [[33 0 0 0 0 0 0 0 0 0]
  34. [ 0 36 1 0 0 0 0 0 2 1]
  35. [ 0 1 40 2 0 0 0 0 2 0]
  36. [ 0 0 0 32 0 0 0 0 0 2]
  37. [ 0 0 0 0 36 0 0 4 0 1]
  38. [ 0 0 0 1 0 34 0 0 0 4]
  39. [ 0 0 0 0 0 0 29 0 0 0]
  40. [ 0 0 0 0 0 0 0 27 1 0]
  41. [ 0 6 1 0 1 1 0 1 25 1]
  42. [ 0 0 0 1 1 1 0 0 3 29]]
  43.  
  44. Topics in LDA model:
  45. Topic #0:
  46. government people mr law gun state president states public use right rights national new control american security encryption health united
  47. Topic #1:
  48. drive card disk bit scsi use mac memory thanks pc does video hard speed apple problem used data monitor software
  49. Topic #2:
  50. said people armenian armenians turkish did saw went came women killed children turkey told dead didn left started greek war
  51. Topic #3:
  52. year good just time game car team years like think don got new play games ago did season better ll
  53. Topic #4:
  54. 10 00 15 25 12 11 20 14 17 16 db 13 18 24 30 19 27 50 21 40
  55. Topic #5:
  56. windows window program version file dos use files available display server using application set edu motif package code ms software
  57. Topic #6:
  58. edu file space com information mail data send available program ftp email entry info list output nasa address anonymous internet
  59. Topic #7:
  60. ax max b8f g9v a86 pl 145 1d9 0t 34u 1t 3t giz bhj wm 2di 75u 2tm bxn 7ey
  61. Topic #8:
  62. god people jesus believe does say think israel christian true life jews did bible don just know world way church
  63. Topic #9:
  64. don know like just think ve want does use good people key time way make problem really work say need
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement