Question: Hello, below is the full question and attached is a picture of Exercise 4.7, thank you. Calculating the similarities (a) Recall Manhattan and Euclidean distance

Hello, below is the full question and attached is a picture of Exercise 4.7, thank you.

Calculating the similarities

(a) Recall Manhattan and Euclidean distance calculation by passing by function as discussed in Exercise 4.7. Digital camera images can be formatted in JFIF files with the extension jpg or jpeg. Lets consider photos, each of which can be described over the features such as color in red (0-255), green (0-255) and blue (0-255), the geocode of shooting location in latitude (-90 90), longitude (-180 180) and altitude (in any feet). With those features, we can compute the distances of any pairs.

The sample images are computed by the three caller statements (which are in the last three line) below.

nPoints = [(115, 115, 115, -25, 110, 10),

(125, 15, 115, -25, 70, 20),

(115, 55, 115, 25, -110, 30),

(15, 115, 115, -25, 70, 40),

(115, 55, 125, -25, 110, 50),

(115, 115, 115, -25, -110, 60),

(115, 115, 55, 25, 70, 70),

(115, 115, 15, -25, 110, 80),

(55, 125, 115, 25, 70, 90),

(15, 115, 115, -25, -110, 100) ]

dist(manhattanDist, nPoints)

dist(euclideanDist, nPoints)

dist(nDimDist, nPoints)

Note that the function dist() takes yet another function, nDimDist() as argument. Practice this high order functional programming skill as illustrated in the textbook.

The sample output for 5 images, for simplicity, is:

A B C D E

A = (115, 115, 115, -25, 110, 10) 0.00 108.63 234.31 111.80 72.80

B = (125, 15, 115, -25, 70, 20) 108.63 0.00 191.57 150.00 65.57

C = (115, 55, 115, 25, -110, 30) 234.31 191.57 0.00 220.45 226.72

D = (15, 115, 115, -25, 70, 40) 111.80 150.00 220.45 0.00 124.10

E = (115, 55, 125, -25, 110, 50) 72.80 65.57 226.72 124.10 0.00

Recall HW3. First eliminate the stop words from the word list for each document.

(b) Write a Python code to find a pair of the nearest similar documents.

Hint: use Jaccard similarity of document pairs.

(c) Improve your code developed above. Explain how the code is improved and how much.

A sample run for (a):

0.062 ['doc4', 'doc6']

0.075 ['doc1', 'doc6']

0.096 ['doc1', 'doc2']

0.105 ['doc4', 'doc5']

0.107 ['doc2', 'doc6']

0.108 ['doc2', 'doc5']

0.112 ['doc1', 'doc5']

0.116 ['doc3', 'doc4']

0.118 ['doc2', 'doc3']

0.119 ['doc3', 'doc6']

0.122 ['doc1', 'doc3']

0.134 ['doc2', 'doc4']

0.137 ['doc1', 'doc4']

0.161 ['doc5', 'doc6']

0.163 ['doc3', 'doc5']

Submission:

1) Python files, one for (a) and another for (b)

2) screenshot of your executions for all (a), (b) and (c)

Hello, below is the full question and attached is a picture of

Python for Data Sciences integro with Excel and with 4.2 Python Processing As well known, Python coding can implement almost all algorithms and functions. This discusses the Python codes for statistical computation, distance measurements, MapReduce, et Some of the statistical elements that are coded below are average, min and max, medi- mode, etc. The distance between two objects can differ across different distance interpretation Minkowski distance in general, Euclidean distance in geometric space, Manhattan distance = walk distance, cosine distance in angle, and Mahalanobis' distance in multivariate datas space. Consider a list of x, y coordinate pair. For example, [(x1.9D). (62, y2). (x3,3). (x4,94)..... (an,yn). Python code import math tvo - (1,2), (2,3), (5,7), 19.5), (4,1) 1 three - [(1,2,3), (2,3,7), (5,7,2), (9,5,4), (4,1,1). 17,7,7) def euclideanDist (isti, Ist2): return math.dist (isti, 1st2) def dist (1st): print("\t\t", "***10, "Distance", ***.10) print("\t\t", end") for item in Ist[0]: print (item, "it", end") print("") for itml in lat [0]: print (itml, "it", end) for itm2 in 1st [0): print(":21}\t.format(euclideanDistrital, it?), end---> print("") Output for dist (two) ***** Distance ****... (1, 2) (2, 3) (5.7) (9,5) (1, 2) 0.00 1.41 (2, 3) 1.41 0.00 5.00 7.28 2.83 (57) 6.40 0.00 19, 5) 8.54 7.28 0.00 3.16 (4,1) 0.00 2.83 You can try to run, dist (three). Exercise 4.7: Python coding to compute Manhattan distance Modify the code Example 4.7 to compute Manhattan distance 5.00 6.08 Combine two programs together. Hint: use function to pass as a parameter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!