Я пытаюсь уместить эти данные:
12,12,12,12,12,12,12,12,12,12,14,18,38,57,100,130,191,212,285,423,653,949,1209,1412,1784,2281,2876,3661,4499,5423,6633,7730,9134,10995,12612,14459,16018,19856,22304,25233,29155,32964,37575,40174,44550,52128,56989,59105,82165,89953,92839,98010,109069,112950,117749,124869,129654,132591,136779,143303
, используя lmfit
и pandas
фрейм данных как:
import datetime
import os
import os.path
import re
import numpy as np
import pandas
from lmfit.models import PolynomialModel
import matplotlib # isort:skip
matplotlib.use('TkAgg') # isort:skip
import matplotlib.pyplot as plt # isort:skip
lastday = 60
datafile = "mwe.dat"
names=["Trial"]
data = (np.genfromtxt(datafile, delimiter=','))
dataset = pandas.DataFrame(data=data.T, columns=names)
model = PolynomialModel(5)
x = dataset.index.values
print('parameter names: {}'.format(model.param_names))
print('independent variables: {}'.format(model.independent_vars))
for name in names:
print(name)
color = next(plt.gca()._get_lines.prop_cycler)['color']
params = model.guess(dataset[name], x=x)
result = model.fit(dataset[name], params, x=x)
print(result.params)
plt.plot(dataset.index.values, dataset[name], 'o-', color=color, label=name)
plt.plot(dataset.index.values, result.best_fit, '-', color=color)
plt.legend(loc='best')
plt.tight_layout(True)
plt.show()
`print (result.params) дает результат как:
Parameters([('c0', <Parameter 'c0', value=3023.2241950739667 +/- 1.92e+03, bounds=[-inf:inf]>), ('c1', <Parameter 'c1', value=-2257.933933498409 +/- 675, bounds=[-inf:inf]>), ('c2', <Parameter 'c2', value=343.722181719893 +/- 72.4, bounds=[-inf:inf]>), ('c3', <Parameter 'c3', value=-19.15755469779014 +/- 3.14, bounds=[-inf:inf]>), ('c4', <Parameter 'c4', value=0.43895322817807797 +/- 0.0589, bounds=[-inf:inf]>), ('c5', <Parameter 'c5', value=-0.0032273077815159245 +/- 0.000397, bounds=[-inf:inf]>)])
Как я могу табулировать эти данные, например,
c0 c1 c2
3023.22419 -2257.9339 -19.15755
и т. д.