Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[조예인] week9_2024_GDG_ML입문스터디 #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
20e8269
[조예인] week1_2024_GDG_ML입문스터디
yeverycode Sep 29, 2024
75c431c
[조예인] week2_2024_GDG_ML입문스터디
yeverycode Oct 5, 2024
92fb45c
[조예인] week2_2024_GDG_ML입문스터디
yeverycode Oct 5, 2024
758a0ac
[조예인] week2_2024_GDG_ML입문스터디
yeverycode Oct 5, 2024
6791036
Update README.md
yeverycode Oct 5, 2024
2364ead
Delete OneDrive/바탕 화면/github/ML/week2 directory
yeverycode Oct 5, 2024
d130b93
Delete [MLNovice]조예인_week2-1.ipynb
yeverycode Oct 5, 2024
5afaa7f
Delete [MLNovice]조예인_week2-2.ipynb
yeverycode Oct 5, 2024
8c3df20
Delete [MLNovice]조예인_week2-3.ipynb
yeverycode Oct 5, 2024
cd118b8
Delete [MLNovice]조예인_week2.pdf
yeverycode Oct 5, 2024
1f5a0ce
[조예인] week2_2024_GDG_ML입문스터디
yeverycode Oct 5, 2024
19539f1
[조예인] week3_2024_GDG_ML입문스터디
yeverycode Oct 12, 2024
7983202
[조예인] week4_2024_GDG_ML입문스터디
yeverycode Oct 28, 2024
35422fe
[조예인] week5_2024_GDG_ML입문스터디
yeverycode Nov 4, 2024
a52f622
[조예인] week6_2024_GDG_ML입문스터디
yeverycode Nov 10, 2024
44451b7
[조예인] week7_2024_GDG_ML입문스터디
yeverycode Nov 17, 2024
4faf551
[조예인] week8_2024_GDG_ML입문스터디
yeverycode Nov 26, 2024
061730e
[조예인] week9_2024_GDG_ML입문스터디
yeverycode Dec 1, 2024
2240393
[조예인] week9_2024_GDG_ML입문스터디
yeverycode Dec 1, 2024
d4173a7
Delete week9/[MLNovice]조예인_다양한 데이터를 가지고 집 값 예측해보기
yeverycode Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions week1/[MLNovice]조예인_week1-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week1/[MLNovice]조예인_week1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week2/[MLNovice]조예인_week2-1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week2/[MLNovice]조예인_week2-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week2/[MLNovice]조예인_week2-3.ipynb

Large diffs are not rendered by default.

Binary file added week2/[MLNovice]조예인_week2.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week3/[MLNovice]조예인_week3-1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week3/[MLNovice]조예인_week3-2.ipynb

Large diffs are not rendered by default.

Binary file added week3/[MLNovice]조예인_week3.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week4/[MLNovice]조예인_week4-1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week4/[MLNovice]조예인_week4-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week4/[MLNovice]조예인_week4-3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPUgi5jqCh/hYdCIXBtzPFS"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# 랜덤포레스트"],"metadata":{"id":"tC1gC_UpQLSI"}},{"cell_type":"markdown","source":["랜덤하게 선택한 샘플과 특성을 사용, 과대적합 방지"],"metadata":{"id":"A7lbQiqyQSY8"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","from sklearn.model_selection import train_test_split\n","\n","wine = pd.read_csv('https://bit.ly/wine_csv_data')\n","\n","data = wine[['alcohol', 'sugar', 'pH']].to_numpy()\n","target = wine['class'].to_numpy()\n","\n","train_input, test_input, train_target, test_target = train_test_split(data, target, test_size=0.2, random_state=42)"],"metadata":{"id":"37pYe1ZaQOjF","executionInfo":{"status":"ok","timestamp":1730121396466,"user_tz":-540,"elapsed":8417,"user":{"displayName":"조예인","userId":"17650117334011908449"}}},"execution_count":1,"outputs":[]},{"cell_type":"code","source":["from sklearn.model_selection import cross_validate\n","from sklearn.ensemble import RandomForestClassifier\n","\n","rf = RandomForestClassifier(n_jobs=-1, random_state=42)\n","scores = cross_validate(rf, train_input, train_target, return_train_score=True, n_jobs=-1)\n","\n","print(np.mean(scores['train_score']), np.mean(scores['test_score']))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Imb0lJQiRTBG","executionInfo":{"status":"ok","timestamp":1730121412462,"user_tz":-540,"elapsed":14959,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"d6cfa960-0f05-4f32-d1d4-e8f0c689e34b"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["0.9973541965122431 0.8905151032797809\n"]}]},{"cell_type":"code","source":["rf.fit(train_input, train_target)\n","print(rf.feature_importances_)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Z747U4MLRWWt","executionInfo":{"status":"ok","timestamp":1730121415947,"user_tz":-540,"elapsed":2506,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"33b13d5e-c62c-47e1-88c0-a4b302c1a682"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["[0.23167441 0.50039841 0.26792718]\n"]}]},{"cell_type":"markdown","source":["OOB 샘플 : 부트스트랩 샘플에 포함되지 않고 남는 샘플"],"metadata":{"id":"LlJdVIYERyVP"}},{"cell_type":"code","source":["rf = RandomForestClassifier(oob_score=True, n_jobs=-1, random_state=42)\n","\n","rf.fit(train_input, train_target)\n","print(rf.oob_score_)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xrEHEv34RZ-T","executionInfo":{"status":"ok","timestamp":1730121418242,"user_tz":-540,"elapsed":2297,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"f0ac9025-7163-41cf-93cc-2f967d5d3f4e"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["0.8934000384837406\n"]}]},{"cell_type":"markdown","source":["# 엑스트라트리"],"metadata":{"id":"TJmnAK8XRdcO"}},{"cell_type":"markdown","source":["부트스트랩 샘플을 사용하지 않고, 전체 훈련 세트를 사용.\n","\n","전체 특성 중에 일부를 랜덤하게 선택."],"metadata":{"id":"MURdvvOERwoK"}},{"cell_type":"code","source":["from sklearn.ensemble import ExtraTreesClassifier\n","\n","et = ExtraTreesClassifier(n_jobs=-1, random_state=42)\n","scores = cross_validate(et, train_input, train_target, return_train_score=True, n_jobs=-1)\n","\n","print(np.mean(scores['train_score']), np.mean(scores['test_score']))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"R9S_rCyWRbfc","executionInfo":{"status":"ok","timestamp":1730121443354,"user_tz":-540,"elapsed":6116,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"81a2ceef-5899-452a-b548-2ff69028c596"},"execution_count":5,"outputs":[{"output_type":"stream","name":"stdout","text":["0.9974503966084433 0.8887848893166506\n"]}]},{"cell_type":"code","source":["et.fit(train_input, train_target)\n","print(et.feature_importances_)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"BflR_pWwRg35","executionInfo":{"status":"ok","timestamp":1730121444652,"user_tz":-540,"elapsed":1301,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"3be41869-474a-4a13-a062-d5b4b35805de"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["[0.20183568 0.52242907 0.27573525]\n"]}]},{"cell_type":"markdown","source":["# 그레이디언트 부스팅"],"metadata":{"id":"zNZbGelsRn1v"}},{"cell_type":"code","source":["from sklearn.ensemble import GradientBoostingClassifier\n","\n","gb = GradientBoostingClassifier(random_state=42)\n","scores = cross_validate(gb, train_input, train_target, return_train_score=True, n_jobs=-1)\n","\n","print(np.mean(scores['train_score']), np.mean(scores['test_score']))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"bDf8HwEJRiR4","executionInfo":{"status":"ok","timestamp":1730121482566,"user_tz":-540,"elapsed":2446,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"e52cbb07-228b-469e-a3c5-5cf62928e9ff"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["0.8881086892152563 0.8720430147331015\n"]}]},{"cell_type":"code","source":["gb = GradientBoostingClassifier(n_estimators=500, learning_rate=0.2, random_state=42)\n","scores = cross_validate(gb, train_input, train_target, return_train_score=True, n_jobs=-1)\n","\n","print(np.mean(scores['train_score']), np.mean(scores['test_score']))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Xh6Upv-7RrRf","executionInfo":{"status":"ok","timestamp":1730121728182,"user_tz":-540,"elapsed":15819,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"05a63cf3-3e90-4c05-dd5a-1df26dc4760b"},"execution_count":8,"outputs":[{"output_type":"stream","name":"stdout","text":["0.9464595437171814 0.8780082549788999\n"]}]},{"cell_type":"code","source":["gb.fit(train_input, train_target)\n","print(gb.feature_importances_)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"W7GIVgxeSkUf","executionInfo":{"status":"ok","timestamp":1730121730349,"user_tz":-540,"elapsed":2168,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"dfb1d89f-5c40-41ec-82e0-1232c796cfd1"},"execution_count":9,"outputs":[{"output_type":"stream","name":"stdout","text":["[0.15887763 0.6799705 0.16115187]\n"]}]},{"cell_type":"markdown","source":["# 히스토그램 기반 그레이디언트 부스팅"],"metadata":{"id":"qgNC4A6_StEz"}},{"cell_type":"code","source":["from sklearn.ensemble import HistGradientBoostingClassifier\n","\n","hgb = HistGradientBoostingClassifier(random_state=42)\n","scores = cross_validate(hgb, train_input, train_target, return_train_score=True, n_jobs=-1)\n","\n","print(np.mean(scores['train_score']), np.mean(scores['test_score']))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"aQMMCPRoSv3L","executionInfo":{"status":"ok","timestamp":1730121809503,"user_tz":-540,"elapsed":2381,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"5eb52325-8c36-4740-d1f4-246cd39efb2d"},"execution_count":10,"outputs":[{"output_type":"stream","name":"stdout","text":["0.9321723946453317 0.8801241948619236\n"]}]},{"cell_type":"code","source":["from sklearn.inspection import permutation_importance\n","\n","hgb.fit(train_input, train_target)\n","result = permutation_importance(hgb, train_input, train_target, n_repeats=10,\n"," random_state=42, n_jobs=-1)\n","print(result.importances_mean)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"akYdz-O4S7L1","executionInfo":{"status":"ok","timestamp":1730121816890,"user_tz":-540,"elapsed":5072,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"bdfd8ae2-e514-4282-bc2d-55c161597516"},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["[0.08876275 0.23438522 0.08027708]\n"]}]},{"cell_type":"code","source":["result = permutation_importance(hgb, test_input, test_target, n_repeats=10,\n"," random_state=42, n_jobs=-1)\n","print(result.importances_mean)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"4hpfPdzYS8U7","executionInfo":{"status":"ok","timestamp":1730121818528,"user_tz":-540,"elapsed":1095,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"4d60af58-557d-4384-ad46-fa1df41a8e65"},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["[0.05969231 0.20238462 0.049 ]\n"]}]},{"cell_type":"code","source":["hgb.score(test_input, test_target)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"8gJvPcirS9qh","executionInfo":{"status":"ok","timestamp":1730121820896,"user_tz":-540,"elapsed":394,"user":{"displayName":"조예인","userId":"17650117334011908449"}},"outputId":"681f71f9-b511-463d-ef85-e4420c988cc0"},"execution_count":13,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0.8723076923076923"]},"metadata":{},"execution_count":13}]},{"cell_type":"code","source":[],"metadata":{"id":"GBcMwm77S-ci"},"execution_count":null,"outputs":[]}]}
Binary file added week4/[MLNovice]조예인_week4.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week5/[MLNovice]조예인_week5-1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week5/[MLNovice]조예인_week5-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week5/[MLNovice]조예인_week5-3.ipynb

Large diffs are not rendered by default.

Binary file added week5/[MLNovice]조예인_week5.pdf
Binary file not shown.
Binary file added week6/[MLNovice]조예인_week6.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week6/[MLNovice]조예인_week7-1.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week6/[MLNovice]조예인_week7-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week6/[MLNovice]조예인_week7-3.ipynb

Large diffs are not rendered by default.

Binary file added week7/[MLNovice]조예인_week7.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week7/[MLNovice]조예인_week8-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week7/[MLNovice]조예인_week8-3.ipynb

Large diffs are not rendered by default.

Binary file added week8/[MLNovice]조예인_week8.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions week8/[MLNovice]조예인_week9-2.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions week8/[MLNovice]조예인_week9-3.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.