def test_transpose_compatible(self): """Test that the results of `transpose` are compatible for sparse and dense arrays.""" arr = tocoo(np.arange(27).reshape(3, 3, 3)) np.testing.assert_array_equal(todense(transpose(arr, (1, 2, 0))), transpose(todense(arr), (1, 2, 0))) for _ in range(5): ndims = np.random.randint(2, 6) dims = tuple(np.random.randint(5, 20, size=ndims)) axes = np.random.permutation(range(ndims)) arr = sp.random(dims, density=0.1) out1 = todense(transpose(arr, axes)) out2 = transpose(todense(arr), axes) np.testing.assert_allclose(out1, out2, verbose=True)
def predict_interval(self, X, alpha=.05): """ Get a confidence interval for the prediction at `X`. Parameters ---------- X : array-like The features at which to predict alpha : float The significance level to use for the interval Returns ------- array, shape (2, n_samples) Lower and upper bounds for the confidence interval at each sample point """ if self.fit_intercept: X = add_constant(X, has_constant='add') # NOTE: we use `obs = False` to get a confidence, rather than prediction, interval preds = self.results.get_prediction(X).conf_int(alpha=alpha, obs=False) # statsmodels uses the last dimension instead of the first to store the confidence intervals, # so we need to transpose the result return transpose(preds)
def coef__interval(self, alpha): if self.fit_intercept: return transpose(self.results.conf_int(alpha=alpha)[1:]) else: return transpose(self.results.conf_int(alpha=alpha))