from scipy import statsn = stats.norm(loc=0, scale=1) # mean 0, sd 1n.pdf(0) # 0.3989 height of the bell at centern.cdf(1.96) # 0.9750 area to the left of 1.96n.sf(1.96) # 0.0250 area to the right (= 1 - cdf)n.ppf(0.975) # 1.96 inverse of cdfn.rvs(size=5) # 5 random samples
Imagine a bag of marbles where some sizes are common and some rare. A distribution is the rulebook saying how common each size is. The PDF is "how popular is exactly this size," the CDF is "how many marbles are this size or smaller." A hypothesis test is like a friend claiming the bag is "all medium marbles." You grab a handful: if you keep pulling giants, you say "no way that's just luck — your claim is wrong!" The p-value is how often pure luck could have given you a handful this weird. Tiny p = "luck can't explain this" = your friend was wrong.
Dekho, scipy.stats basically ek statistics ka toolbox hai. Iska pehla kaam hai distributions — jaise stats.norm jo normal (bell curve) ko represent karta hai. Iske andar chaar important functions hote hain: .pdf (kisi exact point pe density kitni hai), .cdf (us point tak ka total area, yaani P(X≤x)), .sf (upar wala tail, P(X>x)), aur .ppf (ulta — probability do, value milegi, yaani percentile). Yaad rakho: sab kuch CDF se nikalta hai — PDF uska derivative hai, PPF uska inverse hai.
Doosra bada kaam hai hypothesis testing. Idea simple hai: tum maan lo "kuch khaas nahi ho raha" (yeh hai H0, null hypothesis). Phir tum ek statistic banate ho jiska distribution H0 ke under pata hota hai. Phir p-value nikalta hai — iska matlab hai "agar H0 sach hota, toh itna ya isse zyada extreme data milne ka chance kitna tha." Agar p chhota hai (jaise <0.05), toh bolte ho "yeh luck se nahi ho sakta", aur H0 ko reject kar dete ho.
Sabse common galti yeh hai ki students sochte hain p-value ka matlab "H0 sach hone ki probability" hai — yeh galat hai. p-value hai P(data∣H0), ulta nahi. Aur ek aur trick: t-test mein z ki jagah t isliye use karte hain kyunki hum σ ko sample se estimate (s) karte hain, jisse thodi extra uncertainty aati hai. Standard error mein n se divide karte hain kyunki average lene se noise kam hota hai. Yeh module DS, ML, aur research papers — har jagah kaam aata hai, isliye iski feel banana zaroori hai.