Histogram में bins की संख्या समायोजित करना
जो histogram आपने अभी बनाया, उसमें दस bins थे। यह matplotlib का default है। "square root rule" bins चुनने का एक आम thumb rule है: bins की संख्या सैंपल्स की संख्या के वर्गमूल के बराबर रखें। अब फिर से Iris versicolor की petal length का histogram बनाएँ, इस बार bins की संख्या के लिए square root rule का उपयोग करें। आप plt.hist() के bins keyword argument से bins की संख्या बताते हैं।
Plotting utilities पहले से इम्पोर्ट हैं और seaborn के defaults भी सेट हैं। वैरिएबल versicolor_petal_length में petal lengths की एक array है और वह आपके namespace में पहले से मौजूद है।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Statistical Thinking in Python (Part 1)
अभ्यास निर्देश
numpyकोnpनाम से इम्पोर्ट कीजिए। इससे आपको square root फंक्शनnp.sqrt()मिलेगा।len()का उपयोग करके पता लगाइए कि आपके पास कितने data points हैं।- Square root rule का उपयोग करके bins की संख्या compute करें।
- Built-in
int()फंक्शन से bins की संख्या को integer में बदलें। - Histogram जनरेट करें और सुनिश्चित करें कि आप
binskeyword argument का उपयोग कर रहे हैं। - फ़िगर प्लॉट करने और अपना परिणाम देखने के लिए सबमिट करें!
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import numpy
# Compute number of data points: n_data
# Number of bins is the square root of number of data points: n_bins
# Convert number of bins to integer: n_bins
# Plot the histogram
# Label axes
_ = plt.xlabel('petal length (cm)')
_ = plt.ylabel('count')
# Show histogram
plt.show()