import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 3, 0.01)
y = np.log(x)
plt.title("loge(x)")
plt.plot(x, y)
plt.show()
默认是以log以e为底的对数函数。
效果图:
交叉熵的而分类损失: -log(x) 0<x<1
import numpy as np
import math
import matplotlib.pyplot as plt
x=np.arange(0.0001,2,0.001)
y1=[-math.log(a,2.7) for a in x]
# y2=[math.log(a,1/1.3) for a in x]
y3=[a for a in x]
plot1=plt.plot(x,y1,'-b',label="-loge(x)")
# plot2=plt.plot(x,y2,'-r',label="log0.2(x)")
# plot3=plt.plot(x,y3,'-g',label="(x)")
plt.ylim(-5, 15) #设置纵坐标范围
plt.xlim(-0.01, 2.1) #设置纵坐标范围
plt.legend(loc='lower right')
plt.show()