Guest User

Untitled

a guest
Sep 14th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. from sklearn.dummy import DummyClassifier
  2. dummy_model = DummyClassifier(strategy = 'most_frequent', random_state = 0)
  3. dummy_model.fit(x_train, y_train)
  4.  
  5. [[9700 0 0]
  6.  
  7. [ 211 0 0]
  8.  
  9. [ 82 0 0]]
  10.  
  11. precision recall f1-score support
  12.  
  13. 1 0.97 1.00 0.99 9700
  14. 2 0.00 0.00 0.00 211
  15. 3 0.00 0.00 0.00 82
  16.  
  17. avg / total 0.94 0.97 0.96 9993
  18.  
  19. from sklearn.linear_model import LogisticRegression
  20. logit_model = LogisticRegression(C=0.05, random_state=18, class_weight='balanced', penalty='l1')
  21. logit_model.fit(x_train, y_train)
  22.  
  23. [[9700 0 0]
  24.  
  25. [ 211 0 0]
  26.  
  27. [ 82 0 0]]
  28.  
  29. precision recall f1-score support
  30.  
  31. 1 0.97 1.00 0.99 9700
  32. 2 0.00 0.00 0.00 211
  33. 3 0.00 0.00 0.00 82
  34.  
  35. avg / total 0.94 0.97 0.96 9993
  36.  
  37. logit_model_base = LogisticRegression(random_state = 18)
  38. from sklearn.model_selection import GridSearchCV
  39. parameters = {'C': [0.03, 0.05, 0.08, 0.1, 0.3, 0.5, 10], 'penalty': ['l1', 'l2']}
  40. logit_model_best = GridSearchCV(logit_model_base, param_grid = parameters, cv = 3)
  41. logit_model_best.fit(x_train, y_train)
  42.  
  43. [[9700 0 0]
  44.  
  45. [ 211 0 0]
  46.  
  47. [ 82 0 0]]
  48.  
  49. precision recall f1-score support
  50.  
  51. 1 0.97 1.00 0.99 9700
  52. 2 0.00 0.00 0.00 211
  53. 3 0.00 0.00 0.00 82
  54.  
  55. avg / total 0.94 0.97 0.96 9993
  56.  
  57. from sklearn.linear_model import LogisticRegressionCV
  58. logit_model_cv = LogisticRegressionCV(cv = 10, class_weight = 'balanced')
  59. logit_model_cv.fit(x_train, y_train)
  60.  
  61. [[2831 3384 3485]
  62.  
  63. [ 36 104 71]
  64.  
  65. [ 9 28 45]]
  66.  
  67. precision recall f1-score support
  68.  
  69. 1 0.98 0.29 0.45 9700
  70. 2 0.03 0.49 0.06 211
  71. 3 0.01 0.55 0.02 82
  72.  
  73. avg / total 0.96 0.30 0.44 9993
  74.  
  75. from sklearn.linear_model import LogisticRegressionCV
  76. logit_model_cv = LogisticRegressionCV(cv = 10)
  77. logit_model_cv.fit(x_train, y_train)
  78.  
  79. [[9700 0 0]
  80.  
  81. [ 211 0 0]
  82.  
  83. [ 82 0 0]]
  84.  
  85. precision recall f1-score support
  86.  
  87. 1 0.97 1.00 0.99 9700
  88. 2 0.00 0.00 0.00 211
  89. 3 0.00 0.00 0.00 82
  90.  
  91. avg / total 0.94 0.97 0.96 9993
Add Comment
Please, Sign In to add comment