सिम्युलेटेड और ऐतिहासिक डेटा की तुलना
एक अच्छी simulation के नतीजे ऐतिहासिक डेटा से मिलते-जुलते होने चाहिए। क्या वीडियो में की गई simulation के लिए यह सच था? इस अभ्यास में, आप simulation के नतीजों की जाँच करने का एक तरीका आज़माएँगे और पता लगाएंगे!
सबसे पहले, आप multivariate normal distribution और dia के mean और covariance matrix का उपयोग करके एक simulation चलाएँगे। फिर, आप ऐतिहासिक और सिम्युलेटेड—दोनों डेटा के means जाँचेंगे। क्या वे एक जैसे हैं?
Diabetes डेटासेट एक DataFrame dia के रूप में लोड किया गया है, और ये लाइब्रेरी आपके लिए इम्पोर्ट की गई हैं: pandas as pd, numpy as np, और scipy.stats as st.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Monte Carlo Simulations
अभ्यास निर्देश
diaके mean और covariance matrix का उपयोग करते हुए multivariate normal distribution से 10,000 बार simulation करें।- pandas की
.mean()फंक्शन का इस्तेमाल करके ऐतिहासिक डेटासेटdiaकीbmiऔरtcकॉलम्स के mean वैल्यू निकालिए, औरdf_resultsसे सिम्युलेटेडbmiऔरtcके mean निकालकर देखें कि वे कितने मिलते-जुलते हैं। - इसी तरह, pandas की
.cov()का उपयोग करकेdiaकीbmiऔरtcकॉलम्स तथाdf_resultsसे सिम्युलेटेडbmiऔरtcके लिए covariance matrix निकालें, ताकि आकलन कर सकें कि वे समान हैं या नहीं.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
cov_dia = dia[["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"]].cov()
mean_dia = dia[["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"]].mean()
# Complete the code to perform the simulation
simulation_results = st.multivariate_normal.rvs(____)
df_results = pd.DataFrame(simulation_results,columns=["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"])
# Calculate bmi and tc means for the historical and simulated results
print(dia[["bmi","tc"]].____)
print(____)
# Calculate bmi and tc covariances for the historical and simulated results
print(____)
print(____)