Skip to content

Commit

Permalink
Merge pull request #70 from dohuyduc2002/feature/module3_week5
Browse files Browse the repository at this point in the history
Rm OVH key
  • Loading branch information
dohuyduc2002 authored Sep 23, 2024
2 parents 6588d2f + 23e866c commit 9db549c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"from sys import path\n",
"from simple_utils import *\n",
"import os\n",
"\n",
"path.append('/Users/microwave/AIO_2024/Module_2/Image_retrieval/utils')\n",
"from query import plot_results"
"from utils.query import plot_results"
]
},
{
Expand All @@ -27,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"ROOT = '/Users/microwave/AIO_2024/Module_2/Image_retrieval/data'\n",
"ROOT = os.getenv('IMAGE_RETRIEVAL_ROOT', '/default/path/to/data')\n",
"CLASS_NAME = sorted(list(os.listdir(f'{ROOT}/train')))"
]
},
Expand Down
79 changes: 54 additions & 25 deletions Module_3/Week5/exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,7 +14,8 @@
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import OrdinalEncoder, LabelEncoder\n",
"import os\n",
"import warnings"
"import warnings\n",
"from xgboost import XGBClassifier"
]
},
{
Expand All @@ -26,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -277,20 +278,19 @@
"[510 rows x 13 columns]"
]
},
"execution_count": 2,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PATH = os.chdir('/Users/microwave/AIO_2024/Module_3/Week5')\n",
"df = pd.read_csv('Problem 3.csv')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -321,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -334,9 +334,17 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/microwave/opt/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py:2815: RuntimeWarning: invalid value encountered in cast\n",
" _data = np.array(data, dtype=dtype, copy=copy,\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand Down Expand Up @@ -370,7 +378,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -400,7 +408,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -553,7 +561,7 @@
"4 2.93 735.0 0 "
]
},
"execution_count": 7,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -565,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -577,18 +585,23 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'XGBRegressor' object has no attribute 'XGBClassifier'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [9]\u001b[0m, in \u001b[0;36m<cell line: 9>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m params \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobjective\u001b[39m\u001b[38;5;124m'\u001b[39m: [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbinary:logistic\u001b[39m\u001b[38;5;124m'\u001b[39m],\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlearning_rate\u001b[39m\u001b[38;5;124m'\u001b[39m: [\u001b[38;5;241m0.01\u001b[39m, \u001b[38;5;241m0.02\u001b[39m, \u001b[38;5;241m0.03\u001b[39m, \u001b[38;5;241m0.04\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgamma\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m3\u001b[39m)\n\u001b[1;32m 7\u001b[0m }\n\u001b[0;32m----> 9\u001b[0m xgb_clf \u001b[38;5;241m=\u001b[39m \u001b[43mxgb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mXGBClassifier\u001b[49m()\n\u001b[1;32m 10\u001b[0m xgb_grid_clf \u001b[38;5;241m=\u001b[39m GridSearchCV(xgb_clf, params, cv\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m, n_jobs\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m3\u001b[39m)\n\u001b[1;32m 11\u001b[0m xgb_grid_clf\u001b[38;5;241m.\u001b[39mfit(X_train, y_train)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'XGBRegressor' object has no attribute 'XGBClassifier'"
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/microwave/opt/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py:2815: RuntimeWarning: invalid value encountered in cast\n",
" _data = np.array(data, dtype=dtype, copy=copy,\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Best params for XGB Classifier: {'gamma': 2, 'learning_rate': 0.02, 'max_depth': 3, 'n_estimators': 103, 'objective': 'binary:logistic'}\n",
"Best score for XGB Classifier: 0.9435483870967742\n"
]
}
],
Expand All @@ -601,7 +614,7 @@
" 'gamma': range(0, 3)\n",
"}\n",
"\n",
"xgb_clf = xgb.XGBClassifier()\n",
"xgb_clf = XGBClassifier()\n",
"xgb_grid_clf = GridSearchCV(xgb_clf, params, cv=2, n_jobs=3)\n",
"xgb_grid_clf.fit(X_train, y_train)\n",
"\n",
Expand All @@ -611,7 +624,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -621,16 +634,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train accuracy: 1.0\n",
"Test accuracy 0.9629629629629629\n"
]
}
],
"source": [
"train_acc = accuracy_score(y_train, y_train_pred,)\n",
"test_acc = accuracy_score(y_test,y_pred)\n",
"\n",
"print(f'Train accuracy: {train_acc}')\n",
"print(f'Test accuracy {test_acc}')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 9db549c

Please sign in to comment.