(window as any).global = window;
我在做什么错了?
答案 0 :(得分:0)
必须对线性化数据进行样条拟合,即使用log(x)
代替x
:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
#Original Data
pwl_data = np.array([[1, 1e3, 1e5, 1e8], [-90, -90, -90, -130]])
x = pwl_data[0]
y = pwl_data[1]
log_x = np.log(x)
#spine interpolation
pwl_spline = interpolate.splrep(log_x, y)
spline_log_x = np.linspace(0, 18, 30)
spline_y = interpolate.splev(spline_log_x, pwl_spline )
plt.plot(log_x, y, '-o')
plt.plot(spline_log_x, spline_y, '-*')
plt.xlabel('log(x)');
注意:我从数据中删除了零。此外,如果需要分段线性函数,样条拟合可能不是最佳选择,例如,您可以查看以下问题:https://datascience.stackexchange.com/q/8457/53362