You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
581 lines
32 KiB
581 lines
32 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Introduction to Probability and Statistics\n",
|
|
"ဒီ notebook မှာ ကျွန်ုပ်တို့ ယခင်က ဆွေးနွေးခဲ့သော အတော်များများ အကြောင်းအရာတွေကို စမ်းသပ်ဖော်ပြရမယ်။ Probability နှင့် statistics တွင် အသုံးပြုကြတဲ့ အဓိက concepts များကို Python ၏ data processing အတွက် အသုံးဝင်သော `numpy` နှင့် `pandas` စတဲ့ library များထဲမှာ ကောင်းစွာ ကိုယ်စားပြုထားပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"import pandas as pd\n",
|
|
"import random\n",
|
|
"import matplotlib.pyplot as plt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Random Variables and Distributions\n",
|
|
"0 မှ 9 အထိ တညီတညွတ်ဖြန့်ဝေမှုမှ တန်ဖိုး 30 ခုထွက်ယူကြစို့။ ကြောင်းနှင့် အလွန်အကျွံကိုလည်းတွက်ချက်မယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"sample = [ random.randint(0,10) for _ in range(30) ]\n",
|
|
"print(f\"Sample: {sample}\")\n",
|
|
"print(f\"Mean = {np.mean(sample)}\")\n",
|
|
"print(f\"Variance = {np.var(sample)}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"နမူနာထဲမှာ မတူတဲ့ တန်ဖိုးများ ဘယ်နှစ်ခု ရှိနိုင်တယ်ဆိုတာကို မြင်မြင်ကွင်းကွင်း ခန့်မှန်းဖို့၊ **ဟစ္စ်တိုဂရမ်** ကို ပုံဆွဲနိုင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.hist(sample)\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## တကယ့်ဒေတာကို စိစစ်ခြင်း\n",
|
|
"\n",
|
|
"အမှန်တကယ်ရှိသော ဒေတာကို စိစစ်ရာတွင် ပျမ်းမျှတန်ဖိုးနှင့် ကွာဟမှုသည် အလွန်အရေးပါတ်သည်။ [SOCR MLB Height/Weight Data](http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_MLB_HeightsWeights) မှ ဘေ့စ်ဘောကစားသမားများဆိုင်ရာ ဒေတာကို ထည့်သွင်းကြည့်လိုက်ပါစို့။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = pd.read_csv(\"../../data/SOCR_MLB.tsv\",sep='\\t', header=None, names=['Name','Team','Role','Weight','Height','Age'])\n",
|
|
"df\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"> ဤနေရာတွင် ဒေတာ phân tích အတွက် [**Pandas**](https://pandas.pydata.org/) ဟုခေါ်သော package ကို အသုံးပြုနေပါသည်။ ဤသင်ကြားမှုပိုင်းတွင် Python ဖြင့် Pandas နှင့် ဒေတာနှင့်ဆက်စပ်၍ ပိုမိုဆွေးနွေးသွားမည်ဖြစ်သည်။\n",
|
|
"\n",
|
|
"အသက်၊ အရွယ်အစားနှင့် အလေးချိန်တို့အတွက် ပျမ်းမျှတန်ဖိုးများကိုတွက်ချက်ကြပါစို့-\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df[['Age','Height','Weight']].mean()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ယခု ကျွန်ုပ်တို့ စိတ်ဝင်စားရမည့်အချက်မှာ အမြင့်ဖြစ်ပြီး၊ စံချိန်လွှာနှင့် အနည်းငယ်ကြောင်းကိုတွက်ချက်ကြမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(list(df['Height'])[:20])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mean = df['Height'].mean()\n",
|
|
"var = df['Height'].var()\n",
|
|
"std = df['Height'].std()\n",
|
|
"print(f\"Mean = {mean}\\nVariance = {var}\\nStandard Deviation = {std}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"အလယ်ချိန်ထက် ပိုမိုတရားဝင်သည်မှာ အလယ်တန်းတန်ဖိုးနှင့် ခွဲခြားချက်များကိုလည်း ကြည့်ရှုသင့်သည်။ ၎င်းတို့ကို **box plot** ကို အသုံးပြု၍ မြင်ကွင်းဖော်ပြနိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,2))\n",
|
|
"plt.boxplot(df['Height'].ffill(), vert=False, showmeans=True)\n",
|
|
"plt.grid(color='gray', linestyle='dotted')\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ကျွန်ုပ်တို့၏ ဒေတာစုစည်းမှု၏ အပိုင်းအစများမှ ဥပမာအားဖြင့် ကစားသမား အခန်းကဏ္ဍအလိုက် အုပ်စုဖွဲ့ထားသော ဘူးကွက်ပုံများကိုလည်း ဖန်တီးနိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df.boxplot(column='Height', by='Role', figsize=(10,8))\n",
|
|
"plt.xticks(rotation='vertical')\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"> **မှတ်ချက်**: ဒီဇယားက ပုံမှန်အားဖြင့် ပထမသူကစားသမားများရဲ့ အမြင့်တွေက ဒုတိယသူကစားသမားများရဲ့ အမြင့်တွေထက် ပိုမြင့်နေလို့ ဖြစ်ပါတယ်ဆိုတာကို ပြထားပါတယ်။ နောက်ပိုင်းမှာ ဒီထင်မြင်ချက်ကို ပိုတိကျစွာ စမ်းသပ်နည်းနဲ့ ဒီအချက်အလက်တွေက စာရင်းဇယားအနေနဲ့ အရေးပါတဲ့ ဒေတာဆိုတာ ဘယ်လိုသက်သေပြနိုင်ကြောင်း ကို သင်ယူကြမယ်။ \n",
|
|
"\n",
|
|
"အရွယ်အစား၊ အမြင့်နဲ့ အလေးချိန်တွေက အဆက်မပြတ် ဖြစ်နိုင်တဲ့ အလိုအလျောက်ပြောင်းလဲသည့် အမျိုးအစားဖြစ်ပါတယ်။ ဒါတို့ရဲ့ ဖြန့်ချိမှုကို သင်ဘာတွေးပါသလဲ? တန်ဖိုးတွေကို ရေနွှမ်းစားပုံဖေါ်ခြင်း (histogram) ရေးဆွဲဖော်ပြတာက ရှာဖွေသိရှိဖို့ အကောင်းဆုံးနည်းလမ်းတစ်ခုဖြစ်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df['Weight'].hist(bins=15, figsize=(10,6))\n",
|
|
"plt.suptitle('Weight distribution of MLB Players')\n",
|
|
"plt.xlabel('Weight')\n",
|
|
"plt.ylabel('Count')\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Normal Distribution\n",
|
|
"\n",
|
|
"ကျွန်ုပ်တို့၏ အမှန်တကယ်ဒေတာနှင့် တူညီသော အရွယ်အစားရေတွက်နှင့် ရေရှည်လျော့နည်းမှုကို လိုက်နာသည့် ပုံမှန်ဖြန့်ဝေမှုတစ်ခုအတိုင်း အတုတစ်ခုကို ဖန်တီးကြစို့။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"generated = np.random.normal(mean, std, 1000)\n",
|
|
"generated[:20]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.hist(generated, bins=15)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.hist(np.random.normal(0,1,50000), bins=300)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"အမှန်တကယ်ဘဝမှာ တန်ဖိုးအများစုဟာ ပုံမှန်ဖြန့်ဖြူးထားတာဖြစ်လို့ နမူနာဒေတာတွေထုတ်ဖို့မှာ တူညီတန်ဖိုး ရှိတဲ့ ကျပန်းရှေ့ဆက်ဂျင်နရေးတာကို သုံးခွင့်မရှိပါဘူး။ uniform distribution ကိုသုံးပြီး အလေးချိန်တွေကို ထုတ်ဖို့ ကြိုးစားရင် (np.random.rand နဲ့ ထုတ်ထားတာ) ဖြစ်တာက ဒီလိုဖြစ်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"wrong_sample = np.random.rand(1000)*2*std+mean-std\n",
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.hist(wrong_sample)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ယုံကြည်မှု အကြားကွာဟမှုများ\n",
|
|
"\n",
|
|
"အခုတော့ ဘေ့စ်ဘောကစားသမားများ၏ အလေးချိန်နှင့် အမြင့်အတွက် ယုံကြည်မှု အကြားကွာဟမှုများကိုတွက်ချက်ကြမည်။ ကျွန်ုပ်တို့သည် [ဒီ stackoverflow ဆွေးနွေးချက်မှ](https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data) ကိုဒ်ကိုအသုံးပြုမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import scipy.stats\n",
|
|
"\n",
|
|
"def mean_confidence_interval(data, confidence=0.95):\n",
|
|
" a = 1.0 * np.array(data)\n",
|
|
" n = len(a)\n",
|
|
" m, se = np.mean(a), scipy.stats.sem(a)\n",
|
|
" h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1)\n",
|
|
" return m, h\n",
|
|
"\n",
|
|
"for p in [0.85, 0.9, 0.95]:\n",
|
|
" m, h = mean_confidence_interval(df['Weight'].fillna(method='pad'),p)\n",
|
|
" print(f\"p={p:.2f}, mean = {m:.2f} ± {h:.2f}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Hypothesis Testing\n",
|
|
"\n",
|
|
"ကျွန်ုပ်တို့၏ဘေ့စ်ဘောကစားသူများဒေတာသိုက်တွင် သုံးဆောင်သော တာဝန်များကို ရှာဖွေကြမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df.groupby('Role').agg({ 'Weight' : 'mean', 'Height' : 'mean', 'Age' : 'count'}).rename(columns={ 'Age' : 'Count'})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ပထမဦးဆုံး ဘေ့စ်မန်များသည် ဒုတိယဦးဆုံး ဘေ့စ်မန်များထက် ပိုရှည်လျားကြောင်း အယူအဆကို စမ်းသပ်ကြည့်ပါစို့။ ဤအယူအဆကို စစ်ဆေးရန် အလွယ်တကူနည်းလမ်းမှာ ယုံကြည်စိတ်ချမှုအကြောင်းအရာများကို စစ်ဆေးခြင်းဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for p in [0.85,0.9,0.95]:\n",
|
|
" m1, h1 = mean_confidence_interval(df.loc[df['Role']=='First_Baseman',['Height']],p)\n",
|
|
" m2, h2 = mean_confidence_interval(df.loc[df['Role']=='Second_Baseman',['Height']],p)\n",
|
|
" print(f'Conf={p:.2f}, 1st basemen height: {m1-h1[0]:.2f}..{m1+h1[0]:.2f}, 2nd basemen height: {m2-h2[0]:.2f}..{m2+h2[0]:.2f}')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"အစီအစဉ်များသည် ထပ်တွဲမှုမရှိကြောင်း တွေ့မြင်ရပါသည်။\n",
|
|
"\n",
|
|
"သရုပ်ပြချက်ကို ပိုမိုမှန်ကန်စွာ သက်သေပြရန် အဆင့်မြင့် ထုတ်ပြန်မှုမှာ **Student t-test** ကို အသုံးပြုခြင်းဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from scipy.stats import ttest_ind\n",
|
|
"\n",
|
|
"tval, pval = ttest_ind(df.loc[df['Role']=='First_Baseman',['Height']], df.loc[df['Role']=='Second_Baseman',['Height']],equal_var=False)\n",
|
|
"print(f\"T-value = {tval[0]:.2f}\\nP-value: {pval[0]}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"`ttest_ind` function က ပြန်လာတဲ့ တန်ဖိုး နှစ်ခုကတော့ -\n",
|
|
"* p-value က နှစ်ခုရဲ့ distribution တူညီတဲ့ mean တန်ဖိုးကြားရှိနိုင်မှု ရာခိုင်နှုန်းအနေနဲ့ယူဆနိုင်ပါတယ်။ ကျွန်တော်တို့မှာတော့ ကျယ်လွန်တဲ့ အထောက်အထားတွေ ရှိတယ်ဆိုတာကို ရှင်းပြတာပါ၊ ဒါကြောင့် ပထမဆုံး baseman တွေဟာ ပိုပြီးပါးစပ်ကြီးတယ်လို့ ဆိုနိုင်ပါတယ်။\n",
|
|
"* t-value က t-test တွင် အသုံးပြုတဲ့ normalized mean difference ရဲ့ အလယ်အလတ်တန်ဖိုးဖြစ်ပြီး အဆိုပါ confidence value အတွက် သတ်မှတ်ထားတဲ့ နံပါတ်တန်ဖိုးနဲ့ နှိုင်းယှဉ်ကြည့်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Central Limit Theorem ဖြင့် ပုံမှန်ဖြန့်ဝေမှုကို နမူနာဖန်တီးခြင်း\n",
|
|
"\n",
|
|
"Python မှာ pseudo-random generator ကို uniform distribution ပေးဖို့ ဒီဇိုင်းလုပ်ထားပါတယ်။ ပုံမှန်ဖြန့်ဝေမှုအတွက် generator ဖန်တီးချင်ရင်၊ central limit theorem ကို အသုံးပြုနိုင်ပါတယ်။ ပုံမှန်ဖြန့်ဝေမှုတန်ဖိုးကို ရဖို့ uniform-generated နမူနာတစ်ခုရဲ့ အလယ်တန်းကိုတွက်ချက်ပေးရမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def normal_random(sample_size=100):\n",
|
|
" sample = [random.uniform(0,1) for _ in range(sample_size) ]\n",
|
|
" return sum(sample)/sample_size\n",
|
|
"\n",
|
|
"sample = [normal_random() for _ in range(100)]\n",
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.hist(sample)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ဆက်စပ်မှုနှင့် မကောင်းသော ဘေ့စ်ဘော ကော်ပိုရေးရှင်း\n",
|
|
"\n",
|
|
"ဆက်စပ်မှုသည် ဒေတာအစဉ်များအကြား ဆက်နွယ်မှုများကို ရှာဖွေရန် အခွင့်အလမ်းပေးသည်။ ကျွန်ုပ်တို့၏ ကစားစက်ဥပမာတွင် မကောင်းသော ဘေ့စ်ဘော ကော်ပိုရေးရှင်းတစ်ခုရှိပြီး ၎င်းသည် ကစားသမားများဆီကို အမြင့်အလိုက် လစာပေးနေသည်ဟု သဘောထားကြရအောင် - ကစားသမားမှာ မြင့်မားသမျှ အပိုငွေများကို ရရှိမည်။ မူလလစာ $1000 ရှိပြီး၊ အမြင့်ပမာဏအပေါ်မူတည်၍ $0 မှ $100 အထိ အပိုအားသာငွေ ရရှိနိုင်သည် ဟု သတ်မှတ်ကြသည်။ ကျွန်ုပ်တို့ MLB မှ တကယ့်ကစားသမားများကို ယူပြီး သူတို့၏ ဟောင်းသော လစာများကိုတွက်မည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"heights = df['Height'].fillna(method='pad')\n",
|
|
"salaries = 1000+(heights-heights.min())/(heights.max()-heights.mean())*100\n",
|
|
"print(list(zip(heights, salaries))[:10])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ယခုဆိုရင် ဤအဆက်စပ်များ၏ ကိုဗားရီးယားနှင့် ကိုယ်စားပြုချက်အား တွက်ချက်ကြမည်။ `np.cov` သည် ကျွန်ုပ်တို့အား အဆိုပါ **ကိုဗားရီးယား မက်ထရစ်စ်** ကို ပေးမည်ဖြစ်ပြီး၊ ၎င်းမှာ များပြားသော မည့်သည့် ပြောင်းလဲမှုများအတွက် ကိုဗားရီးယား၏ ဖြည်းဖြည်းချင်း စွဲသုံးမှုတစ်ခုဖြစ်ပါသည်။ ကိုဗားရီးယား မက်ထရစ်စ် $M$ ၏ အတိုင်းအတာ $M_{ij}$ သည် ထည့်သွင်းမည့် ပြောင်းလဲမှုများ $X_i$ နှင့် $X_j$ တို့အကြား ကိုယ်စားပြုချက်ဖြစ်ပြီး၊ ကွက်တိပေါ်ရှိ တန်ဖိုးများ $M_{ii}$ သည် $X_{i}$ ၏ မတည်ငြိမ်မှုဖြစ်သည်။ သဘောတူညီ၍ `np.corrcoef` သည် ကျွန်ုပ်တို့အား **ကိုယ်စားပြုချက် မက်ထရစ်စ်** ကို ပေးမည်ဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(f\"Covariance matrix:\\n{np.cov(heights, salaries)}\")\n",
|
|
"print(f\"Covariance = {np.cov(heights, salaries)[0,1]}\")\n",
|
|
"print(f\"Correlation = {np.corrcoef(heights, salaries)[0,1]}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ကိုယ်စားပြုတန်ဖိုး 1 နှင့်တူညီသည်ဆိုသည်မှာ အမျိုးအစားနှစ်ခုအကြား ပြင်းထန်သော **လိုင်နာဆက်စပ်မှု** ရှိသည်ကို ဆိုလိုသည်။ တန်ဖိုးတစ်ခုအား တစ်ခုကို အဆင့်လိုက်ထိုးပြခြင်းဖြင့် လိုင်းဆက်စပ်မှုကို ကိုယ်ရည်အသိပိုင်းဖြင့် တွေ့မြင်နိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.scatter(heights,salaries)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"အဆက်အဆံမျိုးသည် လိုင်းနစ်မဟုတ်ပါက ဘာတွေဖြစ်မလဲဆိုတာ ကြည့်ကြရအောင်။ ကျွန်ုပ်တို့၏ကုမ္ပဏီသည် အမြင့်နှင့် လစာအကြား ရိုးရှင်းသော လိုင်းနစ်ဆက်နှင့်မှုကို ဖုံးကွယ်ရန်ဆုံးဖြတ်ခဲ့ပြီး၊ `sin` ကဲ့သို့သော အမျိုးအစား မလိုင်းနစ်မျိုးကို ဖော်မြူလာထဲသို့ ထည့်သွင်းခဲ့သည်ဟု ယူဆပါစို့။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"salaries = 1000+np.sin((heights-heights.min())/(heights.max()-heights.mean()))*100\n",
|
|
"print(f\"Correlation = {np.corrcoef(heights, salaries)[0,1]}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ဒီအခါမှာ ဆက်စပ်မှုက စာနည်းနည်းသာ လျော့နည်းနေတာ ဖြစ်ပေမယ့် အရမ်းမြင့်မားနေဆဲ ဖြစ်ပါတယ်။ အခုတော့ ဆက်စပ်မှုကို နည်းနည်း မသေချာအောင်လုပ်ဖို့ အလုပ်ခကို စိတ်ကူးမဲ့ အမျိုးအစားတစ်ခု ထည့်ပြီး အလှည့်အပြောင်း ပိုမိုတွေ့လာစေချင်တယ်။ ဘာဖြစ်လာမလဲ ကြည့်ကြရအောင်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"salaries = 1000+np.sin((heights-heights.min())/(heights.max()-heights.mean()))*100+np.random.random(size=len(heights))*20-10\n",
|
|
"print(f\"Correlation = {np.corrcoef(heights, salaries)[0,1]}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.scatter(heights, salaries)\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"> အကြောင်းမှာ အမှတ်လေးတွေက ဒီလို ထောင့်စောင်းလိုက်တယ်ဆိုတာ ကို နှုတ်ဆက်မtightရနိုင်လား?\n",
|
|
"\n",
|
|
"ကျွန်ုပ်တို့သည် လစာကဲ့သို့ အသုံးပြုမှုဖြင့် ထိန်းချုပ်ထားသောအကြောင်းအရာနှင့် ကြည့်ရှုသောအခြေအနေ* အမြင့်* ၏တွဲဖက်မှုကို တွေ့ရှိခဲ့ပြီးဖြစ်သည်။ ထို့အပြင်၊ အမြင့်နှင့် ဝန်အားကဲ့သို့ ကြည့်ရှုသောအခြေအနေ နှစ်ခုလုံးအကြားလည်း တွဲဖက်မှုရှိမရှိကိုကြည့်လိုက်ကြပါစို့။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"np.corrcoef(df['Height'].ffill(),df['Weight'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"ကံမကောင်းစွာဖြင့် ကျွန်ုပ်တို့ အရာများအတွက် ရလဒ် မရရှိကြပါဘူး - အတိုင်းအတာ `nan` အနည်းငယ်သာ ရှိနေပါတယ်။ ၎င်းမှာဖြစ်ရခြင်းမှာ ကျွန်ုပ်တို့၏ series အချို့၏ တန်ဖိုးများသည် အမည်မသိဖြစ်၍ `nan` အဖြစ် ဖော်ပြထားသလို ဖြစ်သည်၊ ၎င်းကြောင့် အလုပ်လုပ်ပုံရလဒ်လည်း အမည်မသိ ဖြစ်နေသည်။ matrix ကို ကြည့်မယ်ဆိုရင် `Weight` ကန့်သတ်သော ကော်လံဖြစ်ကာ၊ `Height` တန်ဖိုးများအကြား ကိုယ်တိုင် အချိုးအစားချက်ကို တွက်ချက်ပြီးဖြစ်သည်ကို မြင်ရသည်။\n",
|
|
"\n",
|
|
"> ဤနမူနာသည် **ဒေတာပြင်ဆင်ခြင်း** နှင့် **ရှင်းလင်းခြင်း** ၏ အရေးကြီးမှုကို ပြသသည်။ သင့်တော်သော ဒေတာ မရှိဘဲနဲ့ ကိစ္စရာ များကို တွက်ချက်၍ မရနိုင်ပါ။\n",
|
|
"\n",
|
|
"`fillna` နည်းလမ်းကို အသုံးပြု၍ လိုအပ်သော တန်ဖိုးများကို ဖြည့်ပြီး အချိုးအစားချက်ကို တွက်ချက်ကြမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"np.corrcoef(df['Height'].fillna(method='pad'), df['Weight'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"တကယ်တော့ ဆက်စပ်မှုတစ်ခုရှိပါသည်၊ သို့သော် ကျွန်ုပ်တို့လုပ်ဆောင်ထားသော လူမှုရိုက်ထွဲထားသော ဥပမာကဲ့သို့ ပြင်းထန်မှု မရှိပါ။ တကယ်လို့ တန်ဖိုးတစ်ဖက်ကို တစ်ဖက်နှင့် ဆက်စပ်မှုရှိမှုကို scatter plot မှ ဖြတ်သွားကြည့်ပါက၊ ဆက်စပ်မှုမှာ ပိုသေးငယ်ပြီး မမြင်သာနိုင်ပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(10,6))\n",
|
|
"plt.scatter(df['Weight'],df['Height'])\n",
|
|
"plt.xlabel('Weight')\n",
|
|
"plt.ylabel('Height')\n",
|
|
"plt.tight_layout()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## နိဂုံးချုပ်\n",
|
|
"\n",
|
|
"ဤ notebook တွင် ဒေတာပေါ်တွင် အခြေခံအလုပ်ဆောင်မှုများကို စာရင်းပြုလုပ်ကာ သင်္ချာနဲ့ စာရင်းဆိုင်ရာ ဖွင့်ဆိုချက်များကို တွက်ချက်နိုင်ရန် သင်ကြားခဲ့ရသည်။ ကျွန်ုပ်တို့တွင် သင်္ချာနည်းပညာနှင့် စာရင်းဆိုင်ရာနည်းလမ်းများကို အသုံးပြု၍ အယူအဆတချို့ကို သက်သေပြရန်နှင့် ဒေတာနမူနာအား အခြေခံကာ ပြောင်းလဲနိုင်သော အလားအလာဆိုင်ရာ များအတွက် ယုံကြည်မှု အကွာအဝေးများကို တွက်ချက်နည်းကို လည်း ယခုသိရှိလာခဲ့ပါပြီ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"---\n\n<!-- CO-OP TRANSLATOR DISCLAIMER START -->\n**သတိပေးချက်** \nဤစာရွက်စာတမ်းကို AI ဘာသာပြန်ဝန်ဆောင်မှုဖြစ်သော [Co-op Translator](https://github.com/Azure/co-op-translator) ဖြင့် ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှန်ကန်မှုအတွက် ကြိုးပမ်းသော်လည်း၊ အလိုအလျောက် ဘာသာပြန်ခြင်းတွင် အမှားများ သို့မဟုတ် မှန်ကန်မှုမရှိမှုများ ဖြစ်ပေါ်နိုင်ကြောင်း သတိပြုပါရန် ဖိတ်ခေါ်ပါသည်။ မူလစာရွက်စာတမ်းကို မိခင်ဘာသာဖြင့်သာ ယုံကြည်စိတ်ချရသော အရင်းအမြစ်အဖြစ် ထင်ရှားစွာ သတ်မှတ်ရမည်ဖြစ်သည်။ အရေးကြီးသော အချက်အလက်များအတွက် အသက်မွေး၀မ်းကြောင်းအတတ်ပညာရှင်များ၏ လူသားဘာသာပြန်ခြင်းကို အကြံပြုပါသည်။ ဤဘာသာပြန်ချက်ကို အသုံးပြုရာတွင် ဖြစ်ပေါ်လာသော နားလည်မှားယွင်းမှုများ သို့မဟုတ် မှားယွင်းဖော်ပြချက်များအတွက် ကျွန်ုပ်တို့သည် တာဝန်ယူလျက်မရှိပါ။\n<!-- CO-OP TRANSLATOR DISCLAIMER END -->\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"interpreter": {
|
|
"hash": "86193a1ab0ba47eac1c69c1756090baa3b420b3eea7d4aafab8b85f8b312f0c5"
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.6"
|
|
},
|
|
"coopTranslator": {
|
|
"original_hash": "0f899e3c5019f948e7c787b22f3b2304",
|
|
"translation_date": "2026-01-16T21:23:35+00:00",
|
|
"source_file": "1-Introduction/04-stats-and-probability/notebook.ipynb",
|
|
"language_code": "my"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
} |