Skip to content

Commit

Permalink
fix: check features finite with .all()
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Sep 25, 2023
1 parent 31f0d88 commit afdd208
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/accelerometer/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ def activityClassification(epoch, activityModel="walmsley"):
activityModel = resolveModelPath(activityModel)

featureCols = joblib.load(getFileFromTar(activityModel, 'featureCols'))

X = epoch[featureCols].to_numpy()
mask = np.isfinite(X).any(axis=1)
X = X[mask]
print(f"{len(epoch) - np.sum(mask)} rows with NaN or Inf values, out of {len(epoch)}")

model = joblib.load(getFileFromTar(activityModel, 'model'))
hmmParams = joblib.load(getFileFromTar(activityModel, 'hmmParams'))
labels = joblib.load(getFileFromTar(activityModel, 'labels')).tolist()

Y = viterbi(model.predict(X), hmmParams)
X = epoch[featureCols].to_numpy()
ok = np.isfinite(X).all(axis=1)
print(f"{len(epoch) - np.sum(ok)} rows with NaN or Inf values, out of {len(epoch)}")

Y = viterbi(model.predict(X[ok]), hmmParams)

if smooth_sleep:
sleep = pd.Series(Y == 'sleep')
Expand All @@ -79,7 +77,7 @@ def activityClassification(epoch, activityModel="walmsley"):

# Append predicted activities to epoch dataframe
epoch["label"] = np.nan
epoch.loc[mask, "label"] = Y
epoch.loc[ok, "label"] = Y

# MET prediction
METs = joblib.load(getFileFromTar(activityModel, 'METs'))
Expand Down

0 comments on commit afdd208

Please sign in to comment.