Accept nested feature configuration.

To do this, pass a dict as parameters to SensorFeatures class, rather than actually reading the object from yaml file.
rapids
junos 2021-08-19 17:23:23 +02:00
parent 429aa43bd1
commit 5be3e82797
3 changed files with 16 additions and 15 deletions

View File

@ -158,7 +158,11 @@ from machine_learning import pipeline
# %%
with open("../machine_learning/config/minimal_features.yaml", "r") as file:
sensor_features = yaml.full_load(file)
sensor_features_params = yaml.safe_load(file)
# %%
sensor_features = pipeline.SensorFeatures(**sensor_features_params)
sensor_features.data_types
# %%
sensor_features.get_sensor_data("proximity")
@ -174,3 +178,5 @@ sensor_features.calculate_features()
# %%
sensor_features.get_features("proximity", "all")
# %%

View File

@ -1,5 +1,5 @@
--- !SensorFeatures
grouping_variable: date_lj
data_types: [proximity]
feature_names: all
features:
proximity:
all
participants_usernames: [nokia_0000003]

View File

@ -1,7 +1,7 @@
import datetime
from collections.abc import Collection
import pandas as pd
import yaml
from sklearn.model_selection import cross_val_score
import participants.query_db
@ -9,21 +9,16 @@ from features import communication, esm, helper, proximity
from machine_learning import QUESTIONNAIRE_IDS, QUESTIONNAIRE_IDS_RENAME
class SensorFeatures(yaml.YAMLObject):
yaml_tag = u"!SensorFeatures"
class SensorFeatures:
def __init__(
self,
grouping_variable,
data_types,
feature_names=None,
participants_usernames=None,
grouping_variable: str,
features: dict,
participants_usernames: Collection = None,
):
self.data_types = data_types
self.grouping_variable = grouping_variable
if feature_names is None:
self.feature_names = []
self.data_types = features.keys()
if participants_usernames is None:
participants_usernames = participants.query_db.get_usernames(