Home > Software design >  numpy - Get values from interpolated curve
numpy - Get values from interpolated curve

Time:05-28

I used enter image description here

Looking into the plot's yData and modelPredictions, they contain only some points:

yModel:
[ 1.15782001 -0.28222724 -1.2323253  -1.74439018 -1.86822111 -1.65150054
-1.13979412 -0.37655073  0.59689757  1.74133546  3.01966445  4.39690281
5.84018563  7.31876474  8.80400881 10.26940325 11.69055029 13.04516893
14.31309498 15.476281   16.51879637 17.42682725 18.18867658 18.79476409
19.2376263  19.51191652 19.61440484 19.54397815 19.30164012 18.89051119
18.31582862 17.58494644 16.70733547 15.69458331 14.56039437 13.32058981
11.99310762 10.59800255  9.15744614  7.69572673  6.23924944  4.81653617
3.45822563  2.19707328  1.06795141  0.10784907 -0.6441279  -1.14675686
-1.35669839 -1.22849628]

modelPredictions:
[ 1.15782001 -1.86995241  0.03116542  4.63071161 10.10425433 15.03339189
18.40575265 19.61499511 18.46080785 15.14890953 10.29104893  4.90500491
0.41458645 -1.22849628]

Neither gives me enough granularity to get desired values, let alone to get precise value for any data point. I asume it's easy to get it from interpolated model, but failed to find how.

CodePudding user response:

quoting from the posted linked answer the line

modelPredictions = numpy.polyval(fittedParameters, xData)

you can change xData with whatever you want, like this

needed_x_points = [10,20,30,40,50]
modelPredictions = numpy.polyval(fittedParameters, needed_x_points)
plt.scatter(needed_x_points,modelPredictions)
plt.show()

and it will work.

beware that matplotlib.plot joins the drawn points with a line, which is essentially linear interpolating between them, so make sure you use a proper scatter plot for plotting.

  • Related