diff --git "a/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-1.ipynb" "b/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-1.ipynb"
new file mode 100644
index 0000000..2c537a3
--- /dev/null
+++ "b/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-1.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyN+NosSh6cOGlVX9GZGUYoV"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"mUPgayDTIuMU"},"outputs":[],"source":["# 럭키백의 확률\n","\n","# 데이터 준비하기\n","import pandas as pd\n","\n","fish = pd.read_csv('https://bit.ly/fish_csv_data')\n","fish.head() # 테이블로 출력해\n","\n","# input 데이터\n","fish_input = fish[['Weight','Length','Diagonal','Height','Width']].to_numpy()\n","# target 데이터\n","fish_target = fish['Species'].to_numpy()"]},{"cell_type":"code","source":["# 데이터 전처리\n","# train set, test set 나누기\n","from sklearn.model_selection import train_test_split\n","\n","train_input, test_input, train_target, test_target = train_test_split(\n"," fish_input, fish_target, random_state=42)\n","\n","# data scaling\n","from sklearn.preprocessing import StandardScaler\n","\n","ss = StandardScaler()\n","ss.fit(train_input)\n","train_scaled = ss.transform(train_input)\n","test_scaled = ss.transform(test_input)"],"metadata":{"id":"vUaGxPeON4Rb"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# K-최근접 이웃의 다중분류 확률 예측\n","from sklearn.neighbors import KNeighborsClassifier\n","\n","kn = KNeighborsClassifier(n_neighbors=3) # 기본값은 5, 이번엔 3으로 설정\n","kn.fit(train_scaled, train_target)\n","\n","print(kn.classes_)\n","# class가 어떤식으로 나눠졌지 확인\n","\n","import numpy as np\n","\n","# 확률 출력 (predict_proba 메소드 사용)\n","proba = kn.predict_proba(test_scaled[:5])\n","print(np.round(proba, decimals=4))\n","\n","distances, indexes = kn.kneighbors(test_scaled[3:4])\n","print(train_target[indexes])"],"metadata":{"id":"5ZCyyrihN7sA"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 시그모이드 함수 만들기\n","import numpy as np\n","import matplotlib.pyplot as plt\n","\n","z = np.arange(-5, 5, 0.1)\n","phi = 1 / (1 + np.exp(-z))\n","\n","plt.plot(z, phi)\n","plt.xlabel('z')\n","plt.ylabel('phi')\n","plt.show()"],"metadata":{"id":"taWW1UNoOClC"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 로지스틱 회귀로 이진 분류\n","bream_smelt_indexes = (train_target == 'Bream') | (train_target == 'Smelt') # 불린 인덱싱\n","train_bream_smelt = train_scaled[bream_smelt_indexes]\n","target_bream_smelt = train_target[bream_smelt_indexes]\n","\n","from sklearn.linear_model import LogisticRegression\n","\n","# 객체 만들기\n","lr = LogisticRegression()\n","lr.fit(train_bream_smelt, target_bream_smelt)\n","\n","# 샘플 5개 (도미, 빙어)\n","print(lr.predict(train_bream_smelt[:5]))\n","# 샘플에 대한 확률\n","print(lr.predict_proba(train_bream_smelt[:5]))\n","\n","# 가중치\n","print(lr.coef_, lr.intercept_)\n","\n","# z값 계산\n","decisions = lr.decision_function(train_bream_smelt[:5])\n","print(decisions)\n","\n","# scipy에서 시그모이드함수 불러오기\n","from scipy.special import expit\n","print(expit(decisions))"],"metadata":{"id":"tWN1R-diOD7t"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 로지스틱 회귀로 다중 분류\n","lr = LogisticRegression(C=20, max_iter=1000)\n","lr.fit(train_scaled, train_target)\n","\n","# 정확도 예측\n","print(lr.score(train_scaled, train_target))\n","print(lr.score(test_scaled, test_target))\n","\n","# predict_proba 메소드로 확률 출력\n","proba = lr.predict_proba(test_scaled[:5])\n","print(np.round(proba, decimals=3))\n","\n","decision = lr.decision_function(test_scaled[:5])\n","print(np.round(decision, decimals=2))\n","\n","# 소프트맥스 함수\n","from scipy.special import softmax\n","\n","proba = softmax(decision, axis=1)\n","print(np.round(proba, decimals=3))"],"metadata":{"id":"w7q7UdRFOORO"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"FRzXkTPzPqlU"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"ftJkVWXTPqtU"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git "a/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-2.ipynb" "b/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-2.ipynb"
new file mode 100644
index 0000000..41f1719
--- /dev/null
+++ "b/week3/[MLNovice]\355\231\251\354\247\200\354\233\220_week3-2.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPp4SoE1DvNF6xZT3xKSAFg"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"k-tsR6BKTlHO"},"outputs":[],"source":["#SGD Classifier (확률적 경사 하강법 분류기)"]},{"cell_type":"code","source":["# 데이터 전처리\n","import pandas as pd\n","\n","fish = pd.read_csv('https://bit.ly/fish_csv_data')\n","\n","fish_input = fish[['Weight','Length','Diagonal','Height','Width']].to_numpy()\n","fish_target = fish['Species'].to_numpy()\n","\n","from sklearn.model_selection import train_test_split\n","\n","train_input, test_input, train_target, test_target = train_test_split(\n"," fish_input, fish_target, random_state=42)\n","\n","from sklearn.preprocessing import StandardScaler\n","\n","ss = StandardScaler()\n","ss.fit(train_input)\n","train_scaled = ss.transform(train_input)\n","test_scaled = ss.transform(test_input)"],"metadata":{"id":"bHmNSvnpTmxX"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 사이킷런에서 제공하는 SGD 모델\n","from sklearn.linear_model import SGDClassifier\n","\n","# 로지스틱 손실함수 지정\n","sc = SGDClassifier(loss='log_loss', max_iter=10, random_state=42)\n","sc.fit(train_scaled, train_target)\n","\n","# 정확도 출력\n","print(sc.score(train_scaled, train_target))\n","print(sc.score(test_scaled, test_target))\n","\n","# 이전에 훈련한 걸 다시 사용할지\n","sc.partial_fit(train_scaled, train_target)\n","\n","print(sc.score(train_scaled, train_target))\n","print(sc.score(test_scaled, test_target))"],"metadata":{"id":"HCBeluU2Tm2i"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 에포크와 과대/과소적합\n","\n","import numpy as np\n","\n","sc = SGDClassifier(loss='log_loss', random_state=42)\n","\n","train_score = []\n","test_score = []\n","\n","# partial_fit 메소드로 훈련\n","classes = np.unique(train_target)\n","for _ in range(0, 300):\n"," sc.partial_fit(train_scaled, train_target, classes=classes)\n","\n"," train_score.append(sc.score(train_scaled, train_target))\n"," test_score.append(sc.score(test_scaled, test_target))\n","\n","sc = SGDClassifier(loss='log_loss', max_iter=100, tol=None, random_state=42)\n","sc.fit(train_scaled, train_target)\n","\n","print(sc.score(train_scaled, train_target))\n","print(sc.score(test_scaled, test_target))"],"metadata":{"id":"GFBSr9OPe7Uq"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 훈련세트와 테스트셋의 성능 측정 그래프\n","import matplotlib.pyplot as plt\n","\n","plt.plot(train_score)\n","plt.plot(test_score)\n","plt.xlabel('epoch')\n","plt.ylabel('accuracy')\n","plt.show()"],"metadata":{"id":"fomxBb2IgKyN"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 소프트맥스 함수 사용할때는 손실함수에 'hinge'\n","sc = SGDClassifier(loss='hinge', max_iter=100, tol=None, random_state=42)\n","sc.fit(train_scaled, train_target)\n","\n","print(sc.score(train_scaled, train_target))\n","print(sc.score(test_scaled, test_target))"],"metadata":{"id":"5ZFYqBype7ho"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git "a/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-1.ipynb" "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-1.ipynb"
new file mode 100644
index 0000000..560728c
--- /dev/null
+++ "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-1.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNpugaSWMPn0ue9hSmkzVix"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"5QrsbuJIMTLD"},"outputs":[],"source":["# 데이터준비\n","import pandas as pd\n","\n","wine = pd.read_csv('https://bit.ly/wine_csv_data')\n","\n","# 누락된 데이터 값이 있는지 간단히 확인\n","wine.describe()\n","\n","data = wine[['alcohol', 'sugar', 'pH']].to_numpy()\n","target = wine['class'].to_numpy()"]},{"cell_type":"code","source":["# 데이터 스케일링\n","from sklearn.model_selection import train_test_split\n","\n","train_input, test_input, train_target, test_target = train_test_split(\n"," data, target, test_size=0.2, random_state=42)\n","\n","\n","from sklearn.preprocessing import StandardScaler\n","\n","ss = StandardScaler()\n","ss.fit(train_input)\n","\n","train_scaled = ss.transform(train_input)\n","test_scaled = ss.transform(test_input)"],"metadata":{"id":"z61hBwLES0oq"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 로지스틱 회귀\n","from sklearn.linear_model import LogisticRegression\n","\n","lr = LogisticRegression()\n","lr.fit(train_scaled, train_target)\n","\n","print(lr.score(train_scaled, train_target))\n","print(lr.score(test_scaled, test_target))\n","\n","print(lr.coef_, lr.intercept_)\n","# [[ 0.51268071 1.67335441 -0.68775646]] [1.81773456]"],"metadata":{"id":"gX6Q_8EES0rm"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 결정 트리\n","from sklearn.tree import DecisionTreeClassifier\n","\n","dt = DecisionTreeClassifier(random_state=42) # 사용할 특성을 랜덤하게 선택\n","dt.fit(train_scaled, train_target)\n","\n","# 트리 구조 보기\n","import matplotlib.pyplot as plt\n","from sklearn.tree import plot_tree\n","\n","plt.figure(figsize=(10,7))\n","plot_tree(dt)\n","plt.show()"],"metadata":{"id":"hq3oVCKYS0t4"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 트리 구조 간단히 보기\n","plt.figure(figsize=(10,7))\n","plot_tree(dt, max_depth=1, filled=True, feature_names=['alcohol', 'sugar', 'pH'])\n","plt.show()"],"metadata":{"id":"KR1woCnmS0wM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 가지치기\n","dt = DecisionTreeClassifier(max_depth=3, random_state=42)\n","# max_depth로 트리의 깊이 조절\n","dt.fit(train_scaled, train_target)\n","\n","plt.figure(figsize=(20,15))\n","plot_tree(dt, filled=True, feature_names=['alcohol', 'sugar', 'pH'])\n","plt.show()\n","\n","dt = DecisionTreeClassifier(max_depth=3, random_state=42)\n","dt.fit(train_input, train_target)\n","\n","plt.figure(figsize=(20,15))\n","plot_tree(dt, filled=True, feature_names=['alcohol', 'sugar', 'pH'])\n","plt.show()"],"metadata":{"id":"Hn-P2w22S8YQ"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git "a/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-2.ipynb" "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-2.ipynb"
new file mode 100644
index 0000000..288a8a5
--- /dev/null
+++ "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-2.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNy8oz0bYMZiwhj1kBoh0/Z"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"nDI_gzaCTPjJ"},"outputs":[],"source":["# 검증 세트\n","\n","# 데이터\n","import pandas as pd\n","\n","wine = pd.read_csv('https://bit.ly/wine_csv_data')\n","data = wine[['alcohol', 'sugar', 'pH']].to_numpy()\n","target = wine['class'].to_numpy()\n","\n","# train, test 나누기\n","from sklearn.model_selection import train_test_split\n","\n","train_input, test_input, train_target, test_target = train_test_split(\n"," data, target, test_size=0.2, random_state=42)\n","\n","sub_input, val_input, sub_target, val_target = train_test_split(\n"," train_input, train_target, test_size=0.2, random_state=42)\n","\n","from sklearn.tree import DecisionTreeClassifier\n","\n","dt = DecisionTreeClassifier(random_state=42)\n","dt.fit(sub_input, sub_target)"]},{"cell_type":"code","source":["# 교차 검증\n","from sklearn.model_selection import cross_validate\n","\n","# 처음 나눈 세트로 교차검증\n","scores = cross_validate(dt, train_input, train_target)\n","\n","# 검증의 점수 평균 내보기\n","import numpy as np\n","print(np.mean(scores['test_score']))"],"metadata":{"id":"-n5UDAQ7bGsQ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 분할기를 사용한 교차 검증\n","from sklearn.model_selection import StratifiedKFold\n","\n","scores = cross_validate(dt, train_input, train_target, cv=StratifiedKFold())\n","\n","\n","splitter = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)\n","scores = cross_validate(dt, train_input, train_target, cv=splitter"],"metadata":{"id":"FEygEuZsbGv0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 하이퍼 파라미터 튜닝\n","from sklearn.model_selection import GridSearchCV\n","\n","# 매개변수를 딕셔너리에 정의\n","params = {'min_impurity_decrease': [0.0001, 0.0002, 0.0003, 0.0004, 0.0005]}\n","\n","gs = GridSearchCV(DecisionTreeClassifier(random_state=42), params, n_jobs=-1)\n","gs.fit(train_input, train_target)\n","\n","# 최적의 값을 찾아서 best_estimator_에 넣어줌\n","dt = gs.best_estimator_\n","print(dt.score(train_input, train_target))\n","\n","print(gs.best_params_)\n","print(gs.cv_results_['mean_test_score'])"],"metadata":{"id":"5pD2hPx0hZt6"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 확률 분포 선택\n","from scipy.stats import uniform, randint # 균등 분포 샘플링\n","\n","rgen = randint(0, 10)\n","rgen.rvs(10)\n","\n","np.unique(rgen.rvs(1000), return_counts=True)\n","\n","ugen = uniform(0, 1) # 실수값을 샘플링\n","ugen.rvs(10)"],"metadata":{"id":"yX1FcDMzhZwq"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 랜덤 서치\n","params = {'min_impurity_decrease': uniform(0.0001, 0.001),\n"," 'max_depth': randint(20, 50),\n"," 'min_samples_split': randint(2, 25),\n"," 'min_samples_leaf': randint(1, 25),\n"," }\n","\n","from sklearn.model_selection import RandomizedSearchCV # 랜덤 서치 함수\n","\n","gs = RandomizedSearchCV(DecisionTreeClassifier(random_state=42), params,\n"," n_iter=100, n_jobs=-1, random_state=42)\n","# n_iter : 모델 개수\n","\n","gs.fit(train_input, train_target)m sklearn.model_selection import RandomizedSearchCV\n","\n","gs = RandomizedSearchCV(DecisionTreeClassifier(random_state=42), params,\n"," n_iter=100, n_jobs=-1, random_state=42)\n","gs.fit(train_input, train_target)"],"metadata":{"id":"QJxx6uh2bGyu"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git "a/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-3.ipynb" "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-3.ipynb"
new file mode 100644
index 0000000..bc22488
--- /dev/null
+++ "b/week4/[MLNovice]\355\231\251\354\247\200\354\233\220_week4-3.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyM4+2lCH8tm12reo9hz8z2m"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"g-eXJt1LbCY5"},"outputs":[],"source":["# 랜덤 포레스트\n","\n","# 데이터 불러오기\n","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)\n","\n","# 앙상블에서 랜덤포레스트 류기\n","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']))\n","\n","# OOB 샘플 : 남는 샘플데이터를 활용하여 검증\n","rf.fit(train_input, train_target)\n","rf = RandomForestClassifier(oob_score=True, n_jobs=-1, random_state=42)\n","rf.fit(train_input, train_target)"]},{"cell_type":"code","source":["# 엑스트라 트리\n","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']))\n","\n","et.fit(train_input, train_target)\n","print(et.feature_importances_)"],"metadata":{"id":"gcS6Ifvbqmq5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 그래디언트 부스팅\n","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","# 트리 개수 늘리기 (500개로 늘림)\n","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","gb.fit(train_input, train_target)"],"metadata":{"id":"XuvMPwC9qmtZ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 히스토그램 기반 부스팅\n","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","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,random_state=42, n_jobs=-1)\n","\n","result = permutation_importance(hgb, test_input, test_target, n_repeats=10, random_state=42, n_jobs=-1)\n","hgb.score(test_input, test_target)"],"metadata":{"id":"qmHHje1UqqOL"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git a/week4/ch5_TreeAlgorithm b/week4/ch5_TreeAlgorithm
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/week4/ch5_TreeAlgorithm
@@ -0,0 +1 @@
+
diff --git a/week5/Ch6 Clustering b/week5/Ch6 Clustering
new file mode 100644
index 0000000..11dcf5d
--- /dev/null
+++ b/week5/Ch6 Clustering
@@ -0,0 +1 @@
+Ch6 Clustering
diff --git "a/week5/[MLNovice]\355\231\251\354\247\200\354\233\220_week5.ipynb" "b/week5/[MLNovice]\355\231\251\354\247\200\354\233\220_week5.ipynb"
new file mode 100644
index 0000000..b506c42
--- /dev/null
+++ "b/week5/[MLNovice]\355\231\251\354\247\200\354\233\220_week5.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMscckwFuxfW+EJASgZe3lf"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["# 군집 알고리즘"],"metadata":{"id":"s60iWWQdJjWH"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TikC71eZ2kFf"},"outputs":[],"source":["# 과일 데이터 준비\n","\n","# numpy 파일로 준비, 코랩에 데이터 파일로 불러오기\n","!wget https://bit.ly/fruits_300_data -O fruits_300.npy\n","\n","import numpy as np\n","import matplotlib.pyplot as plt\n","\n","fruits = np.load('fruits_300.npy')\n","\n","print(fruits.shape) #총 300개, 100x100 크기의 데이터\n","\n","# numpy 배열의 데이터를 이미지로 보여줌\n","plt.imshow(fruits[0], cmap='gray')\n","plt.show()\n","\n","# 색상 반전을 하여 보기 좋게 만들기\n","plt.imshow(fruits[0], cmap='gray_r')\n","plt.show()\n","\n","fig, axs = plt.subplots(1, 2)\n","axs[0].imshow(fruits[100], cmap='gray_r') # 파인애플\n","axs[1].imshow(fruits[200], cmap='gray_r') # 바나나\n","plt.show()"]},{"cell_type":"code","source":["# 샘플 차원 변경하기 (픽셀을 100x100 1차원 배열에 넣기)\n","apple = fruits[0:100].reshape(-1, 100*100)\n","pineapple = fruits[100:200].reshape(-1, 100*100)\n","banana = fruits[200:300].reshape(-1, 100*100)\n","\n","# 샘플 평균의 히스토그램\n","plt.hist(np.mean(apple, axis=1), alpha=0.8)\n","plt.hist(np.mean(pineapple, axis=1), alpha=0.8)\n","plt.hist(np.mean(banana, axis=1), alpha=0.8)\n","plt.legend(['apple', 'pineapple', 'banana'])\n","plt.show()\n","\n","# 픽셀 평균의 히스토그램\n","fig, axs = plt.subplots(1, 3, figsize=(20, 5))\n","axs[0].bar(range(10000), np.mean(apple, axis=0))\n","axs[1].bar(range(10000), np.mean(pineapple, axis=0))\n","axs[2].bar(range(10000), np.mean(banana, axis=0))\n","plt.show()\n","\n","# 평균 이미지 그리기\n","apple_mean = np.mean(apple, axis=0).reshape(100, 100)\n","pineapple_mean = np.mean(pineapple, axis=0).reshape(100, 100)\n","banana_mean = np.mean(banana, axis=0).reshape(100, 100)\n","\n","fig, axs = plt.subplots(1, 3, figsize=(20, 5))\n","axs[0].imshow(apple_mean, cmap='gray_r')\n","axs[1].imshow(pineapple_mean, cmap='gray_r')\n","axs[2].imshow(banana_mean, cmap='gray_r')\n","plt.show()"],"metadata":{"id":"VQyFRn5pJjRM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 평균값과 가까운 사진 고르기\n","abs_diff = np.abs(fruits - apple_mean)\n","bs_mean = np.mean(abs_diff, axis=(1,2))\n","\n","apple_index = np.argsort(abs_mean)[:100]\n","fig, axs = plt.subplots(10, 10, figsize=(10,10))\n","for i in range(10):\n"," for j in range(10):\n"," axs[i, j].imshow(fruits[apple_index[i*10 + j]], cmap='gray_r')\n"," axs[i, j].axis('off')\n","plt.show()"],"metadata":{"id":"rJrdVi_AJjUA"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# K-평균"],"metadata":{"id":"-ed-hq3jKAnr"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 데이터 준비\n","!wget https://bit.ly/fruits_300_data -O fruits_300.npy\n","\n","import numpy as np\n","\n","fruits = np.load('fruits_300.npy')\n","fruits_2d = fruits.reshape(-1, 100*100)"],"metadata":{"id":"elmjftpzKL2a"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 모델 훈련\n","from sklearn.cluster import KMeans\n","\n","km = KMeans(n_clusters=3, random_state=42)\n","km.fit(fruits_2d) # 데이터를 2차원 배열로 변경\n","\n","# 잘 분류가 되었는지 확인해보기 (데이터 수가 적어서 가능)\n","print(np.unique(km.labels_, return_counts=True))"],"metadata":{"id":"e98fIQq2KL4w"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 첫번째 클러스터\n","\n","import matplotlib.pyplot as plt\n","\n","def draw_fruits(arr, ratio=1):\n"," n = len(arr) # n은 샘플 개수\n"," # 한 줄에 10개씩 이미지를 그립니다. 샘플 개수를 10으로 나누어 전체 행 개수를 계산합니다.\n"," rows = int(np.ceil(n/10))\n"," # 행이 1개 이면 열 개수는 샘플 개수입니다. 그렇지 않으면 10개입니다.\n"," cols = n if rows < 2 else 10\n"," fig, axs = plt.subplots(rows, cols,\n"," figsize=(cols*ratio, rows*ratio), squeeze=False)\n"," for i in range(rows):\n"," for j in range(cols):\n"," if i*10 + j < n: # n 개까지만 그립니다.\n"," axs[i, j].imshow(arr[i*10 + j], cmap='gray_r')\n"," axs[i, j].axis('off')\n"," plt.show()\n","\n"," draw_fruits(fruits[km.labels_==0])"],"metadata":{"id":"yH-WWn51KL7i"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 클러스터 중심\n","draw_fruits(km.cluster_centers_.reshape(-1, 100, 100), ratio=3)"],"metadata":{"id":"qRcRHRNHKL-I"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 최적의 K 찾기\n","inertia = []\n","for k in range(2, 7):\n"," km = KMeans(n_clusters=k, n_init='auto', random_state=42)\n"," km.fit(fruits_2d)\n"," inertia.append(km.inertia_)\n","\n","plt.plot(range(2, 7), inertia)\n","plt.xlabel('k')\n","plt.ylabel('inertia')\n","plt.show()"],"metadata":{"id":"Ii4uhzJVYMPJ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 주성분 분석"],"metadata":{"id":"FUoTpNERYMVe"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 데이터 불러오기\n","!wget https://bit.ly/fruits_300_data -O fruits_300.npy\n","\n","import numpy as np\n","\n","fruits = np.load('fruits_300.npy')\n","fruits_2d = fruits.reshape(-1, 100*100)"],"metadata":{"id":"P6M9z9_mYRt4"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# PCA\n","from sklearn.decomposition import PCA\n","\n","pca = PCA(n_components=50)\n","pca.fit(fruits_2d)\n","\n","import matplotlib.pyplot as plt\n","\n","def draw_fruits(arr, ratio=1):\n"," n = len(arr) # n은 샘플 개수입니다\n"," # 한 줄에 10개씩 이미지를 그립니다. 샘플 개수를 10으로 나누어 전체 행 개수를 계산합니다.\n"," rows = int(np.ceil(n/10))\n"," # 행이 1개 이면 열 개수는 샘플 개수입니다. 그렇지 않으면 10개입니다.\n"," cols = n if rows < 2 else 10\n"," fig, axs = plt.subplots(rows, cols,\n"," figsize=(cols*ratio, rows*ratio), squeeze=False)\n"," for i in range(rows):\n"," for j in range(cols):\n"," if i*10 + j < n: # n 개까지만 그립니다.\n"," axs[i, j].imshow(arr[i*10 + j], cmap='gray_r')\n"," axs[i, j].axis('off')\n"," plt.show()\n","\n","draw_fruits(pca.components_.reshape(-1, 100, 100))"],"metadata":{"id":"sWZd0aucYRoP"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 뽑은 주성분으로 원본 데이터 복원\n","\n","fruits_inverse = pca.inverse_transform(fruits_pca)\n","print(fruits_inverse.shape)\n","\n","fruits_reconstruct = fruits_inverse.reshape(-1, 100, 100)\n","\n","for start in [0, 100, 200]:\n"," draw_fruits(fruits_reconstruct[start:start+100])\n"," print(\"\\n\")"],"metadata":{"id":"bjvZuPo4fOFh"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 설명된 분산\n","print(np.sum(pca.explained_variance_ratio_))\n","\n","plt.plot(pca.explained_variance_ratio_)"],"metadata":{"id":"Uf0x2rjIfPud"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git a/week7/Ch8 Convolution b/week7/Ch8 Convolution
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/week7/Ch8 Convolution
@@ -0,0 +1 @@
+
diff --git "a/week7/[MLNovice]\355\231\251\354\247\200\354\233\220_week7.ipynb" "b/week7/[MLNovice]\355\231\251\354\247\200\354\233\220_week7.ipynb"
new file mode 100644
index 0000000..0bba6e6
--- /dev/null
+++ "b/week7/[MLNovice]\355\231\251\354\247\200\354\233\220_week7.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPQbvi+FLkxdQa8dUROlnkk"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"usXAq7K9w_Go"},"outputs":[],"source":["# 합성곱 신경망을 사용한 이미지 분류"]},{"cell_type":"code","source":["# 패션 MNIST 데이터 불러오기\n","from tensorflow import keras\n","from sklearn.model_selection import train_test_split\n","\n","(train_input, train_target), (test_input, test_target) = \\\n"," keras.datasets.fashion_mnist.load_data()\n","\n","train_scaled = train_input.reshape(-1, 28, 28, 1) / 255.0 # 마지막 차원만 늘\n","\n","train_scaled, val_scaled, train_target, val_target = train_test_split(\n"," train_scaled, train_target, test_size=0.2, random_state=42)"],"metadata":{"id":"yEqM-KJDxHMT"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 합성곱 신경망 만들기\n","model = keras.Sequential()\n","\n","# 첫번째 층 (필터 사이즈, 활성함수, 패딩)\n","model.add(keras.layers.Conv2D(32, kernel_size=3, activation='relu',padding='same', input_shape=(28,28,1)))\n","# 풀링 레이어 추가\n","model.add(keras.layers.MaxPooling2D(2))\n","\n","model.add(keras.layers.Conv2D(64, kernel_size=(3,3), activation='relu',padding='same'))\n","model.add(keras.layers.MaxPooling2D(2))\n","\n","model.add(keras.layers.Flatten())\n","model.add(keras.layers.Dense(100, activation='relu'))\n","model.add(keras.layers.Dropout(0.4))\n","model.add(keras.layers.Dense(10, activation='softmax'))\n","\n","model.summary()"],"metadata":{"id":"BsPngWqCxHR5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 컴파일과 훈련\n","model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n","\n","checkpoint_cb = keras.callbacks.ModelCheckpoint('best-model.keras', save_best_only=True)\n","early_stopping_cb = keras.callbacks.EarlyStopping(patience=2, restore_best_weights=True)\n","\n","history = model.fit(train_scaled, train_target, epochs=20, verbose=0,\n"," validation_data=(val_scaled, val_target),\n"," callbacks=[checkpoint_cb, early_stopping_cb])"],"metadata":{"id":"DHYHpWrNI2F8"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 합성곱 신경망 시각화"],"metadata":{"id":"qwXQZqzyI2IK"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"XCgVeRnYxHVe"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"gxv2VKQMI9XQ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"l078ZGmFI9Zu"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git a/week8/Ch9 RNN b/week8/Ch9 RNN
new file mode 100644
index 0000000..e6224a1
--- /dev/null
+++ b/week8/Ch9 RNN
@@ -0,0 +1 @@
+RNN
diff --git "a/week8/[MLNovice]\355\231\251\354\247\200\354\233\220_week8.ipynb" "b/week8/[MLNovice]\355\231\251\354\247\200\354\233\220_week8.ipynb"
new file mode 100644
index 0000000..2f73ed5
--- /dev/null
+++ "b/week8/[MLNovice]\355\231\251\354\247\200\354\233\220_week8.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMrIgdGhNXr0VrXkQp6YpAN"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"3aYY73BdpXJE"},"outputs":[],"source":["# 순환 신경망으로 IMDB 리뷰 분류하기"]},{"cell_type":"code","source":["# IMDB 리뷰 데이터셋 불러오기\n","from tensorflow.keras.datasets import imdb\n","(train_input, train_target), (test_input, test_target) = imdb.load_data(num_words=200)\n","\n","# train, test set 설정\n","from sklearn.model_selection import train_test_split\n","train_input, val_input, train_target, val_target = train_test_split(train_input, train_target, test_size=0.2, random_state=42)\n","\n","# 리뷰 길이 시각화\n","import matplotlib.pyplot as plt\n","\n","plt.hist(lengths)\n","plt.xlabel('length')\n","plt.ylabel('frequency')\n","plt.show()"],"metadata":{"id":"skd11nHjpZqi"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 시퀀스 패딩\n","from tensorflow.keras.preprocessing.sequence import pad_sequences\n","train_seq = pad_sequences(train_input, maxlen=100)\n","# 100보다 긴 리뷰는 자르고, 100보다 짧은 리뷰는 100으로 패딩"],"metadata":{"id":"h8bPpFaspZso"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 순환 신경망 만들기\n","from tensorflow import keras\n","\n","model = keras.Sequential()\n","\n","model.add(keras.layers.SimpleRNN(8, input_shape=(100, 200)))\n","model.add(keras.layers.Dense(1, activation='sigmoid'))\n","\n","train_oh = keras.utils.to_categorical(train_seq)\n","\n","val_oh = keras.utils.to_categorical(val_seq)\n","model.summary()"],"metadata":{"id":"07wvb3FV2Vuq"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 모델 훈련\n","rmsprop = keras.optimizers.RMSprop(learning_rate=1e-4)\n","model.compile(optimizer=rmsprop, loss='binary_crossentropy', metrics=['accuracy'])\n","\n","checkpoint_cb = keras.callbacks.ModelCheckpoint('best-simplernn-model.keras', save_best_only=True)\n","early_stopping_cb = keras.callbacks.EarlyStopping(patience=3, restore_best_weights=True)\n","\n","history = model.fit(train_oh, train_target, epochs=100, batch_size=64, validation_data=(val_oh, val_target),\n","callbacks=[checkpoint_cb, early_stopping_cb])\n","\n","# 성능 평가\n","plt.plot(history.history['loss'])\n","plt.plot(history.history['val_loss'])\n","plt.xlabel('epoch')\n","plt.ylabel('loss')\n","plt.legend(['train', 'val'])\n","plt.show()"],"metadata":{"id":"NFxdY1NO2VxQ"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 임베딩 사용 모델\n","model2 = keras.Sequential()\n","\n","model2.add(keras.layers.Embedding(200, 16, input_shape=(100,)))\n","model2.add(keras.layers.SimpleRNN(8))\n","model2.add(keras.layers.Dense(1, activation='sigmoid'))\n","\n","model2.summary()"],"metadata":{"id":"QfqCQ9SW2Vzw"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 모델 훈련\n","rmsprop = keras.optimizers.RMSprop(learning_rate=1e-4)\n","model2.compile(optimizer=rmsprop, loss='binary_crossentropy',\n"," metrics=['accuracy'])\n","\n","checkpoint_cb = keras.callbacks.ModelCheckpoint('best-embedding-model.keras', save_best_only=True)\n","early_stopping_cb = keras.callbacks.EarlyStopping(patience=3, restore_best_weights=True)\n","\n","history = model2.fit(train_seq, train_target, epochs=100, batch_size=64, validation_data=(val_seq, val_target),\n","callbacks=[checkpoint_cb, early_stopping_cb])\n","\n","plt.plot(history.history['loss'])\n","plt.plot(history.history['val_loss'])\n","plt.xlabel('epoch')\n","plt.ylabel('loss')\n","plt.legend(['train', 'val'])\n","plt.show()"],"metadata":{"id":"xB1NEr8RpZu7"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# LSTM과 GRU 셀"],"metadata":{"id":"NJJ1DYp72gN_"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# LSTM 신경망 훈련하기\n","from tensorflow.keras.datasets import imdb\n","from sklearn.model_selection import train_test_split\n","\n","(train_input, train_target), (test_input, test_target) = imdb.load_data(num_words=500)\n","train_input, val_input, train_target, val_target = train_test_split(train_input, train_target, test_size=0.2, random_state=42)\n","\n","\n","from tensorflow.keras.preprocessing.sequence import pad_sequences\n","\n","train_seq = pad_sequences(train_input, maxlen=100)\n","val_seq = pad_sequences(val_input, maxlen=100)"],"metadata":{"id":"3VeHwT612gQ1"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 모델 만들기 (keras에서 RNN을 LSTM으로 바꾸면 됨)\n","from tensorflow import keras\n","\n","model = keras.Sequential()\n","\n","model.add(keras.layers.Embedding(500, 16, input_shape=(100,)))\n","model.add(keras.layers.LSTM(8))\n","model.add(keras.layers.Dense(1, activation='sigmoid'))\n","\n","model.summary()"],"metadata":{"id":"P87IZIAs3j2V"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 모델 훈련\n","rmsprop = keras.optimizers.RMSprop(learning_rate=1e-4)\n","model.compile(optimizer=rmsprop, loss='binary_crossentropy', metrics=['accuracy'])\n","\n","checkpoint_cb = keras.callbacks.ModelCheckpoint('best-lstm-model.keras', save_best_only=True)\n","early_stopping_cb = keras.callbacks.EarlyStopping(patience=3, restore_best_weights=True)\n","\n","history = model.fit(train_seq, train_target, epochs=100, batch_size=64,\n"," validation_data=(val_seq, val_target),\n"," callbacks=[checkpoint_cb, early_stopping_cb])"],"metadata":{"id":"PsMwgtkL6QVM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 성능 평가\n","import matplotlib.pyplot as plt\n","\n","plt.plot(history.history['loss'])\n","plt.plot(history.history['val_loss'])\n","plt.xlabel('epoch')\n","plt.ylabel('loss')\n","plt.legend(['train', 'val'])\n","plt.show()"],"metadata":{"id":"7JgudiBv3j5R"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 순환 층에 드롭아웃 적용하기\n","model2 = keras.Sequential()\n","\n","model2.add(keras.layers.Embedding(500, 16, input_shape=(100,)))\n","model2.add(keras.layers.LSTM(8, dropout=0.3))\n","model2.add(keras.layers.Dense(1, activation='sigmoid'))"],"metadata":{"id":"FjAaqHXp6TgE"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# 2개의 층을 연결하기\n","model3 = keras.Sequential()\n","\n","model3.add(keras.layers.Embedding(500, 16, input_shape=(100,)))\n","model3.add(keras.layers.LSTM(8, dropout=0.3, return_sequences=True)) # return_sequences=True 기억하기\n","model3.add(keras.layers.LSTM(8, dropout=0.3))\n","model3.add(keras.layers.Dense(1, activation='sigmoid'))\n","\n","model3.summary()"],"metadata":{"id":"HgpUGpro6Tiz"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# GRU 신경망 훈련하기\n","model4 = keras.Sequential()\n","\n","model4.add(keras.layers.Embedding(500, 16, input_shape=(100,)))\n","model4.add(keras.layers.GRU(8))\n","model4.add(keras.layers.Dense(1, activation='sigmoid'))\n","\n","model4.summary()"],"metadata":{"id":"56W6-nEx6X4r"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file
diff --git a/week9/CIFAR-10 - Object Recognition in Images b/week9/CIFAR-10 - Object Recognition in Images
new file mode 100644
index 0000000..7e2e2e5
--- /dev/null
+++ b/week9/CIFAR-10 - Object Recognition in Images
@@ -0,0 +1 @@
+CIFAR-10 - Object Recognition in Images
diff --git "a/week9/[MLNovice]\355\231\251\354\247\200\354\233\220_week9.ipynb" "b/week9/[MLNovice]\355\231\251\354\247\200\354\233\220_week9.ipynb"
new file mode 100644
index 0000000..ca0f0be
--- /dev/null
+++ "b/week9/[MLNovice]\355\231\251\354\247\200\354\233\220_week9.ipynb"
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"gpuType":"T4","authorship_tag":"ABX9TyPCfux6edvQfIJjc2rYVezW"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU"},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"Dg_KLBMMxDPB","executionInfo":{"status":"ok","timestamp":1733275384623,"user_tz":-540,"elapsed":3518,"user":{"displayName":"황지원","userId":"01099698570160424720"}}},"outputs":[],"source":["import keras\n","from keras.datasets import cifar10\n","#from keras.preprocessing.image import ImageDataGenerator\n","from keras.models import Sequential\n","from keras.layers import Dense, Dropout, Activation, Flatten\n","from keras.layers import Conv2D, MaxPooling2D\n","\n","import numpy as np\n","\n","import seaborn as sns\n","import matplotlib\n","import matplotlib.pyplot as plt\n","\n","from sklearn.metrics import confusion_matrix, classification_report\n","import itertools"]},{"cell_type":"code","source":["batch_size = 32 # The default batch size of keras.\n","num_classes = 10 # Number of class for the dataset\n","epochs = 20\n","data_augmentation = False"],"metadata":{"id":"HMlthHjvxE3N","executionInfo":{"status":"ok","timestamp":1733275390231,"user_tz":-540,"elapsed":294,"user":{"displayName":"황지원","userId":"01099698570160424720"}}},"execution_count":2,"outputs":[]},{"cell_type":"code","source":["# The data, split between train and test sets:\n","(x_train, y_train), (x_test, y_test) = cifar10.load_data()\n","print('x_train shape:', x_train.shape)\n","print('y_train shape:', y_train.shape)\n","print(x_train.shape[0], 'train samples')\n","print(x_test.shape[0], 'test samples')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_Sfr5RTNxE7Z","executionInfo":{"status":"ok","timestamp":1733275393261,"user_tz":-540,"elapsed":1520,"user":{"displayName":"황지원","userId":"01099698570160424720"}},"outputId":"cc75bfa2-e76b-4ee4-9189-00a9fe3ec759"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["x_train shape: (50000, 32, 32, 3)\n","y_train shape: (50000, 1)\n","50000 train samples\n","10000 test samples\n"]}]},{"cell_type":"code","source":["# Normalize the data. Before we need to connvert data type to float for computation.\n","x_train = x_train.astype('float32')\n","x_test = x_test.astype('float32')\n","x_train /= 255\n","x_test /= 255\n","\n","# Convert class vectors to binary class matrices. This is called one hot encoding.\n","y_train = keras.utils.to_categorical(y_train, num_classes)\n","y_test = keras.utils.to_categorical(y_test, num_classes)"],"metadata":{"id":"ndjfxvyPxE-A","executionInfo":{"status":"ok","timestamp":1733275394555,"user_tz":-540,"elapsed":285,"user":{"displayName":"황지원","userId":"01099698570160424720"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","source":["#define the convnet\n","model = Sequential()\n","# CONV => RELU => CONV => RELU => POOL => DROPOUT\n","model.add(Conv2D(32, (3, 3), padding='same',input_shape=x_train.shape[1:]))\n","model.add(Activation('relu'))\n","model.add(Conv2D(32, (3, 3)))\n","model.add(Activation('relu'))\n","model.add(MaxPooling2D(pool_size=(2, 2)))\n","model.add(Dropout(0.25))\n","\n","# CONV => RELU => CONV => RELU => POOL => DROPOUT\n","model.add(Conv2D(64, (3, 3), padding='same'))\n","model.add(Activation('relu'))\n","model.add(Conv2D(64, (3, 3)))\n","model.add(Activation('relu'))\n","model.add(MaxPooling2D(pool_size=(2, 2)))\n","model.add(Dropout(0.25))\n","\n","# FLATTERN => DENSE => RELU => DROPOUT\n","model.add(Flatten())\n","model.add(Dense(512))\n","model.add(Activation('relu'))\n","model.add(Dropout(0.5))\n","# a softmax classifier\n","model.add(Dense(num_classes))\n","model.add(Activation('softmax'))\n","\n","model.summary()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":805},"id":"HTgGR2ylOk3k","executionInfo":{"status":"ok","timestamp":1733275398029,"user_tz":-540,"elapsed":1926,"user":{"displayName":"황지원","userId":"01099698570160424720"}},"outputId":"96d25dcf-72f3-4099-ed6a-9b1d985b3fbb"},"execution_count":5,"outputs":[{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.10/dist-packages/keras/src/layers/convolutional/base_conv.py:107: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n"," super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n"]},{"output_type":"display_data","data":{"text/plain":["\u001b[1mModel: \"sequential\"\u001b[0m\n"],"text/html":["
Model: \"sequential\"\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓\n","┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n","┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩\n","│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m896\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m30\u001b[0m, \u001b[38;5;34m30\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m9,248\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_1 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m30\u001b[0m, \u001b[38;5;34m30\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ max_pooling2d (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m18,496\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_2 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m15\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m36,928\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_3 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ max_pooling2d_1 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout_1 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ flatten (\u001b[38;5;33mFlatten\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2304\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m1,180,160\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_4 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout_2 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m10\u001b[0m) │ \u001b[38;5;34m5,130\u001b[0m │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_5 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m10\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n","└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘\n"],"text/html":["┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓\n","┃ Layer (type) ┃ Output Shape ┃ Param # ┃\n","┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩\n","│ conv2d (Conv2D) │ (None, 32, 32, 32) │ 896 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation (Activation) │ (None, 32, 32, 32) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_1 (Conv2D) │ (None, 30, 30, 32) │ 9,248 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_1 (Activation) │ (None, 30, 30, 32) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ max_pooling2d (MaxPooling2D) │ (None, 15, 15, 32) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout (Dropout) │ (None, 15, 15, 32) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_2 (Conv2D) │ (None, 15, 15, 64) │ 18,496 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_2 (Activation) │ (None, 15, 15, 64) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ conv2d_3 (Conv2D) │ (None, 13, 13, 64) │ 36,928 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_3 (Activation) │ (None, 13, 13, 64) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ max_pooling2d_1 (MaxPooling2D) │ (None, 6, 6, 64) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout_1 (Dropout) │ (None, 6, 6, 64) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ flatten (Flatten) │ (None, 2304) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dense (Dense) │ (None, 512) │ 1,180,160 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_4 (Activation) │ (None, 512) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dropout_2 (Dropout) │ (None, 512) │ 0 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ dense_1 (Dense) │ (None, 10) │ 5,130 │\n","├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n","│ activation_5 (Activation) │ (None, 10) │ 0 │\n","└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[1m Total params: \u001b[0m\u001b[38;5;34m1,250,858\u001b[0m (4.77 MB)\n"],"text/html":[" Total params: 1,250,858 (4.77 MB)\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m1,250,858\u001b[0m (4.77 MB)\n"],"text/html":[" Trainable params: 1,250,858 (4.77 MB)\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n"],"text/html":[" Non-trainable params: 0 (0.00 B)\n","
\n"]},"metadata":{}}]},{"cell_type":"code","source":["from tensorflow.keras.optimizers import Adam\n","\n","model.compile(optimizer=Adam(learning_rate=0.001),\n"," loss='categorical_crossentropy',\n"," metrics=['accuracy'])"],"metadata":{"id":"Ouh0oAs2Ok5_","executionInfo":{"status":"ok","timestamp":1733275400369,"user_tz":-540,"elapsed":264,"user":{"displayName":"황지원","userId":"01099698570160424720"}}},"execution_count":6,"outputs":[]},{"cell_type":"code","source":["history = model.fit(x_train, y_train,\n"," batch_size=batch_size,\n"," epochs=epochs,\n"," validation_data=(x_test, y_test),\n"," shuffle=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"tFcSRLjwP7Md","executionInfo":{"status":"ok","timestamp":1733275583714,"user_tz":-540,"elapsed":181586,"user":{"displayName":"황지원","userId":"01099698570160424720"}},"outputId":"3cb0b8dc-86cd-4342-831f-aea6880cda3e"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["Epoch 1/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m18s\u001b[0m 8ms/step - accuracy: 0.3391 - loss: 1.7770 - val_accuracy: 0.5835 - val_loss: 1.1544\n","Epoch 2/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m12s\u001b[0m 5ms/step - accuracy: 0.5852 - loss: 1.1565 - val_accuracy: 0.6666 - val_loss: 0.9254\n","Epoch 3/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.6601 - loss: 0.9585 - val_accuracy: 0.6949 - val_loss: 0.8740\n","Epoch 4/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.6969 - loss: 0.8537 - val_accuracy: 0.7167 - val_loss: 0.8012\n","Epoch 5/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.7166 - loss: 0.8056 - val_accuracy: 0.7430 - val_loss: 0.7391\n","Epoch 6/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.7375 - loss: 0.7515 - val_accuracy: 0.7589 - val_loss: 0.6972\n","Epoch 7/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.7506 - loss: 0.7052 - val_accuracy: 0.7678 - val_loss: 0.6748\n","Epoch 8/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.7622 - loss: 0.6690 - val_accuracy: 0.7476 - val_loss: 0.7262\n","Epoch 9/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m12s\u001b[0m 5ms/step - accuracy: 0.7727 - loss: 0.6430 - val_accuracy: 0.7708 - val_loss: 0.6646\n","Epoch 10/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.7856 - loss: 0.6121 - val_accuracy: 0.7751 - val_loss: 0.6579\n","Epoch 11/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.7913 - loss: 0.5902 - val_accuracy: 0.7688 - val_loss: 0.6792\n","Epoch 12/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.7928 - loss: 0.5859 - val_accuracy: 0.7846 - val_loss: 0.6281\n","Epoch 13/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 4ms/step - accuracy: 0.8015 - loss: 0.5587 - val_accuracy: 0.7875 - val_loss: 0.6388\n","Epoch 14/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 4ms/step - accuracy: 0.8054 - loss: 0.5511 - val_accuracy: 0.7831 - val_loss: 0.6376\n","Epoch 15/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.8108 - loss: 0.5380 - val_accuracy: 0.7855 - val_loss: 0.6367\n","Epoch 16/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 4ms/step - accuracy: 0.8147 - loss: 0.5268 - val_accuracy: 0.7903 - val_loss: 0.6240\n","Epoch 17/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.8188 - loss: 0.5127 - val_accuracy: 0.7909 - val_loss: 0.6292\n","Epoch 18/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m11s\u001b[0m 4ms/step - accuracy: 0.8240 - loss: 0.5044 - val_accuracy: 0.7760 - val_loss: 0.6655\n","Epoch 19/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.8275 - loss: 0.4970 - val_accuracy: 0.7817 - val_loss: 0.6755\n","Epoch 20/20\n","\u001b[1m1563/1563\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 4ms/step - accuracy: 0.8321 - loss: 0.4833 - val_accuracy: 0.7771 - val_loss: 0.6703\n"]}]},{"cell_type":"code","source":["%matplotlib inline\n","\n","fig, axs = plt.subplots(1,2,figsize=(15,5))\n","\n","# summarize history for accuracy\n","axs[0].plot(history.history['accuracy'])\n","axs[0].plot(history.history['val_accuracy'])\n","axs[0].set_title('Model Accuracy')\n","axs[0].set_ylabel('Accuracy')\n","axs[0].set_xlabel('Epoch')\n","axs[0].legend(['train', 'validate'], loc='upper left')\n","\n","# summarize history for loss\n","axs[1].plot(history.history['loss'])\n","axs[1].plot(history.history['val_loss'])\n","axs[1].set_title('Model Loss')\n","axs[1].set_ylabel('Loss')\n","axs[1].set_xlabel('Epoch')\n","axs[1].legend(['train', 'validate'], loc='upper left')\n","plt.show()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":487},"id":"InwcPZgyQeqJ","executionInfo":{"status":"ok","timestamp":1733275692749,"user_tz":-540,"elapsed":881,"user":{"displayName":"황지원","userId":"01099698570160424720"}},"outputId":"ab6acb4e-866b-4ff0-c021-ace6c8b8b651"},"execution_count":8,"outputs":[{"output_type":"display_data","data":{"text/plain":["