Created
April 7, 2020 12:51
-
-
Save pragatibaheti/25ff47918bf779fa6204ed9c326752f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# we can use sklearn algorithms in NLTK | |
from nltk.classify.scikitlearn import SklearnClassifier | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.linear_model import LogisticRegression, SGDClassifier | |
from sklearn.naive_bayes import MultinomialNB | |
from sklearn.svm import SVC | |
from sklearn.metrics import classification_report, accuracy_score, confusion_matrix | |
# Define models to train | |
names = ["SVM","K Nearest Neighbors", "Decision Tree", "Random Forest", "Logistic Regression", "SGD Classifier", | |
"Naive Bayes", "SVM Linear"] | |
classifier = [ SVC(kernel = 'linear'),KNeighborsClassifier(), DecisionTreeClassifier(), RandomForestClassifier(), LogisticRegression(), SGDClassifier(max_iter = 100), MultinomialNB(), SVC(kernel = 'linear')] | |
models = zip(names, classifier) | |
for name, model in models: | |
nltk_model = SklearnClassifier(model) | |
nltk_model.train(training) | |
accuracy = nltk.classify.accuracy(nltk_model, testing)*100 | |
print("{} Accuracy: {}".format(name, accuracy)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment