Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
File size: 1,207 Bytes
93a9282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Split checks and the fit call shared by verification and refits."""
import numpy as np


def check_splits(*parts):
    """Require sequence metadata, one global vocabulary and disjoint group IDs."""
    first = parts[0]
    if not first.label_names:
        raise ValueError("Supply the ordered global label_names")
    seen = set()
    for data in parts:
        if data.label_names != first.label_names or data.X.shape[1:] != first.X.shape[1:]:
            raise ValueError("Split vocabularies and time/channel shapes must match")
        if data.subject is None or data.time_index is None or not len(data.y):
            raise ValueError("Every split needs nonempty windows, subject and time_index")
        if np.min(data.y) < 0 or np.max(data.y) >= len(first.label_names):
            raise ValueError("Class ID outside supplied global vocabulary")
        groups = set(np.asarray(data.subject).astype(str))
        if groups & seen:
            raise ValueError("Participant/sequence groups overlap between splits")
        seen |= groups


def fit_on(model, data):
    return model.fit(data.X, data.y, groups=data.subject, time_index=data.time_index,
                     n_classes=data.n_classes)