How to calculate the bootstrap error and its confidence interval of a time series data #780
Replies: 2 comments
-
Looking at the implementation of
it says x can be (n_samples, [n_columns]), perhaps you need to reshape your data to have this dimension? |
Beta Was this translation helpful? Give feedback.
-
Yes, @pkaf is correct it can be both an 1D or 2D array. Reshaping may not be necessary though. It depends on what your argument for import numpy as np
from mlxtend.evaluate import bootstrap
rng = np.random.RandomState(123)
x = rng.normal(loc=5., size=100)
original, std_err, ci_bounds = bootstrap(x, num_rounds=1000, func=np.mean, ci=0.95, seed=123)
print('Mean: %.2f, SE: +/- %.2f, CI95: [%.2f, %.2f]' % (original,
std_err,
ci_bounds[0],
ci_bounds[1])) and rng = np.random.RandomState(123)
x = rng.normal(loc=5., size=(100, 2))
original, std_err, ci_bounds = bootstrap(x, num_rounds=1000, func=np.mean, ci=0.95, seed=123)
print('Mean: %.2f, SE: +/- %.2f, CI95: [%.2f, %.2f]' % (original,
std_err,
ci_bounds[0],
ci_bounds[1])) would work. You could also handle the reshaping yourself if it is necessary for your from mlxtend.data import autompg_data
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
X, y = autompg_data()
lr = LinearRegression()
def r2_fit(X, model=lr):
x, y = X[:, 0].reshape(-1, 1), X[:, 1]
pred = lr.fit(x, y).predict(x)
return r2_score(y, pred)
original, std_err, ci_bounds = bootstrap(X, num_rounds=1000,
func=r2_fit,
ci=0.95,
seed=123)
print('Mean: %.2f, SE: +/- %.2f, CI95: [%.2f, %.2f]' % (original,
std_err,
ci_bounds[0],
ci_bounds[1])) |
Beta Was this translation helpful? Give feedback.
-
Dear experts, i need to calculate the bootstrap error of the 5 time series data appended in a file. In side the time_series files five time series data are separated with > > symbols. https://i.fluffy.cc/12NLsqHhTTcvR67btNjRzXZCkbpkfw9c.html can anybody suggest better way to do it. I tried http://rasbt.github.io/mlxtend/user_guide/evaluate/bootstrap/#example-1-bootstrapping-the-mean but its for only single timseries data
Beta Was this translation helpful? Give feedback.
All reactions