-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_matrix.py
39 lines (26 loc) · 1.14 KB
/
show_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import algorithm
import matplotlib.pyplot as plt
from vector import load_from_json
def show_distance_matrix(names, coordinates):
# graph size
plt.figure(figsize=(8, 6))
# Marking dots
plt.scatter(coordinates[:, 0], coordinates[:, 1], color='blue')
# Map the student name for each point
for i, name in enumerate(names):
plt.text(coordinates[i, 0], coordinates[i, 1], name, fontsize=10, ha='right')
plt.xlabel("Dimension 1")
plt.ylabel("Dimension 2")
plt.grid(True)
plt.show()
if __name__ == "__main__":
students = load_from_json("students_data.json")
student_names = [student['name'] for student in students] # student name list
# Student vector extraction / Calculate the Similarity Matrix
student_vectors = [student["vector"] for student in students]
similarity_matrix = algorithm.calculate_similarity_matrix(student_vectors)
# Converting to distance matrix
distance_matrix = 1 - similarity_matrix
# Converting multi dimension Distance Matrix to 2d Matrix
mds_coordinates = algorithm.mds_scaling(distance_matrix)
show_distance_matrix(student_names, mds_coordinates)