#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 18 13:02:24 2017

@author: rv
"""

import numpy as np
from matplotlib import pyplot as plt
from exploration import loadSubject

data = loadSubject(101, interpolate=False)

desc = data.describe().T
desc = desc.round(2)
print(desc)

act_desc = []

for act in data['activity'].unique():
    data_act = data.loc[data['activity'] == act]

    desc_ = data_act.describe().T
    act_desc.append((act, desc_))

data_ = data.drop(['time', 'activity'], axis=1)
features = data_.columns.unique()
for feature in features:
    m = np.zeros(len(act_desc))
    s = np.zeros(len(act_desc))
示例#2
0
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score

from exploration import loadSubject, slidingWindows
from summarizingData import summarizeWindows
"""----------------------------------------------------------------------------
-------------------------------------------------------------------------------
----------------------------------------------------------------------------"""

nEstimators_ = [5, 9, 15, 25]
data = loadSubject(101)
""" Choose which features to use. Outcomment all for all """
#data = data[['time','activity','hand_acc_16g_x','hand_acc_16g_y','hand_acc_16g_z']] #TRY ONLY WITH ACC HAND
#data = data[['time','activity','heart_rate','hand_acc_16g_x','hand_acc_16g_y','hand_acc_16g_z']] #TRY ONLY WITH ACC HAND+HEART RATE
#data = data[['time','activity','hand_temp','hand_acc_16g_x','hand_acc_16g_y','hand_acc_16g_z']] #TRY ONLY WITH HAND MEASUREMENTS
data = data[[
    'time', 'activity', 'heart_rate', 'hand_temp', 'chest_temp', 'ankle_temp'
]]
""" Choose which configuration to use by commenting in."""

### This mode uses summary statistics, rolling mean and std.
#MODE = 'summaries'
#wsizes = [10,20,40,80,120]

### This mode allows prediction using full data for a given window.
MODE = 'windows'
示例#3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 18 13:56:16 2017

@author: rv
"""

import numpy as np
from matplotlib import pyplot as plt
from exploration import loadSubject

subs = [101, 102, 105, 108]
data = [loadSubject(i, interpolate=False) for i in subs]

acts = []
for _, d in enumerate(data):
    for u in d['activity'].unique():
        if u not in acts:
            acts.append(u)

m_total = []
s_total = []

for _, d in enumerate(data):
    act_desc = []

    for act in acts:
        data_act = d.loc[d['activity'] == act]

        desc_ = data_act.describe().T
### This mode uses summary statistics, rolling mean and std.
#MODE = 'summaries'
wsize = 120
nEsts = 25

"""----------------------------------------------------------------------------
-------------------------------------------------------------------------------
----------------------------------------------------------------------------"""

Results = []
for trainSub in Subs:
    print('Training Subject '+str(trainSub))
    testSubs = Subs[:]
    testSubs.remove(trainSub)
    
    data = loadSubject(trainSub)
    data = data[features]
    data_w = summarizeWindows(data,wsize)
    #Dropping time as a prediction parameter
    data_w = data_w.drop('time',axis=1)
    
    data_w = data_w.iloc[np.random.permutation(len(data_w))]
        
    X = data_w.drop('activity',axis=1)
    y = data_w['activity']
        
    clf = RandomForestClassifier(n_estimators=nEsts)
    clf.fit(X,y)
    resSub = []
    for sub in Subs:
        print('Testing Subject '+str(sub))
示例#5
0
wsize = 120
nEsts = 25
"""----------------------------------------------------------------------------
-------------------------------------------------------------------------------
----------------------------------------------------------------------------"""

Results = []
for testSub in Subs:
    print('Test Subject ' + str(testSub))
    trainSubs = Subs[:]
    trainSubs.remove(testSub)

    init = 1
    for sub in trainSubs:
        print('Loading Subject ' + str(sub))
        data = loadSubject(sub)
        #        data = data[features]
        data_w = summarizeWindows(data, wsize)

        #Dropping time as a prediction parameter
        data_w = data_w.drop('time', axis=1)

        data_w = data_w.iloc[np.random.permutation(len(data_w))]

        X_ = data_w.drop('activity', axis=1)
        y_ = data_w['activity']

        if init == 1:
            X_train = X_
            y_train = y_
            init = 0