从3个包含重复值的列表中创建3D图形

时间:2019-05-20 04:20:19

标签: python-3.x list matplotlib graph 3d

我是python的新手。 我正在研究一个机器学习问题,在该问题中,我通过给定theta(学习率)和多个时期的准确性来评估我的模型。 如何创建一个清晰的3D图形,该图形将表示一个2参数函数,如下所示: f(theta,历元数)=精度。 我想澄清一下,因此每个theta贯穿所有时期 例如,如果: theta值= 0.1,1 纪元值= 5、10、15 那么我将评估theta值的笛卡尔积的准确性, 时代值,然后我需要绘制它。

以下是此类列表的示例:

[1,0.1,0.010000000000000002,0.0010000000000000002,1,0.1,0.010000000000000002,0.0010000000000000002,1,0.1,0.010000000000000002,0.0010000000000000002,1,0.1,0.010000000000000002,0.0010000000000000002,1,0.1,0.010000000000000002,0.0010000000000000002,1,0.1,0.010000000000000002, 0.0010000000000000002,1,0.1,0.010000000000000002,0.0010000000000000002]

[5、5、5、5、10、10、10、10、20、20、20、20、40、40、40、40、80、80、80、80、160、160、160, 160、320、320、320、320]

[0.6576355636979362,0.6494099087220626,0.6488214366675455,0.6494219372389003,0.6606834048104814,0.6515514473544203,0.648811721327023,0.6454677936461672,0.6567195458772259,0.6561162694942934,0.6533700665732143,0.6503374924243476,0.6558169444791421,0.6536837332815182,0.6479040309410463,0.6427229786308771,0.6570221093392181,0.6497263512419444,0.652764477013967,0.6536897475399369,0.6567246348651186,0.6485054567829269,0.6479012551294685, 0.6442506002692537、0.6625038745703276、0.6512535102450578、0.6509463204304359、0.6494219372389003]

1 个答案:

答案 0 :(得分:0)

我不确定我是否完全理解你的问题;不过,这是一个如何绘制3D列表的示例:

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

x=np.array([1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002, 1, 0.1, 0.010000000000000002, 0.0010000000000000002])

y=np.array([5, 5, 5, 5, 10, 10, 10, 10, 20, 20, 20, 20, 40, 40, 40, 40, 80, 80, 80, 80, 160, 160, 160, 160, 320, 320, 320, 320])

z=np.array([0.6576355636979362, 0.6494099087220626, 0.6488214366675455, 0.6494219372389003, 0.6606834048104814, 0.6515514473544203, 0.648811721327023, 0.6454677936461672, 0.6567195458772259, 0.6561162694942934, 0.6533700665732143, 0.6503374924243476, 0.6558169444791421, 0.6536837332815182, 0.6479040309410463, 0.6427229786308771, 0.6570221093392181, 0.6497263512419444, 0.652764477013967, 0.6536897475399369, 0.6567246348651186, 0.6485054567829269, 0.6479012551294685, 0.6442506002692537, 0.6625038745703276, 0.6512535102450578, 0.6509463204304359, 0.6494219372389003])

fig=plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.scatter(x,y,z)
plt.show()