@sh.add_function(dsp, outputs=['start_stop_model'])
def calibrate_start_stop_model(
on_engine, velocities, accelerations, times,
start_stop_activation_time):
"""
Calibrates an start/stop model to predict if the engine is on.
:param on_engine:
If the engine is on [-].
:type on_engine: numpy.array
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param accelerations:
Acceleration vector [m/s2].
:type accelerations: numpy.array
:param times:
Time vector [s].
:type times: numpy.array
:param start_stop_activation_time:
Start-stop activation time threshold [s].
:type start_stop_activation_time: float
:return:
Start/stop model.
:rtype: sklearn.tree.DecisionTreeClassifier
"""
from sklearn.tree import DecisionTreeClassifier
i = np.searchsorted(times, start_stop_activation_time)
model = DecisionTreeClassifier(random_state=0, max_depth=3)
if i >= velocities.shape[0]:
return _start_stop_model
model.fit(
np.column_stack((velocities[i:], accelerations[i:])), on_engine[i:]
)
return model.predict