import numpy as np from utils.Answer import evaluation_test1 label = np.array([0, 1, 1, 1, 1, 0, 0, 1, 1, 0]) pred = np.array([0, 1, 0, 0, 1, 1, 1, 0, 0, 1]) hypo = np.array([0.43, 0.77, 0.31, 0.03, 0.52, 0.66, 0.90, 0.26, 0.44, 0.74]) result = evaluation_test1(label, pred, at=5) real_result = {} real_result['Accuracy '] = 0.300000 real_result['Precision'] = 0.400000 real_result['Recall '] = 0.333333 real_result['F_measure'] = 0.363636 for key in result.keys(): print('your: ', key, '\t:\t %.6f' % result[key], '\tanswer: ', '\t:\t %.6f' % real_result[key])
# OPTIMIZER OPTIMIZER = 'SGD' assert DATA_NAME in ['Contracept', 'Heart', 'Yeast'] assert OPTIMIZER == 'SGD' # Load dataset, model and evaluation metric train_data, test_data, logistic_regression = _initialize(DATA_NAME) train_x, train_y = train_data num_data, num_features = train_x.shape num_class = len(np.unique(train_y)) optim = SGD() model = LogisticRegression(num_features) loss, epoch = model.train(train_x, train_y, batch_size, num_epochs, learning_rate, optim) test_x, test_y = test_data hypo, pred = model.predict(test_x) pred = np.squeeze(pred) # ======== Edit here ========= result = evaluation_test1(test_y, pred, at=90) # ============================= for key in result.keys(): print(key, '\t\t\t:\t\t %.6f' % result[key])