Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. def multinomial_nb_with_cv(x_train, y_train):
  2. random.shuffle(X)
  3. kf = cross_validation.KFold(len(X), n_folds=10)
  4. acc = []
  5. for train_index, test_index in kf:
  6. y_true = y_train[test_index]
  7. clf = MultinomialNB().fit(x_train[train_index],
  8. y_train[train_index])
  9. y_pred = clf.predict(x_train[test_index])
  10. acc.append(accuracy_score(y_true, y_pred))
  11.  
  12. def multinomial_nb(x_train, y_train, x_test, y_test):
  13. clf = MultinomialNB().fit(x_train, y_train)
  14. y_pred = clf.predict(x_test)
  15. y_true = y_test
  16. print classification_report(y_true, y_pred)
  17.  
  18. precision recall f1-score support
  19.  
  20. 0 0.50 0.24 0.33 221
  21. 1 0.00 0.00 0.00 18
  22. 2 0.00 0.00 0.00 27
  23. 3 0.00 0.00 0.00 28
  24. 4 0.00 0.00 0.00 32
  25. 5 0.04 0.02 0.02 57
  26. 6 0.00 0.00 0.00 26
  27. 7 0.00 0.00 0.00 25
  28. 8 0.00 0.00 0.00 43
  29. 9 0.00 0.00 0.00 99
  30. 10 0.63 0.98 0.76 716
  31.  
  32. avg / total 0.44 0.59 0.48 1292
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement