数据插值方式总结
Scipy 一维数据插值
曲线最好能有函数关系
详见:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html
‘’’
class scipy.interpolate.interp1d(x, y, kind=‘linear’, axis=-1, copy=True, bounds_error=None, fill_value=nan, assume_sorted=False)[source]
Interpolate a 1-D function.
x and y are arrays of values used to approximate some function f: y = f(x). This class returns a function whose call method uses interpolation to find the value of new points.
‘’’
import numpy as np
from scipy import interpolate # 插值 Class
import pylab as pl
import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame
带有 显示函数关系的插值
plt.figure(1, figsize=(40, 20))
x=np.linspace(0,10,11)
#x=[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]
y=np.sin(x)
xnew=np.linspace(0,10,101)
plt.plot(x,y,"ro")
for kind in ["nearest","zero","slinear","quadratic","cubic"]:#插值方式
#"nearest","zero"为阶梯插值
#slinear 线性插值
#"quadratic","cubic" 为2阶、3阶B样条曲线插值
f=interpolate.interp1d(x,y,kind=kind)
# ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)
ynew=f(xnew)
plt.plot(xnew,ynew,label=str(kind))
plt.legend(loc="lower right",fontsize =30)
plt.show()
df = pd.read_excel('118ad.xlsx') # 读取文件
test = DataFrame(df)
test
Activity41 Activity42 Activity43 Activity44 Activity45 Activity46 Activity47 Activity48 Activity49 Activity50 … Dose41 Dose42 Dose43 Dose44 Dose45 Dose46 Dose47 Dose48 Dose49 Dose50
0 0.000000 0.000000 0.000000 0.000000 0.000415 0.000000 0.000000 0.000000 0.000083 0.002710 … 0.164550 1.644300e-01 1.641900e-01 0.170860 0.175240 0.166360 0.161920 0.165450 0.166400 1.644000e-01
1 0.000000 0.000041 0.000428 0.000876 0.000000 0.000421 0.000809 0.000000 0.000000 0.000775 … 0.170490 1.704700e-01 1.704500e-01 0.176920 0.181820 0.172080 0.167950 0.171830 0.172660 1.696500e-01
2 0.000000 0.000820 0.000000 0.000042 0.000000 0.000842 0.000000 0.000000 0.000414 0.000000 … 0.172970 1.729800e-01 1.724400e-01 0.179670 0.184030 0.174890 0.170510 0.174370 0.175390 1.718500e-01
3 0.000453 0.000000 0.000039 0.000417 0.000000 0.000421 0.000000 0.000449 0.000000 0.000000 …