# step 3.3 - predict subject and join it to the readings data print('Predicting subject ... ') predicted_subject = clf_subject.predict(readings_test) readings_subject_test = np.column_stack((readings_test, predicted_subject)) # step 3.4 - predict activity print('Predicting activity ... ') predicted_activity = clf_activity.predict(readings_subject_test) # step 4 - printing results actual_activity_test = df_test_s.ix[:, -1] actual_subject_test = df_test_s.ix[:, -2] subj_activity_test = np.array((100 * actual_subject_test) + actual_activity_test) predicted_subj_activity_test = (100 * predicted_subject) + predicted_activity subj_activity_train = (100 * subj_train_for_result) + activity_train_for_result predicted_subj_activity_train = ( 100 * predicted_subj_train) + predicted_activity_train ResultsWriter.write_to_file('results_junquan.txt', model='gnb_pca', y_train_actual=subj_activity_train, y_train_predicted=predicted_subj_activity_train, y_test_actual=subj_activity_test, y_test_predicted=predicted_subj_activity_test, dur_train_activity=dur_train_activity, dur_train_subj=dur_train_subj, dur_train_both=0, method='sa') # method = both / as / sa
}) # step 2.2 - predict subject activity print('Predicting subject activity ... ') predicted_subj_activity = clf_multi.predict(readings_test) predicted_subj_activity = pd.DataFrame({ 'subject': predicted_subj_activity[:, 1], 'activity_id': predicted_subj_activity[:, 0] }) predicted_subj = predicted_subj_activity.ix[:, 1] predicted_activity = predicted_subj_activity.ix[:, 0] predicted_subj_activity_test = (100 * predicted_subj) + predicted_activity # step 3 - printing results actual_subj = df_test.ix[:, -3] actual_activity = df_test.ix[:, -2] subj_activity_test = (100 * actual_subj) + actual_activity subj_activity_train = (100 * subj_train) + activity_train ResultsWriter.write_to_file('results_junquan.txt', model='gnb_multioutput', y_train_actual=subj_activity_train, y_train_predicted=predicted_subj_activity_train, y_test_actual=subj_activity_test, y_test_predicted=predicted_subj_activity_test, dur_train_activity=0, dur_train_subj=0, dur_train_both=dur_train_both, method='both') # method = both / as / sa
# step 1.2 - fit the model to predict subject print('Fitting model to predict subject and activity...') clf_both = SGDClassifier(alpha=0.1) time_bgn = time.time() clf_both.fit(readings_train, subj_activity_train) dur_train_both = time.time() - time_bgn predicted_subj_activity_train = clf_both.predict(readings_train) # step 2.1 - get the readings data (from data stratified using subject) print('Predicting subject activity ... ') readings_test = df_test.ix[:, :-3] # step 2.2 - predict subject activity predicted_subj_activity_test = clf_both.predict(readings_test) # step 3 - printing results subj_activity_test = df_test.ix[:, -1] ResultsWriter.write_to_file( 'results_junquan_both.txt', model='svm_sgd_run_' + str(i + 1), y_train_actual=subj_activity_train, y_train_predicted=predicted_subj_activity_train, y_test_actual=subj_activity_test, y_test_predicted=predicted_subj_activity_test, dur_train_activity=0, dur_train_subj=0, dur_train_both=dur_train_both, method='both') # method = both / as / sa