1. Using class keyword, define the class CosineSimilarity. 2. Define the _init__() function, which accepts three parameters, self, x, and z, and stores them as class variables. These two parameters will be the vectors used to compute the cosine similarity. 3. Create a function named compute angle() that accepts just self as an argument (remember self is a required argument for methods). 4. Within the compute angle() method compute the angle between two vectors and return the answer in degrees. Use the following equation to compute the angle between two vector. $$ \theta = \text{arccos}{\frac{\mathbf{x} \cdot \mathbf{z}} {||\mathbf{x}|| 2 ||\mathbf{z}|| 2}) $$

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
# TODO 15.1
 
 
 
x = np.array([1, 1])
z = np.array([-2, -2])
cosin_sim = CosineSimilarity(x, z)
angle = cosin_sim.compute_angle()

print(f"angle output: {angle}")

todo_check([
(np.isclose(angle,180.0),'The value of the angle is not approximately 180 degrees! Make sure you converted from radians to degrees.')
])
 
Run the code below to put your CosineSimilarity implementation to the test.
x = np.array([1, 1])
z = np.array([-2, -2])
cosin_sim = CosineSimilarity(x, z)
angle = cosin_sim.compute_angle()

print(f"angle output: {angle}")

todo_check([
(np.isclose(angle,180.0),'The value of the angle is not approximately 180 degrees! Make sure you converted from radians to degrees.')
])
1. Using class keyword, define the class CosineSimilarity.
2. Define the _init_() function, which accepts three parameters, self, x, and z, and
stores them as class variables. These two parameters will be the vectors used to
compute the cosine similarity.
3. Create a function named compute angle() that accepts just self as an argument
(remember self is a required argument for methods).
4. Within the compute angle() method compute the angle between two vectors an
return the answer in degrees. Use the following equation to compute the angle
between two vector. $$ \theta = \text{arccos}{\frac{\mathbf{x} \cdot \mathbf{z}}
{||\mathbf{x}|| 2 ||\mathbf{z}|| 2}) $$
Transcribed Image Text:1. Using class keyword, define the class CosineSimilarity. 2. Define the _init_() function, which accepts three parameters, self, x, and z, and stores them as class variables. These two parameters will be the vectors used to compute the cosine similarity. 3. Create a function named compute angle() that accepts just self as an argument (remember self is a required argument for methods). 4. Within the compute angle() method compute the angle between two vectors an return the answer in degrees. Use the following equation to compute the angle between two vector. $$ \theta = \text{arccos}{\frac{\mathbf{x} \cdot \mathbf{z}} {||\mathbf{x}|| 2 ||\mathbf{z}|| 2}) $$
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education