i have qustion in pythone program i sent to here but the answer i get is wrong i attached the answer i token from here pleas help me for get good answer
i have qustion in pythone program i sent to here but the answer i get is wrong i attached the answer i token from here pleas help me for get good answer
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
i have qustion in pythone program i sent to here but the answer i get is wrong i attached the answer i token from here pleas help me for get good answer
tahnk you
![+
X Untitled2 - Jupyter Notebe
X Home Page - Select or cre C x pandas - Google
G X Answered: Write a Python b X
و علامة تبويب جديدة
f
localhost:8889/notebooks/Untitled2.ipynb?kernel_name=python3 0
قائمة القراءة
SQL for Beginners:. û
B مرحتّار فياض - . ..Black
Google hiljs A
YouTube
Gmail M
التطبيقات
Cjupyter Untitled Last Checkpoint: as o ius (autosaved)
Logout
File
Edit
View
Insert
Cell
Kernel
Widgets
Help
Trusted
| Python 3 O
+
> Run
Code
# Defining a empty list , to store passing index
pass_index = []
# for each instance s in s, looping instance with help of index
for index in S.index:
# fetching s and sLabel from respective index
s = 5.loc[index]
sLabel
trainy.loc[index]
# finding euclidean distance between s and all instances in s
# using apply method of pandas dataframe, and passing euclidean function in it
# using axis =1 for row wise apply and second argument as s2
euclDistances = S.apply (euclidean, s2 = s, axis=1)
# first k instance have the lowest euclidean distances
# sorting euclDistances and fetching first k instances
firstk = euclDistances.sort_values ().iloc[:k]
# Label (L) for majority of k points
# fetching Labels of firstk by matching index with trainy
firstKLabels = trainy.loc[firstK.index.tolist()]
# finding most occuring label using mode method of pandas
majorLabel = firstKLabels.mode().iloc[0]
# if s label doesn't belong to majorlabel removing from s, i.e. not storing
# its index in pass index
if slabel -- majorlabel:
pass_index.append (index)
# otherwise not including
# filteredData using pass_index
filterTrainx = S.loc[pass_index]
filterTrainy = trainy.loc[pass_index]
# printing size of both
print("\nAfter removing noise: ")
print(filterTrainx.shape, filterTrainy.shape)
File "<ipython-input-2-5d04f7dacd67>", line 52
s = S.loc[index]
IndentationError: expected an indented block
3:36 PM
O Type here to search
95°F
O G ») ENG
9/27/2021
(8)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F723158fd-7202-4703-8c7a-3adefb105dcc%2Feab714b5-25b6-4281-a2a0-987a1bbf1cf8%2Fgcg681q_processed.png&w=3840&q=75)
Transcribed Image Text:+
X Untitled2 - Jupyter Notebe
X Home Page - Select or cre C x pandas - Google
G X Answered: Write a Python b X
و علامة تبويب جديدة
f
localhost:8889/notebooks/Untitled2.ipynb?kernel_name=python3 0
قائمة القراءة
SQL for Beginners:. û
B مرحتّار فياض - . ..Black
Google hiljs A
YouTube
Gmail M
التطبيقات
Cjupyter Untitled Last Checkpoint: as o ius (autosaved)
Logout
File
Edit
View
Insert
Cell
Kernel
Widgets
Help
Trusted
| Python 3 O
+
> Run
Code
# Defining a empty list , to store passing index
pass_index = []
# for each instance s in s, looping instance with help of index
for index in S.index:
# fetching s and sLabel from respective index
s = 5.loc[index]
sLabel
trainy.loc[index]
# finding euclidean distance between s and all instances in s
# using apply method of pandas dataframe, and passing euclidean function in it
# using axis =1 for row wise apply and second argument as s2
euclDistances = S.apply (euclidean, s2 = s, axis=1)
# first k instance have the lowest euclidean distances
# sorting euclDistances and fetching first k instances
firstk = euclDistances.sort_values ().iloc[:k]
# Label (L) for majority of k points
# fetching Labels of firstk by matching index with trainy
firstKLabels = trainy.loc[firstK.index.tolist()]
# finding most occuring label using mode method of pandas
majorLabel = firstKLabels.mode().iloc[0]
# if s label doesn't belong to majorlabel removing from s, i.e. not storing
# its index in pass index
if slabel -- majorlabel:
pass_index.append (index)
# otherwise not including
# filteredData using pass_index
filterTrainx = S.loc[pass_index]
filterTrainy = trainy.loc[pass_index]
# printing size of both
print("\nAfter removing noise: ")
print(filterTrainx.shape, filterTrainy.shape)
File "<ipython-input-2-5d04f7dacd67>", line 52
s = S.loc[index]
IndentationError: expected an indented block
3:36 PM
O Type here to search
95°F
O G ») ENG
9/27/2021
(8)
![+
X Untitled2 - Jupyter Notebe
X Home Page - Select or cre C x pandas - Google
G X Answered: Write a Python b X
و علامة تبويب جديدة
f
localhost:8889/notebooks/Untitled2.ipynb?kernel_name=python3 0
قائمة القراءة
SQL for Beginners:. û
B مرحبّا, فياض - . ..Black
Google hiljs A
YouTube
Gmail M
التطبيقات
C jupyter UntitledY Last Checkpoint as s ie (autosaved)
Logout
File
Edit
View
Insert
Cll
Kernel
Widgets
Help
| Python 3 O
Trusted
+
> Run
Code
In [2]: # import pandas as pd
import pandas as pd
import random
import math
# reading training data
data = pd.read_csv("fashion-mnist_train.csv")
# creating training set
trainx = data
trainy = trainx.pop("label")
## A. selecting 3000 images 300 for each Label
# using list comprehension for fetching list of (trainx, trainy) of 300 rows for each
# Label
data_list = [(trainX[trainy==label].iloc[:300], trainy[trainy==label].iloc[:300]) for label in trainy.unique()]
# concatinating all trainx and trainy in one using pd.concat and passing data_list, using list comprehension to fetch
# trainx and trainy from tuples list
trainx = pd.concat ([df[0] for df in data_list])
trainy = pd.concat ([df[1] for df in data_list])
print("Shape of Data: ")
print(trainx.shape, trainy.shape)
## B. Shuffling the training set
# first fetching the index from trainx
index_list = trainx.index.tolist()
# using random.shuffle to shuffle index_list
random.shuffle(index_list)
# using shuffle_index to get shuffled trainX and y
suffle_trainx = trainx.loc[index_list]
suffle_trainy = trainy.loc[index_list]
## C. Apply ENN
# defining lambda function to calculate euclidean distance, it takes two pd.Series
# or list as argument
# using list comprehension to find (a-b)^2 for every value in s1 and s2
# adding all squared differences using sum
# using math.sqrt to find square root of sum to get distance
euclidean = lambda s1, s2:math.sqrt(sum([(a-b)*(a-b) for a, b in zip(s1, s2)]))
# set s = I
S = suffle_trainx
# chooc valun nf h
3:35 PM
O Type here to search
95°F
O G ) ENG
9/27/2021
(8)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F723158fd-7202-4703-8c7a-3adefb105dcc%2Feab714b5-25b6-4281-a2a0-987a1bbf1cf8%2F105mjyc_processed.png&w=3840&q=75)
Transcribed Image Text:+
X Untitled2 - Jupyter Notebe
X Home Page - Select or cre C x pandas - Google
G X Answered: Write a Python b X
و علامة تبويب جديدة
f
localhost:8889/notebooks/Untitled2.ipynb?kernel_name=python3 0
قائمة القراءة
SQL for Beginners:. û
B مرحبّا, فياض - . ..Black
Google hiljs A
YouTube
Gmail M
التطبيقات
C jupyter UntitledY Last Checkpoint as s ie (autosaved)
Logout
File
Edit
View
Insert
Cll
Kernel
Widgets
Help
| Python 3 O
Trusted
+
> Run
Code
In [2]: # import pandas as pd
import pandas as pd
import random
import math
# reading training data
data = pd.read_csv("fashion-mnist_train.csv")
# creating training set
trainx = data
trainy = trainx.pop("label")
## A. selecting 3000 images 300 for each Label
# using list comprehension for fetching list of (trainx, trainy) of 300 rows for each
# Label
data_list = [(trainX[trainy==label].iloc[:300], trainy[trainy==label].iloc[:300]) for label in trainy.unique()]
# concatinating all trainx and trainy in one using pd.concat and passing data_list, using list comprehension to fetch
# trainx and trainy from tuples list
trainx = pd.concat ([df[0] for df in data_list])
trainy = pd.concat ([df[1] for df in data_list])
print("Shape of Data: ")
print(trainx.shape, trainy.shape)
## B. Shuffling the training set
# first fetching the index from trainx
index_list = trainx.index.tolist()
# using random.shuffle to shuffle index_list
random.shuffle(index_list)
# using shuffle_index to get shuffled trainX and y
suffle_trainx = trainx.loc[index_list]
suffle_trainy = trainy.loc[index_list]
## C. Apply ENN
# defining lambda function to calculate euclidean distance, it takes two pd.Series
# or list as argument
# using list comprehension to find (a-b)^2 for every value in s1 and s2
# adding all squared differences using sum
# using math.sqrt to find square root of sum to get distance
euclidean = lambda s1, s2:math.sqrt(sum([(a-b)*(a-b) for a, b in zip(s1, s2)]))
# set s = I
S = suffle_trainx
# chooc valun nf h
3:35 PM
O Type here to search
95°F
O G ) ENG
9/27/2021
(8)
Expert Solution

Step 1
It is an indentation error in python.
Look at the first picture, the first line where you defined an empty array pass_index []
In the next line, while looping through the instance s in S, press "Enter" after ":" symbol
The correct indentation would be -
for index in S.index:
s = S.lock[index]
sLable = trainy.loc[index]
The error will be solved.
Step by step
Solved in 2 steps

Recommended textbooks for you

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…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

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)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY