Computing a confidence interval of a sample statistic calculates an upper and lower bound for the population value of the statistic at a specified level of confidence based on sample data.
Solution for How to compute the confidence interval of a sample statistic in Python : You can use scipy.stats.t.interval() to find the confidence interval of a sample statistic Use numpy.ndarray.size – 1 with numpy.array as an array of the sample data to find the degrees of freedom. Call numpy.mean(a) to find the mean of sample data a. Call scipy.stats.sem(a) to find the standard error of a. Call scipy.stats.t.interval(alpha, df, mean, std) with df as the degrees of freedom, mean as the sample mean, and std as the sample standard error to calculate a confidence interval with confidence level alpha.
Use sklearn.utils.resample() to create bootstrap samples and generate a confidence interval.
- This solution is better for data without a normal distribution.
- Further reading: See documentation for sklearn.utils.resample()