can someone explain to me why my answer is -1 instead of 2 pleas
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
can someone explain to me why my answer is -1 instead of 2 please
![1 import math
2 v def anomaly_tst(ts, w, threshold):
Write a function anomaly_tst(ts, w, threshold) that given a
time series ts, a subsequence length w, and an anomaly cut-off
3
listi = [n
threshold threshold, returns the index of the subsequence in ts
list2 = []
4
for i in range (len(ts)):
if i+w<=len(ts):
list1.append (ts[i:i+w])
for i in range (0,len(list1)):
r = [1
that has the highest mean distance above the threshold (or -1 if no
subsequence has a mean distance above the threshold). If there is
more than one subsequence that has the same mean distance that is
8 v
the max and above the threshold, then return the index of the first
such time series.
for j in range (0,len(list1)):
10 v
if list1[i]!=list1[j]:
a = listi[i]
b = list1[j]
dist = 0
for h in range (len(a)):
dist=dist+( (a[h]-b[h])**2)
dist=math.sqrt(dist)
r.append (dist)
11 v
The function takes the following parameters:
12
• ts: a time series as a list of integers, containing at least two
13
14
values
15 v
• w: an integer > o that specifies the length of subsequences
• threshold: a integer > 0, where the mean distance of a
16
17
subsequence must be greater than this threshold if it is to be
considered as an anomaly.
18
if len(r)>0:
list2. append (round (sum(r)/len(r),1))
19 v
20
Assumptions:
21
max=0
for k in range (len(list2)):
if list2[k]>max:
• You can assume that the input arguments are correctly
22 v
23 v
formatted.
24
max=list2[k]
if max>threshold or list2.count (max) >1:
for x in range (len(list2)):
if list2[x]==max:
Here are some example calls to your function:
25 v
26 v
>>> ts = [3, 0, 2, 40, 1]
27 v
>>> print(anomaly_tst(ts, 2, 40))
28
return x
2
29 v
else:
>>> print(anomaly_tst(ts, 2, 100))
30
return -1
-1
>>> print(anomaly_tst([10, 10, 10, 10, 0, 0, 10], 2, 12
A Submissions
<> Output
4
>>> print (anomaly_tst([10, 10, 10, 10, 10, 10, 10], 3,
>>> ts 3D [3, о, 2, 40, 1]
>>> print(anomaly_tst(ts, 2, 40))
-1
-1
>>>](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb4dd1632-897d-48de-be2e-66d723258ed0%2F3ca64399-ce63-48cf-a253-948776231007%2Fwfusayw_processed.png&w=3840&q=75)
Transcribed Image Text:1 import math
2 v def anomaly_tst(ts, w, threshold):
Write a function anomaly_tst(ts, w, threshold) that given a
time series ts, a subsequence length w, and an anomaly cut-off
3
listi = [n
threshold threshold, returns the index of the subsequence in ts
list2 = []
4
for i in range (len(ts)):
if i+w<=len(ts):
list1.append (ts[i:i+w])
for i in range (0,len(list1)):
r = [1
that has the highest mean distance above the threshold (or -1 if no
subsequence has a mean distance above the threshold). If there is
more than one subsequence that has the same mean distance that is
8 v
the max and above the threshold, then return the index of the first
such time series.
for j in range (0,len(list1)):
10 v
if list1[i]!=list1[j]:
a = listi[i]
b = list1[j]
dist = 0
for h in range (len(a)):
dist=dist+( (a[h]-b[h])**2)
dist=math.sqrt(dist)
r.append (dist)
11 v
The function takes the following parameters:
12
• ts: a time series as a list of integers, containing at least two
13
14
values
15 v
• w: an integer > o that specifies the length of subsequences
• threshold: a integer > 0, where the mean distance of a
16
17
subsequence must be greater than this threshold if it is to be
considered as an anomaly.
18
if len(r)>0:
list2. append (round (sum(r)/len(r),1))
19 v
20
Assumptions:
21
max=0
for k in range (len(list2)):
if list2[k]>max:
• You can assume that the input arguments are correctly
22 v
23 v
formatted.
24
max=list2[k]
if max>threshold or list2.count (max) >1:
for x in range (len(list2)):
if list2[x]==max:
Here are some example calls to your function:
25 v
26 v
>>> ts = [3, 0, 2, 40, 1]
27 v
>>> print(anomaly_tst(ts, 2, 40))
28
return x
2
29 v
else:
>>> print(anomaly_tst(ts, 2, 100))
30
return -1
-1
>>> print(anomaly_tst([10, 10, 10, 10, 0, 0, 10], 2, 12
A Submissions
<> Output
4
>>> print (anomaly_tst([10, 10, 10, 10, 10, 10, 10], 3,
>>> ts 3D [3, о, 2, 40, 1]
>>> print(anomaly_tst(ts, 2, 40))
-1
-1
>>>
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY