Anomaly detection assignment

  1. Mn=statistics.mean(history_data)
    Variance=0
    for data in history_data :
    Variance += math.pow((data-Mn),2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size-1]+Zn
    Low_bound = history_data[frame_size-1]-Zn
    return [High_bound,Low_bound]
    In this code while calculating high bound and low bound why is there [frame_size-1]. That is, why are we subtracting frame size by 1? Also shouldn’t it be variance-Zn as it is in the formula? Also what does history_data[frame_size-1] do? Like which value does it get?

try:
if sensor_value > bound[0] :
print (“The light level increased suddenly. Sending an SMS.”)
response = sms.send_sms(“Someone turned on the lights”)
print("This is the response ",response)
elif sensor_value < bound[1]:
print (“The light level decreased suddenly. Sending an SMS.”)
response = sms.send_sms(“Someone turned off the lights”)
print("This is the response ",response)
history_data.append(sensor_value);
We haven’t created the list for bound. So why is there bound[0] and bound[1]. Shouldn’t it be High_bound and Low_bound?
3)
print ("This is the value "+data[‘value’])
Why is there +? Its just a print so what does the + do?

It’ll add the data[‘value’] that we wanna print during run time.

Hi @tanushree2k
history_data[frame_size-1] gets the last element from the history_data list. Since python’s list indexing is counted from 0 to n-1, we are specifying the index value as frame_size-1.
…And the ‘+’ sign in the print statement helps to combine the string(“This is the value”) and the variable’s value(data[‘value’]) and prints them as a single statement.

@tanushree2k

The plus sign “+” in the print statement concatenates the two sections “This is the value” and data[‘value’]