使用历史数据样本估计未来的增长

nam*_*ked 1 python r approximation

我有过去几年数据库增长(就规模而言)的历史记录。我试图找出可以根据历史记录向我展示数据库未来增长的最佳方式/图表,当然,如果我们添加一个新表并且它也会增长,这将无济于事,但我只是在寻找一种估计它的方法。我对 Python 或 R 的想法持开放态度

以下是多年来以 TB 为单位的数据库大小:


3.895 - 2012 6.863 - 2013
8.997 - 2014
10.626 - 2015

ari*_*ell 5

将 numpy 和 scipy 的一些部分粘合在一起,您可以使用使用数据的连续近似的一阶和二阶导数进行适当的近似。

可能有更好的方法可以做到这一点,但这对我有用。

import numpy as np
import scipy.interpolate
import matplotlib.pyplot as plt
import matplotlib

x = np.array([2012, 2013, 2014, 2015])
y = np.array([3.895, 6.863, 8.997, 10.626])

# interpolate to approximate a continuous version of hard drive usage over time
f = scipy.interpolate.interp1d(x, y, kind='quadratic')

# approximate the first and second derivatives near the last point (2015)
dx = 0.01
x0 = x[-1] - 2*dx
first = scipy.misc.derivative(f, x0, dx=dx, n=1)
second = scipy.misc.derivative(f, x0, dx=dx, n=2)

# taylor series approximation near x[-1]
forecast = lambda x_new: np.poly1d([second/2, first, f(x[-1])])(x_new - x[-1])
forecast(2016)  # 11.9

xs = np.arange(2012, 2020)
ys = forecast(xs)

# needed to prevent matplotlib from putting the x-axis in scientific notation
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)  
plt.gca().xaxis.set_major_formatter(x_formatter)

plt.plot(xs, ys)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Ben*_*ker 5

d <- data.frame(x= 2012:2015,
            y = c(3.895, 6.863, 8.997, 10.626))
Run Code Online (Sandbox Code Playgroud)

您可以可视化拟合(及其投影):这里我比较了加法模型和多项式模型。不过,我不确定我是否相信加法模型的置信区间:

library("ggplot2"); theme_set(theme_bw())
ggplot(d,aes(x,y))+ geom_point() +
    expand_limits(x=2018)+
    geom_smooth(method="lm",formula=y~poly(x,2),
                fullrange=TRUE,fill="blue")+
    geom_smooth(method="gam",formula=y~s(x,k=3),colour="red",
                fullrange=TRUE,fill="red")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我有点震惊二次关系如此接近。

summary(m1 <- lm(y~poly(x,2),data=d))
## Residual standard error: 0.07357 on 1 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9994 
## F-statistic:  2344 on 2 and 1 DF,  p-value: 0.0146
Run Code Online (Sandbox Code Playgroud)

预测:

predict(m1,newdata=data.frame(x=2016:2018),interval="confidence")
##        fit      lwr      upr
## 1 11.50325 8.901008 14.10549
## 2 11.72745 6.361774 17.09313
## 3 11.28215 2.192911 20.37139
Run Code Online (Sandbox Code Playgroud)

这些数字是你编造的,还是真实的数据?

forecast()对于更复杂的方法,该软件包会更好。