शुरू करेंमुफ़्त में शुरू करें

Confidence interval के लिए bootstrapping

किसी डेटा की variability आकलन करने का एक उपयोगी टूल bootstrap है. इस अभ्यास में, आप अपना खुद का bootstrapping फंक्शन लिखेंगे जो bootstrapped confidence interval लौटाने के काम आएगा.

यह फंक्शन तीन पैरामीटर लेता है: संख्याओं की 2-D array (data), गणना करने के लिए percentiles की एक सूची (percentiles), और उपयोग करने के लिए bootstrap iterations की संख्या (n_boots). यह resample फंक्शन का उपयोग करके एक bootstrap sample बनाता है, और फिर इसे कई बार दोहराकर confidence interval की गणना करता है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Time Series Data के लिए Machine Learning

पाठ्यक्रम देखें

अभ्यास निर्देश

  • फंक्शन को bootstrap की संख्या (पैरामीटर n_boots द्वारा दी गई) पर लूप चलाना चाहिए और:
    • डेटा से replacement के साथ एक रैंडम sample लें, और इस रैंडम sample का mean निकालें
    • bootstrap_means के percentiles compute करें और उसे return करें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

from sklearn.utils import ____

def bootstrap_interval(data, percentiles=(2.5, 97.5), n_boots=100):
    """Bootstrap a confidence interval for the mean of columns of a 2-D dataset."""
    # Create our empty array to fill the results
    bootstrap_means = np.zeros([n_boots, data.shape[-1]])
    for ii in range(____):
        # Generate random indices for our data *with* replacement, then take the sample mean
        random_sample = ____
        bootstrap_means[ii] = random_sample.mean(axis=0)
        
    # Compute the percentiles of choice for the bootstrapped means
    percentiles = ____(bootstrap_means, percentiles, axis=0)
    return percentiles
कोड संपादित करें और चलाएँ