Created
June 5, 2016 19:06
-
-
Save jonasft/7b60e53ead18b504ec3913c976688b5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
import pickle | |
from statistics import mode | |
from data import resources | |
import os | |
from classifiers import trainer_combination | |
from scripts import load_data as loader | |
from sklearn.naive_bayes import BernoulliNB | |
from sklearn.linear_model import LogisticRegression, SGDClassifier | |
from sklearn.ensemble import VotingClassifier | |
from sklearn.grid_search import GridSearchCV | |
from sklearn.metrics import f1_score, make_scorer, classification_report, confusion_matrix | |
from sklearn.cross_validation import StratifiedShuffleSplit, StratifiedKFold | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.pipeline import Pipeline, FeatureUnion | |
from transformers.emoticon_transformer import * | |
from transformers.tfidf_transformer import * | |
from transformers.tfidf_char_transformer import * | |
from transformers.filter_transformer import * | |
from transformers.neg_transformer import * | |
from transformers.lexicon_transformer import * | |
with open("data/pickles/combination/sgd.pickle", "rb") as file: | |
sgd = pickle.load(open_file) | |
with open("data/pickles/combination/maxent.pickle", "rb") as file: | |
maxent = pickle.load(file) | |
with open("data/pickles/combination/bernoulli.pickle", "rb") as file: | |
bernoulli = pickle.load(file) | |
eclf = VotingClassifier(estimators=[('sgd', sgd), ('maxent', maxent), ('bernoulli', bernoulli)]) | |
eclf.fit(X_train,y_train) | |
y_pred = eclf.predict(X_test) | |
labels = ['positive', 'neutral', 'negative'] | |
print(classification_report(y_test, y_pred, labels=labels, digits=3)) | |
cm = confusion_matrix(y_test, y_pred, labels=labels) | |
print(cm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment