绘制高精度d

2024-04-16 18:48:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数组,它包含错误值作为两个不同量的函数(alpha和eigRange)。在

我像这样填充我的数组:

   for j in range(n): 
        for i in range(alphaLen):
            alpha = alpha_list[i]
            c = train.eig(xt_, yt_,m-j, m,alpha, "cpu")
            costListTrain[j, i] = cost.err(xt_, xt_, yt_, c)

   normedValues=costListTrain/np.max(costListTrain.ravel())

在哪里

^{pr2}$

我的costListTrain数组包含一些差异非常小的值,例如:

2.809458902485728 2.809458905776425 2.809458913576337 2.809459011062461 2.030326752376704 2.030329906064879 2.030337351188699 2.030428976282031 1.919840839066182 1.919846470077076 1.919859731440199 1.920021453630778 1.858436351617677 1.858444223016128 1.858462730482461 1.858687054377165 1.475871326997542 1.475901926855846 1.475973476249240 1.476822830933632 1.475775410801635 1.475806023102173 1.475877601316863 1.476727286424228 1.475774284270633 1.475804896751524 1.475876475382906 1.476726165223209 1.463578292548192 1.463611627166494 1.463689466240788 1.464609083309240 1.462859608038034 1.462893157900139 1.462971489632478 1.463896516033939 1.461912706143012 1.461954067956570 1.462047793798572 1.463079574605320 1.450581041157659 1.452770209885761 1.454835202839513 1.459676311335618 1.450581041157643 1.452770209885764 1.454835202839484 1.459676311335624 1.450581041157651 1.452770209885735 1.454835202839484 1.459676311335610 1.450581041157597 1.452770209885784 1.454835202839503 1.459676311335620 1.450581041157575 1.452770209885757 1.454835202839496 1.459676311335619 1.450581041157716 1.452770209885711 1.454835202839499 1.459676311335613 1.450581041157667 1.452770209885744 1.454835202839509 1.459676311335625 1.450581041157649 1.452770209885750 1.454835202839476 1.459676311335617 1.450581041157655 1.452770209885708 1.454835202839442 1.459676311335622 1.450581041157571 1.452770209885700 1.454835202839498 1.459676311335622

因为你可以在这里的价值非常接近!在

我试着用一种方式来绘制这些数据,其中x,y轴上有两个量,误差值用点颜色表示。在

这就是我绘制数据的方式:

    alpha_list = np.log(alpha_list)        
    eigenvalues, alphaa  = np.meshgrid(eigRange, alpha_list) 

    vMin = np.min(costListTrain)
    vMax = np.max(costListTrain)

    plt.scatter(x, y, s=70, c=normedValues, vmin=vMin, vmax=vMax, alpha=0.50)

但结果并不正确。在

  • 我试图用max除以所有值来规范化我的错误值,但没有成功!

  • 唯一能让它工作的方法(这是不正确的)是用两种不同的方法规范化我的数据。一个基于每列(这意味着因子1是常数,因子2是变化的),另一个是基于行的(意味着因子2是常数,因子1是变化的)。但这并没有什么意义,因为我需要一个单独的图来显示两个量在误差值上的折衷。

更新

这就是我最后一段的意思。 标准化值基于与特征值对应的每行的最大值:

maxsEigBasedTrain= np.amax(costListTrain.T,1)[:,np.newaxis]    
maxsEigBasedTest= np.amax(costListTest.T,1)[:,np.newaxis]

normEigCostTrain=costListTrain.T/maxsEigBasedTrain
normEigCostTest=costListTest.T/maxsEigBasedTest

标准化值基于每个列上对应于alphas的max:

maxsAlphaBasedTrain= np.amax(costListTrain,1)[:,np.newaxis]
maxsAlphaBasedTest= np.amax(costListTest,1)[:,np.newaxis]

normAlphaCostTrain=costListTrain/maxsAlphaBasedTrain
normAlphaCostTest=costListTest/maxsAlphaBasedTest

地块1:

enter image description here

其中,编号eigenvalue = 10和α变化(应对应于图1第10列):

enter image description here

其中alpha = 0.0001和特征值发生变化(应对应于图1的第一行)

enter image description here

但正如你所看到的,结果与图1不同!在

更新:

为了澄清更多信息,我是这样阅读我的数据的:

from sklearn.datasets.samples_generator import make_regression

rng = np.random.RandomState(0)
diabetes = datasets.load_diabetes()

X_diabetes, y_diabetes = diabetes.data, diabetes.target
X_diabetes=np.c_[np.ones(len(X_diabetes)),X_diabetes]
ind = np.arange(X_diabetes.shape[0])
rng.shuffle(ind)
#===============================================================================
# Split Data 
#===============================================================================
import math
cross= math.ceil(0.7*len(X_diabetes))
ind_train = ind[:cross]
X_train, y_train = X_diabetes[ind_train], y_diabetes[ind_train]

ind_val=ind[cross:]
X_val,y_val=  X_diabetes[ind_val], y_diabetes[ind_val]

我还上传了.csv文件HERE

log.csv包含绘图1规范化之前的原始值

normalizedLog.csv用于1号地块

eigenConst.csv用于地块2

alphaConst.csv用于3号地块


Tags: csv数据alphanptrainvalmax因子
1条回答
网友
1楼 · 发布于 2024-04-16 18:48:17

我想我找到了答案。首先,我的代码有一个问题。我原以为“特征值的数量”对应于行,但在for循环中,它们填充了列。目前的答案是:

for i in range(alphaLen):
    for j in range(n): 
        alpha=alpha_list[i]
        c=train.eig(xt_, yt_,m-j,m,alpha,"cpu")
        costListTrain[i,j]=cost.err(xt_,xt_,yt_,c)
        costListTest[i,j]=cost.err(xt_,xv_,yv_,c)

在向朋友和同事提问后,我得到了这样的答案:

I would assume on default imshow and other plotting commands you might want to use, do equally sized intervals on the values you are plotting. if you can set that to logarithmic you should be fine. Ideally, equally "populated bins" would proof most effective, i guess.

对于绘图,我只需从错误中减去min value,再加上一个小数字,最后取日志。在

^{pr2}$

结果是:

enter image description here

相关问题 更多 >