def figures_compare_time_based_features(): classifiers = utils.get_classifiers() feature_sets = [ [FeatureType.count, FeatureType.heart_rate], [FeatureType.count, FeatureType.heart_rate, FeatureType.time], [FeatureType.count, FeatureType.heart_rate, FeatureType.cosine], [ FeatureType.count, FeatureType.heart_rate, FeatureType.circadian_model ] ] trial_count = 50 for attributed_classifier in classifiers: if Constants.VERBOSE: print('Running ' + attributed_classifier.name + '...') classifier_summary = SleepWakeClassifierSummaryBuilder.build_monte_carlo( attributed_classifier, feature_sets, trial_count) CurvePlotBuilder.make_roc_sw(classifier_summary, '_time_only') CurvePlotBuilder.make_pr_sw(classifier_summary, '_time_only') TableBuilder.print_table_sw(classifier_summary) CurvePlotBuilder.combine_plots_as_grid(classifiers, trial_count, '_time_only_sw_pr') CurvePlotBuilder.combine_plots_as_grid(classifiers, trial_count, '_time_only_sw_roc')
def test_make_pr_plot(self, mock_build_pr, mock_tidy_plot, mock_set_labels, mock_plt): performance_dictionary = { tuple([FeatureType.count, FeatureType.heart_rate]): ['placeholder', 'for', 'raw', 'performances'], tuple([FeatureType.count]): ['placeholder', 'for', 'raw', 'performances'] } attributed_classifier = AttributedClassifier( name="Logistic Regression", classifier=LogisticRegression()) classifier_summary = ClassifierSummary( attributed_classifier=attributed_classifier, performance_dictionary=performance_dictionary) CurvePlotBuilder.make_pr_sw(classifier_summary) mock_build_pr.assert_called_once_with(classifier_summary) mock_tidy_plot.assert_called_once_with() mock_set_labels.assert_called_once_with( attributed_classifier, 'Fraction of wake scored as wake', 'Fraction of predicted wake correct', (0.5, 1.0)) mock_plt.savefig.assert_called_once_with( str( Constants.FIGURE_FILE_PATH.joinpath( attributed_classifier.name + '_' + str(4) + '__sw_pr.png'))) mock_plt.close.assert_called_once_with()
def figures_mc_sleep_wake(): classifiers = utils.get_classifiers() feature_sets = utils.get_base_feature_sets() trial_count = 20 for attributed_classifier in classifiers: if Constants.VERBOSE: print('Running ' + attributed_classifier.name + '...') classifier_summary = SleepWakeClassifierSummaryBuilder.build_monte_carlo( attributed_classifier, feature_sets, trial_count) CurvePlotBuilder.make_roc_sw(classifier_summary) CurvePlotBuilder.make_pr_sw(classifier_summary) TableBuilder.print_table_sw(classifier_summary) CurvePlotBuilder.combine_plots_as_grid(classifiers, trial_count, '_sw_pr') CurvePlotBuilder.combine_plots_as_grid(classifiers, trial_count, '_sw_roc')
def figure_leave_one_out_roc_and_pr(): classifiers = utils.get_classifiers() feature_sets = utils.get_base_feature_sets() for attributed_classifier in classifiers: if Constants.VERBOSE: print('Running ' + attributed_classifier.name + '...') classifier_summary = SleepWakeClassifierSummaryBuilder.build_leave_one_out( attributed_classifier, feature_sets) CurvePlotBuilder.make_roc_sw(classifier_summary) CurvePlotBuilder.make_pr_sw(classifier_summary) TableBuilder.print_table_sw(classifier_summary) CurvePlotBuilder.combine_plots_as_grid( classifiers, len(SubjectBuilder.get_all_subject_ids()), '_sw_pr') CurvePlotBuilder.combine_plots_as_grid( classifiers, len(SubjectBuilder.get_all_subject_ids()), '_sw_roc')
def figures_mesa_sleep_wake(): classifiers = utils.get_classifiers() # Uncomment to just use MLP: # classifiers = [AttributedClassifier(name='Neural Net', # classifier=MLPClassifier(activation='relu', hidden_layer_sizes=(15, 15, 15), # max_iter=1000, alpha=0.01, solver='lbfgs'))] feature_sets = utils.get_base_feature_sets() for attributed_classifier in classifiers: if Constants.VERBOSE: print('Running ' + attributed_classifier.name + '...') classifier_summary = SleepWakeClassifierSummaryBuilder.build_mesa( attributed_classifier, feature_sets) CurvePlotBuilder.make_roc_sw(classifier_summary, '_mesa') CurvePlotBuilder.make_pr_sw(classifier_summary, '_mesa') TableBuilder.print_table_sw(classifier_summary) CurvePlotBuilder.combine_plots_as_grid(classifiers, 1, '_mesa_sw_pr') CurvePlotBuilder.combine_plots_as_grid(classifiers, 1, '_mesa_sw_roc')