index = np.arange(0, iterations, 1) plt.plot(index, loss_history, c='blue', linestyle='solid') plt.plot(index, loss_history_test, c='red', linestyle='dashed') plt.legend(["Training Loss", "Test Loss"]) plt.xlabel("Number of Iteration") plt.ylabel("Cost") plt.show() # 同时显示训练集和测试集损失曲线