其他分享
首页 > 其他分享> > logistic中交叉熵和均方差函数图像

logistic中交叉熵和均方差函数图像

作者:互联网

image


'''
Author: huajia
Date: 2021-11-22 14:57:01
LastEditors: huajia
LastEditTime: 2021-11-23 14:18:13
Description: 略略略
'''

import numpy as np
import math
import matplotlib.pyplot as plt
from pylab import *
x = np.arange(0.01, 1, 0.01)
y = []
y2 = []
x_1 = []
x_2 = []
yy=1
for t in x:
    y_1 = yy*math.log2(round(t,2))+(1-yy)*math.log2(1-round(t,2))
    y_1 *=-1
    y_2 = math.pow((yy-t),2)
    x_1.append(yy*(1-round(t,2))+(1-yy)*(round(t,2)))
    x_2.append(yy-t)
    y.append(y_1)
    y2.append(y_2)
    
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus']=False
plt.figure(figsize=(16,8))
plt.subplot(1, 2, 1)
plt.xlabel("x")
plt.ylabel("y")
plt.plot(x, y, label="2为底的log交叉熵")
plt.plot(x,x_1,color='red',linewidth=1,linestyle='--')
plt.legend()
plt.subplot(1, 2, 2)
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(0,7)
plt.plot(x, y2, label="均方差")
plt.plot(x,x_2,color='red',linewidth=1,linestyle='--')
plt.legend()
plt.show()


标签:plot,plt,交叉,方差,yy,math,logistic,import,append
来源: https://www.cnblogs.com/huajiasama/p/15593033.html