, polyfit, polyval "x".
, - :
import numpy as np
import matplotlib.pyplot as plt
num = 1000
x = np.linspace(0, 10, num)
y = np.exp(x)
noise = 100 * np.exp(0.2 * x) * np.random.normal(0, 1, num)
y += noise
fig, ax = plt.subplots()
ax.plot(x, y, 'ro')
plt.show()

: y. . "" .
2- ( 2 model = np.polyfit(x, y, 2)):
import numpy as np
import matplotlib.pyplot as plt
num = 1000
x = np.linspace(0, 10, num)
y = np.exp(x)
noise = 100 * np.exp(0.2 * x) * np.random.normal(0, 1, num)
y += noise
model = np.polyfit(x, y, 2)
predicted = np.polyval(model, x)
fig, axes = plt.subplots(nrows=2, sharex=True)
axes[0].plot(x, y, 'ro')
axes[0].plot(x, predicted, 'k-')
axes[0].set(title='Original Data and 2nd Order Polynomial Trend')
axes[1].plot(x, y - predicted, 'ro')
axes[1].set(title='Detrended Residual')
plt.show()

, . , . , , ( ):



