def casas_test(x, y, num_classes, model): """ Test Trained Logistic Regression Model :param x: numpy.array training data :type y: numpy.array :param y: numpy.array training labels :param num_classes: integer number of enabled classes :param model: an model to be trained (in this case: Logistic Regression Object) :return: numpy.array (confusion matrix) """ assert (type(model) == StackedDenoisingAutoencoder) x_tensor = theano.shared(np.asarray(x, dtype=theano.config.floatX), borrow=True) result = model.classify(x_tensor) predicted_y = result[0] confusion_matrix = get_confusion_matrix(num_classes=num_classes, label=y, predicted=predicted_y) return confusion_matrix
model.do_pretraining( data=x_tensor[train_index], num_data=len(train_index), batch_size=10, learning_rate_array=pre_training_learning_rate, num_epochs=pre_training_epochs) model.do_fine_tuning( data=x_tensor[train_index], label=y_tensor[train_index], num_data=len(train_index), batch_size=10, learning_rate_array=fine_tuning_training_rate, num_epochs=fine_tuning_epochs) (predicted_y, ) = model.classify(x_tensor[test_index]) confusion_matrix = get_confusion_matrix( num_classes=feature.num_enabled_activities, label=feature.y[test_index], predicted=predicted_y) (overall_performance, per_class_performance) = \ get_performance_array(num_classes=feature.num_enabled_activities, confusion_matrix=confusion_matrix) learning_result.add_record( model.export_to_dict(), key=record_key, confusion_matrix=confusion_matrix, overall_performance=overall_performance, per_class_performance=per_class_performance) else: model.load_from_dict(record['model']) confusion_matrix = record['confusion_matrix'] overall_performance = record['overall_performance'] per_class_performance = record['per_class_performance']
learning_rate_array=[ 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005 ], num_epochs=36) # model.do_log_layer_training_only(data=train_set_x_tensor, label=train_set_y_tensor, # num_data=train_set_x.shape[0], batch_size=10, # learning_rate_array=[0.005, 0.005]) model.save(model_file_name) num_test = test_set_x.shape[0] result = model.do_reconstruction(test_set_x_tensor) reconstruction = result[0] result = model.classify(test_set_x_tensor) class_result = result[0] confusion_matrix = get_confusion_matrix(10, test_set_y, class_result) performance = get_performance_array(10, confusion_matrix) sys.stdout.write('%22s\t' % ' ') for performance_label in performance_index: sys.stdout.write('%20s\t' % performance_label) sys.stdout.write('\n') num_performance = len(performance_index) for i in range(10): activity_label = ('%d' % i) sys.stdout.write('%22s\t' % activity_label) for j in range(num_performance): sys.stdout.write('%20.5f\t' % (performance[i][j] * 100)) sys.stdout.write('\n') check_array = np.zeros(num_test) check_array[class_result == test_set_y] = 1