绘制图形时发生错误:用序列设置数组元素。
import matplotlib.pyplot as plt
try:
# Plot accuracy graph
plt.figure(figsize=(10, 6))
plt.plot(["Teacher", "Assistant teacher", "Distilled student", "Student trained from scratch"],
[teacher_results, assistant_teacher_results, student_results, student_scratch_results],
marker='o')
plt.title('Accuracy Comparison')
plt.xlabel('Model')
plt.ylabel('Accuracy')
plt.ylim([0, 1])
plt.grid(True)
plt.show()
except Exception as e:
print("An error occurred while plotting the graph:", e)
要解决此问题,请确保 Teacher_results、assistant_teacher_results、student_results 和 Student_scratch_results 是数组或数字列表。如果它们是列表的列表,您可能需要将它们展平或相应地重组您的数据。
这是更正后的代码:
import matplotlib.pyplot as plt
try:
# Plot accuracy graph
plt.figure(figsize=(10, 6))
plt.plot(["Teacher", "Assistant teacher", "Distilled student", "Student trained from scratch"],
[teacher_results, assistant_teacher_results, student_results, student_scratch_results],
marker='o')
plt.title('Accuracy Comparison')
plt.xlabel('Model')
plt.ylabel('Accuracy')
plt.ylim([0, 1])
plt.grid(True)
plt.show()
except Exception as e:
print("An error occurred while plotting the graph:", e)