in src/lookoutequipment/evaluation.py [0:0]
def _get_time_ranges(self):
"""
Extract DateTimeIndex with normal values and anomalies from the
predictions generated by the model.
Returns:
pandas.DateTimeIndex:
Timestamp index for all the values marked as normal during the
training period
pandas.DateTimeIndex:
Timestamp index for all the values predicted as anomalies by
the model during the evaluation period
"""
# Extract the first time series
tag = list(self.df_list.keys())[0]
tag_df = self.df_list[tag]
# Initialize the predictions dataframe:
predictions_df = pd.DataFrame(columns=['Prediction'], index=tag_df.index)
predictions_df['Prediction'] = 0
# Loops through the predicted and labelled anomalies
# ranges and set these predictions to 1 (predicted)
# or 2 (initially known):
for index, row in self.predicted_ranges.iterrows():
predictions_df.loc[row['start']:row['end'], 'Prediction'] = 1
for index, row in self.labelled_ranges.iterrows():
predictions_df.loc[row['start']:row['end'], 'Prediction'] = 2
# Limits the analysis range to the evaluation period:
predictions_df = predictions_df[self.training_start:self.evaluation_end]
# Build a DateTimeIndex for normal values and anomalies:
index_normal = predictions_df[predictions_df['Prediction'] == 0].index
index_anomaly = predictions_df[predictions_df['Prediction'] == 1].index
index_known = predictions_df[predictions_df['Prediction'] == 2].index
return index_normal, index_anomaly, index_known