Python 如何添加图形标签字符串值,如第一层第二层第三层而不是层号

Python 如何添加图形标签字符串值,如第一层第二层第三层而不是层号,python,matplotlib,Python,Matplotlib,如果您提前知道自己的名字: #准备数据集 trainX,trainy,testX,testy=创建_数据集() #评估模型并绘制具有给定节点数的学习曲线 num_节点=[1,2,3,4,5,6,7] 节点名称=[ “第一”、“第二”、“第三”、“第四”、“第五”、“第六”、“第七” ] 对于名称,zip中的n_节点(节点名称,num_节点): #使用给定数量的节点评估模型 历史,结果=评估模型( n_节点, trainX, 训练有素的, testX, 易怒的 ) #绘制学习曲线 pyplot.p

如果您提前知道自己的名字:

#准备数据集
trainX,trainy,testX,testy=创建_数据集()
#评估模型并绘制具有给定节点数的学习曲线
num_节点=[1,2,3,4,5,6,7]
节点名称=[
“第一”、“第二”、“第三”、“第四”、“第五”、“第六”、“第七”
]
对于名称,zip中的n_节点(节点名称,num_节点):
#使用给定数量的节点评估模型
历史,结果=评估模型(
n_节点,
trainX,
训练有素的,
testX,
易怒的
)
#绘制学习曲线
pyplot.plot(history.history['accurity'],label=name)

打印时更改标签。第一个示例
pyplot.plot(history.history['accurity',label=“first layer”)
您应该提供一个,包括一些示例数据。你到底在问什么还不清楚。是否要用更多描述性字符串替换图例文本?我想在图形中添加标签,如第一、第二、第三、第四、第五、第六、第七,而不是数值pyplot.plot(history.history['Accurance',label=“first layer”此代码显示标签第一层到所有层我知道我只是给你一个示例。创建如下列表:
layers=[“第一层”、“第二层”、“第三层”、“第四层”、“五层”、“六层”、“七层”]
然后
pyplot.plot(history.history['accurity',label=layers)
我也不想打印前两层,即我想创建第三层、第五层、第六层和第七层的打印,而不是第一层和第二层layer@SukhpalKaur将
num_节点
node_名称
更改为:
num_节点=[3,4,5,6,7]
node_名称=[“第三”、“第四”、“第五”、“第六”、“第七”]
# prepare dataset
trainX, trainy, testX, testy = create_dataset()

# evaluate model and plot learning curve with given number of nodes
num_nodes = [1, 2, 3, 4, 5, 6, 7]

for n_nodes in num_nodes:
    # evaluate model with a given number of nodes
    history, result = evaluate_model(
        n_nodes,
        trainX,
        trainy,
        testX,
        testy,
    )

    # summarize final test set accuracy
    print('nodes=%d: %.3f' % (n_nodes, result))

    # plot learning curve
    pyplot.plot(history.history['accuracy'], label=str(n_nodes))