Beispiel #1
0

# Oversamples the training data using SMOTE
'''smote = SMOTE(sampling_strategy = 'minority')
xtr, ytr = smote.fit_resample(x_train, y_train)
print('Oversamples data using SMOTE...')'''


# Create and train Mutlinomial Naive Bayes classifier
clf = LogisticRegression(solver='lbfgs',
                            multi_class='multinomial')
clf.fit(x_train, y_train)
print("Classifier trained...")
print()


# Evaluate the predictive accuracy
predicted = clf.predict(x_dev)
print("Mean Accuracy: " + str(np.mean(predicted == y_dev)))
print()

# Prints out the confusion matrix
labels = ['fp_ic', 'fp_terr', 'fp_other', 'dom', 'notapp']
cm = ConfusionMatrix(labels, y_dev, predicted)
cm.print_matrix()
print("Actual: " + str(cm.count_actual()))
print("Predicted: "+ str(cm.count_predicted()))

# Prints the classification report
print(classification_report(y_dev, predicted, target_names=labels))