dragstar328
5/24/2016 - 5:45 AM

py_kinji.py

import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
from scipy import optimize as opt

kion = pd.read_csv("kion_20160501.csv")
kion.head()

Px = np.arange(0, len(kion), 1)
Py = kion['temp']
plt.plot(Px, Py)
plt.show()


def fit_func(x, a, b, c, d):
    return a * x**3 + b * x**2 + c * x + d

res = opt.curve_fit(fit_func, Px, Py)

a = res[0][0]
b = res[0][1]
c = res[0][2]
d = res[0][3]
print("a = %s" % (a))
print("b = %s" % (b))
print("c = %s" % (c))
print("d = %s" % (d))

Px2 = []
for x in Px:
    Px2.append(a * x**3 + b * x**2 + c * x + d)

plt.plot(Px, Py)
plt.plot(Px, np.array(Px2))
plt.show()