diff --git "a/n122a_chi_square_test_ipynb\354\235\230_\354\202\254\353\263\270.ipynb" "b/n122a_chi_square_test_ipynb\354\235\230_\354\202\254\353\263\270.ipynb" new file mode 100644 index 00000000000..76d4e268859 --- /dev/null +++ "b/n122a_chi_square_test_ipynb\354\235\230_\354\202\254\353\263\270.ipynb" @@ -0,0 +1,812 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rQf3dSuc5PqO" + }, + "source": [ + "\n", + "\n", + "## *DATA SCIENCE / SECTION 1 / SPRINT 2 / NOTE 2*\n", + "\n", + "# ๐Ÿ“ Assignment" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Hyx0GzLpzSzM" + }, + "source": [ + "# ์นด์ด์ œ๊ณฑ๊ฒ€์ •" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "11OzdxWTM7UR" + }, + "source": [ + "\n", + "## 1. ๊ณต๊ณต๋ฐ์ดํ„ฐ ์กฐ์ž‘ ์—ฐ์Šต. \n", + "\n", + "๊ตญ๊ฐ€ ํ†ต๊ณ„ ํฌํ„ธ์—์„œ ์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•˜์—ฌ\n", + "\n", + "\n", + "\n", + "**2020๋…„ 8์›”**์— ํ•ด๋‹นํ•˜๋Š” ๊ทœ๋ชจ๋ณ„ ๋ฏธ๋ถ„์–‘ํ˜„ํ™ฉ ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ์…‹์„ ์ƒ์„ฑํ•˜์„ธ์š”. \n", + "\n", + "\n", + "\n", + "- `60m์ดํ•˜`, `60~85m`, `85m์ดˆ๊ณผ`์˜ 3๊ฐœ ๊ทœ๋ชจ์™€ (column)\n", + "- `์„œ์šธ`, `๋Œ€์ „`, `๋Œ€๊ตฌ`, `๋ถ€์‚ฐ` 4๊ฐœ์˜ ์ง€์—ญ์„ ํฌํ•จํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. (row)\n", + "- `๋ฏผ๊ฐ„๋ถ€๋ฌธ`๋งŒ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค\n", + "- ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ๋Š” 0์œผ๋กœ ์ฒ˜๋ฆฌํ•˜์„ธ์š”.\n", + "\n", + "์ดํ›„ ๋ฐ์ดํ„ฐ์…‹์„ colab์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค์„ธ์š”. ์ด๋•Œ ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์€ `df`๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.\n" + ] + }, + { + "cell_type": "code", + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "metadata": { + "id": "L2QoMckd3qY3", + "outputId": "253c85f6-7fc6-4c10-c079-0305f171c10b", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from google.colab import files\n", + "\n", + "uploaded = files.upload()" + ], + "metadata": { + "colab": { + "resources": { + "http://localhost:8080/nbextensions/google.colab/files.js": { + "data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy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Hx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK", + "ok": true, + "headers": [ + [ + "content-type", + "application/javascript" + ] + ], + "status": 200, + "status_text": "" + } + }, + "base_uri": "https://localhost:8080/", + "height": 77 + }, + "id": "7736lBMe67rM", + "outputId": "5475863c-9e19-4287-ab86-ffe267af3a5c" + }, + "execution_count": 13, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " Upload widget is only available when the cell has been executed in the\n", + " current browser session. Please rerun this cell to enable.\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {} + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Saving ๊ทœ๋ชจ๋ณ„_๋ฏธ๋ถ„์–‘ํ˜„ํ™ฉ_20220126143907.csv to ๊ทœ๋ชจ๋ณ„_๋ฏธ๋ถ„์–‘ํ˜„ํ™ฉ_20220126143907 (1).csv\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import io\n", + "import pandas as pd\n", + "\n", + "df = pd.read_csv('๊ทœ๋ชจ๋ณ„_๋ฏธ๋ถ„์–‘ํ˜„ํ™ฉ_20220126143907.csv',encoding='cp949')\n", + "df.drop('๋ถ€๋ฌธ(1)',axis=1,inplace=True)\n", + "df" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + }, + "id": "I8loEPDY7KX4", + "outputId": "ab49d3f5-e642-457b-f26a-8e26ce70bc8f" + }, + "execution_count": 21, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
์‹œ๋„(1)๊ทœ๋ชจ(1)2020. 08
0์„œ์šธ60ใŽก์ดํ•˜54
1์„œ์šธ60โˆผ85ใŽก2
2์„œ์šธ85ใŽก์ดˆ๊ณผ0
3๋ถ€์‚ฐ60ใŽก์ดํ•˜577
4๋ถ€์‚ฐ60โˆผ85ใŽก735
5๋ถ€์‚ฐ85ใŽก์ดˆ๊ณผ142
6๋Œ€๊ตฌ60ใŽก์ดํ•˜143
7๋Œ€๊ตฌ60โˆผ85ใŽก1437
8๋Œ€๊ตฌ85ใŽก์ดˆ๊ณผ44
9๋Œ€์ „60ใŽก์ดํ•˜782
10๋Œ€์ „60โˆผ85ใŽก1
11๋Œ€์ „85ใŽก์ดˆ๊ณผ0
\n", + "
\n", + " \n", + " \n", + " \n", + "\n", + " \n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + " ์‹œ๋„(1) ๊ทœ๋ชจ(1) 2020. 08\n", + "0 ์„œ์šธ 60ใŽก์ดํ•˜ 54\n", + "1 ์„œ์šธ 60โˆผ85ใŽก 2\n", + "2 ์„œ์šธ 85ใŽก์ดˆ๊ณผ 0\n", + "3 ๋ถ€์‚ฐ 60ใŽก์ดํ•˜ 577\n", + "4 ๋ถ€์‚ฐ 60โˆผ85ใŽก 735\n", + "5 ๋ถ€์‚ฐ 85ใŽก์ดˆ๊ณผ 142\n", + "6 ๋Œ€๊ตฌ 60ใŽก์ดํ•˜ 143\n", + "7 ๋Œ€๊ตฌ 60โˆผ85ใŽก 1437\n", + "8 ๋Œ€๊ตฌ 85ใŽก์ดˆ๊ณผ 44\n", + "9 ๋Œ€์ „ 60ใŽก์ดํ•˜ 782\n", + "10 ๋Œ€์ „ 60โˆผ85ใŽก 1\n", + "11 ๋Œ€์ „ 85ใŽก์ดˆ๊ณผ 0" + ] + }, + "metadata": {}, + "execution_count": 21 + } + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "id": "IhWdLFndyVAB", + "outputId": "96ff3ba0-800c-4aef-86b0-378cacc90751", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
๊ทœ๋ชจ(1)60โˆผ85ใŽก60ใŽก์ดํ•˜85ใŽก์ดˆ๊ณผ
์‹œ๋„(1)
๋Œ€๊ตฌ143714344
๋Œ€์ „17820
๋ถ€์‚ฐ735577142
์„œ์šธ2540
\n", + "
\n", + " \n", + " \n", + " \n", + "\n", + " \n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "๊ทœ๋ชจ(1) 60โˆผ85ใŽก 60ใŽก์ดํ•˜ 85ใŽก์ดˆ๊ณผ\n", + "์‹œ๋„(1) \n", + "๋Œ€๊ตฌ 1437 143 44\n", + "๋Œ€์ „ 1 782 0\n", + "๋ถ€์‚ฐ 735 577 142\n", + "์„œ์šธ 2 54 0" + ] + }, + "metadata": {}, + "execution_count": 28 + } + ], + "source": [ + "col = ['~60m2', '60~85m2', '85m2~']\n", + "row = ['์„œ์šธ', '๋Œ€์ „', '๋Œ€๊ตฌ', '๋ถ€์‚ฐ']\n", + "value = list(df.iloc[:,2])\n", + "df = df.pivot(index='์‹œ๋„(1)',columns='๊ทœ๋ชจ(1)',values='2020. 08')\n", + "df\n", + "# ์ธ๋ฑ์Šค ์ˆœ์„œ ์–ด๋–ป๊ฒŒ ๋ฐ”๊ฟ€๊นŒ?\n", + "# df.columns = col\n", + "# df = df.reindex(row)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RXPZZuAi3ccI" + }, + "source": [ + "## 2. ์ง€์—ญ์— ๋Œ€ํ•ด์„œ one-sample chi-square test๋ฅผ ์‹คํ–‰, ํ•ด๋‹น ๊ฒฐ๊ณผ๋ฅผ `chi1`์— ์ €์žฅ ํ›„ ์„ค๋ช…ํ•ด๋ณด์„ธ์š”.\n", + "\n", + "์˜ˆ์‹œ) ๋งŒ์•ฝ **9์›”๋‹ฌ ๋ฐ์ดํ„ฐ**๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹ค๋ฉด\n", + "```python\n", + " [52+2+0, 590+665+142, 113+1061+42, 772+1+0]\n", + "```\n", + "์„ ๋น„๊ต ํ•˜๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "id": "oIMzAkXks-Sv", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "963dc637-4b2d-4164-b139-9d755cd01c2e" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "์‹œ๋„(1)\n", + "๋Œ€๊ตฌ 1624\n", + "๋Œ€์ „ 783\n", + "๋ถ€์‚ฐ 1454\n", + "์„œ์šธ 56\n", + "dtype: int64\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Power_divergenceResult(statistic=1564.4572376818994, pvalue=0.0)" + ] + }, + "metadata": {}, + "execution_count": 45 + } + ], + "source": [ + "from scipy.stats import chisquare\n", + "\n", + "\n", + "df_sum = df.sum(axis=1)\n", + "print(df_sum)\n", + "chi1 = chisquare(df_sum,axis=None)\n", + "chi1\n", + "# ์ง€์—ญ๋ณ„ ๋ฏธ๋ถ„์–‘ ์ˆ˜์— ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "eMDtugVNRu0q" + }, + "source": [ + "## 3. ์ง€์—ญ๊ณผ ๊ทœ๋ชจ์— ๋Œ€ํ•ด์„œ two-sample chi-square test๋ฅผ ์‹คํ–‰, ํ•ด๋‹น ๊ฒฐ๊ณผ๋ฅผ `chi2`์— ์ €์žฅ ํ›„ ์„ค๋ช…ํ•ด๋ณด์„ธ์š”.\n", + "\n", + "์˜ˆ์‹œ) **9์›”๋‹ฌ ๋ฐ์ดํ„ฐ**๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹ค๋ฉด\n", + "\n", + "| |-60 | 60-85 | 85- |\n", + "|:-:|:-:|:-:|:-:|\n", + "|์„œ์šธ|52|2|0|\n", + "|๋Œ€์ „|772|1|0|\n", + "|๋Œ€๊ตฌ|113|1061|42|\n", + "|๋ถ€์‚ฐ|590|665|142|\n", + "\n", + "์— ๋Œ€ํ•ด์„œ ๊ฒ€์ •ํ•ด์•ผ ํ•  ๊ฒ๋‹ˆ๋‹ค.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "id": "Ckcr4A4FM7cs", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "61ca60dc-91c8-49c6-ec09-bca3f6164f5b" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2064.5767314171994, 0.0, 6, array([[901.76155221, 645.12228746, 77.11616033],\n", + " [434.77789124, 311.04110288, 37.18100587],\n", + " [807.36533061, 577.59101353, 69.04365586],\n", + " [ 31.09522594, 22.24559612, 2.65917794]]))\n", + "------------------------------------------------------------------------------------------\n", + "(2064.5767314171994, 0.0, 6, array([[901.76155221, 645.12228746, 77.11616033],\n", + " [434.77789124, 311.04110288, 37.18100587],\n", + " [807.36533061, 577.59101353, 69.04365586],\n", + " [ 31.09522594, 22.24559612, 2.65917794]]))\n" + ] + } + ], + "source": [ + "from scipy.stats import chi2_contingency\n", + "\n", + "print(chi2_contingency(df))\n", + "print('---'*30)\n", + "print(chi2_contingency(df,correction = False))\n", + "\n", + "# ๊ฐ€์„ค\n", + "# H0 : ์ง€์—ญ๋ณ„ ๋ฏธ๋ถ„์–‘๊ฐ€๊ตฌ์˜ ์ˆ˜์™€ ๊ทœ๋ชจ์˜ ์ƒ๊ด€ ๊ด€๊ณ„(์ฐจ์ด)๊ฐ€ ์žˆ๋‹ค.\n", + "\n", + "# p-value ๊ฐ€ 0.0 ์ด๋ฏ€๋กœ H0 ๊ธฐ๊ฐ.\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Tf7XPpBP6YqX" + }, + "source": [ + "### 4. 2๋ฒˆ์— ๋Œ€ํ•ด์„œ NumPy ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ (Scipy๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ ) $\\chi^2$ test ์‹œํ–‰ ํ›„ 2๋ฒˆ์˜ ๊ฒฐ๊ณผ์™€ ๋น„๊ตํ•ด๋ณด์„ธ์š”. \n", + "\n", + "- `obs`, `exp`, `chi`๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค." + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "id": "OjFt0b1-wrFL", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "5acef72e-f7bc-44e3-ae87-42c46d0535fb" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "1564.4572376818994" + ] + }, + "metadata": {}, + "execution_count": 59 + } + ], + "source": [ + "# ์นด์ด์ œ๊ณฑ ๊ฒ€์ • : (์‹ค์ œ๊ฐ’-์˜ˆ์ธก๊ฐ’)^2/์˜ˆ์ธก๊ฐ’ ๋“ค์˜ ํ•ฉ\n", + "import numpy as np\n", + "\n", + "obs = df_sum\n", + "exp = np.mean(obs)\n", + "\n", + "squared = np.power(obs-exp,2)\n", + "chi = np.sum(squared/exp)\n", + "chi" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "a2BrKHq8m8AS" + }, + "source": [ + "## ๐Ÿ”ฅ ๋„์ „ ๊ณผ์ œ\n", + "\n", + "์•„๋ž˜ ์„ธ๊ฐ€์ง€๋ฅผ ๋‹คํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.\n", + "\n", + "### 1. Function\n", + "\n", + "4๋ฒˆ์—์„œ ์‚ฌ์šฉํ•œ one sample chisquare test๋ฅผ ํ•จ์ˆ˜์˜ ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝํ•˜์„ธ์š”." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "AntnuAkFm-JQ" + }, + "outputs": [], + "source": [ + "v1 = [18,22,20,15,23,22]\n", + "v2 = [5,23,26,19,24,23]\n", + "\n", + "def myChisq(value):\n", + " return None# ๋‚ด์šฉ์„ ์ฑ„์šฐ์„ธ์š”.\n", + "\n", + "myChisq(v1) \n", + "\n", + "# chisquare๊ฐ’๊ณผ pvalue๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.\n", + "\n", + "myChisq(v2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4ohsJhQUmEuS" + }, + "source": [ + "### 2. ANOVA\n", + "\n", + "์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•˜์—ฌ ANOVA ์— ๋Œ€ํ•œ ๊ธ€์„ ์ฝ๊ณ \n", + "\n", + "\n", + "\n", + "๋‹ค์Œ `4๊ฐœ ๊ทธ๋ฃน์— ๋Œ€ํ•ด์„œ ํ‰๊ท ์˜ ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€`์— ๋Œ€ํ•œ ๊ฐ€์„ค ๊ฒ€์ •์„ ์‹œํ–‰ํ•˜์„ธ์š”.\n", + "\n", + "A : `38 33 35 92 76 97 88 41 11 9`\n", + "\n", + "B : `18 52 62 48 30 40 87 12 97 82`\n", + "\n", + "C : `28 90 5 49 66 73 96 80 4 17`\n", + "\n", + "D : ` 8 99 4 12 7 64 18 10 9 20`\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "DMebi5_4UaSn" + }, + "outputs": [], + "source": [ + "# ์ด ๊ณณ์— ๋‹ต์•ˆ์„ ์ž‘์„ฑํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค" + ] + } + ], + "metadata": { + "colab": { + "name": "n122a-chi-square-test.ipynb์˜ ์‚ฌ๋ณธ", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file