Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. parameters = [{'kernel': ['linear'], 'C': [1, 10, 100]},
  2. {'kernel': ['rbf'], 'gamma': [1e-2,1e-3, 1e-4],'C': [1, 10, 1000, 5000], }]
  3.  
  4. tfidf = TfidfVectorizer( ngram_range=(1, 20))
  5. clf=GridSearchCV(SVC(class_weight='balanced'),parameters,cv=2,refit=True)
  6. model= make_pipeline(tfidf,clf)
  7. model.fit(X_train, y_train)
  8.  
  9.  
  10.  
  11. print("Best parameters set:",clf.best_params_)
  12. print("Grid scores on every set of parameters:")
  13. print()
  14. means = clf.cv_results_['mean_test_score']
  15. stds = clf.cv_results_['std_test_score']
  16. for mean, std, params in zip(means, stds, clf.cv_results_['params']):
  17. print("%0.3f (+/-%0.04f) for %r"
  18. % (mean, std * 2, params))
  19.  
  20.  
  21. print()
  22. print("Classification report:")
  23. y_pred = model.predict(X_test)
  24. print(classification_report(y_test, y_pred))
  25. print("Test accuracy:",accuracy_score(y_test, y_pred))
  26. labels = model.classes_
  27. matrix = confusion_matrix(y_test,y_pred)
  28. print(pd.DataFrame(matrix,columns=labels, index=labels))
  29. plot_confusion_matrix(matrix,labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement