## =======================================================
## MODELING
## =======================================================
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.svm import LinearSVC
from sklearn.naive_bayes import BernoulliNB, MultinomialNB
## ----- CLASSIFIERS
mnb = MultinomialNB()
svm = LinearSVC(C=1)
def get_test_train(X,y):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)
return X_train, X_test, y_train, y_test
def run_classifier(X_train, X_test, y_train, y_test, labels, target_names, classifier):
clf = classifier
clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)
report = classification_report(y_test, y_pred, target_names=target_names,output_dict=True)
score = clf.score(X_test,y_test)
return clf, score, report
def get_model(X, y, labels, target_names, classifier):
X_train, X_test, y_train, y_test = get_test_train(X,y)
model, score, report = run_classifier(X_train, X_test, y_train, y_test, labels, target_names, classifier)
return model, score, report