Commit bcafdf29 authored by Frida Heskebeck's avatar Frida Heskebeck
Browse files

Finished presentation

parent 9a1735a0
No preview for this file type
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 07:38:10 2020
@author: frida
"""
import numpy as np
import sys
from get_data import get_data
import matplotlib.pyplot as plt
#%%
def main(person):
freq = 100 # Assume data was collected at 100 Hz
still = 2
walk = 20
# Get mean of accelerometer x,y,z data
acc, ground_truth = get_data(person, 'ACC')
confMat = np.zeros((3,3))
# Check minimum and maximum value over time interval. Determine activity during time interval based on difference between these
time_interval = 2 # s
for i in np.arange(0, len(acc)//freq - time_interval, time_interval):
acc_one_sec = acc[i * freq:(i + time_interval) * freq]
xMin = min(acc_one_sec)
xMax = max(acc_one_sec)
classes = ['Still','Walking','Running']
true_idx = classes.index(ground_truth[int((2 * i + time_interval) * freq / 2.0)])
if xMax - xMin < still: # Some limit for still
print("At time: {}-{}, the person is - Still ({}, Diff: {:0.2f})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)], xMax - xMin))
pred_idx = 0
elif xMax - xMin < walk: # Some limit for walk
print("At time: {}-{}, the person is - Walking ({}, Diff: {:0.2f})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)], xMax - xMin))
pred_idx = 1
else:
print("At time: {}-{}, the person is - Running ({}, Diff: {:0.2f})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)], xMax - xMin))
pred_idx = 2
confMat[true_idx,pred_idx] += 1
fig, ax = plt.subplots()
im = ax.imshow(confMat,cmap='rainbow')
# We want to show all ticks...
#ax.set_xticks(np.arange(len(classes)))
#ax.set_yticks(np.arange(len(classes)))
# ... and label them with the respective list entries
classes_tick = [' ','Still',' ','Walking',' ','Running',' ']
ax.set_xticklabels(classes_tick)
ax.set_yticklabels(classes_tick)
# Rotate the tick labels and set their alignment.
plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
rotation_mode="anchor")
# Loop over data dimensions and create text annotations.
for i in range(len(classes)):
for j in range(len(classes)):
text = ax.text(j, i, confMat[i, j],
ha="center", va="center", color="k")
ax.set_title("Confusion matrix {}, \nrows - true activity, cols - predicted activity".format(person))
#fig.tight_layout()
fig.colorbar(im)
plt.show()
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment