def main():
    data_dir = '/Users/thuong/Documents/tmp_datasets/SI/TrainValue'
    (train_data_df, test_data_df, class_names) = build_data_frame(data_dir)
    pipeline = Pipeline([('vectorizer', CountVectorizer()), ('tfidf_transformer', TfidfTransformer()), ('classifier', LinearSVC())])
    (train_data, test_data) = (train_data_df['value'].values, test_data_df['value'].values)
    (train_target, test_target) = (train_data_df['class'].values, test_data_df['class'].values)
    pipeline.fit(train_data, train_target)
    predictions = pipeline.predict(test_data)
    cnf_matrix = confusion_matrix(test_target, predictions)
    print('Confusion matrix with one-fold: ')
    print(cnf_matrix)
    print(('Score with one-fold: %s' % precision_score(test_target, predictions, average='weighted')))
    print(('Score with one-fold: %s' % precision_score(test_target, predictions, average=None)))
    plt.figure()
    plot_confusion_matrix(cnf_matrix, classes=class_names, title='Confusion matrix, without normalization')
    plt.figure()
    plot_confusion_matrix(cnf_matrix, classes=class_names, normalize=True, title='Normalized confusion matrix')
    plt.show()
def main():
    data_dir = '/Users/thuong/Documents/tmp_datasets/SI/TrainValue'
    (train_data_df, test_data_df, class_names) = build_data_frame(data_dir)
    pipeline = Pipeline([('vectorizer', CountVectorizer()), ('tfidf_transformer', TfidfTransformer()), ('classifier', LinearSVC())])
    (train_data, test_data) = (train_data_df['value'].values, test_data_df['value'].values)
    (train_target, test_target) = (train_data_df['class'].values, test_data_df['class'].values)
    pipeline.fit(train_data, train_target)
    predictions = pipeline.predict(test_data)
    cnf_matrix = confusion_matrix(test_target, predictions)
    print('Confusion matrix with one-fold: ')
    print(cnf_matrix)
    print(('Score with one-fold: %s' % precision_score(test_target, predictions, average='weighted')))
    print(('Score with one-fold: %s' % precision_score(test_target, predictions, average=None)))
    plt.figure()
    plot_confusion_matrix(cnf_matrix, classes=class_names, title='Confusion matrix, without normalization')
    plt.figure()
    plot_confusion_matrix(cnf_matrix, classes=class_names, normalize=True, title='Normalized confusion matrix')
    plt.show()