Upload Untitled.ipynb
This commit is contained in:
parent
3b9ea07ad9
commit
536179fd6e
126
Untitled.ipynb
Normal file
126
Untitled.ipynb
Normal file
@ -0,0 +1,126 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "a914d431-18c5-4055-a09e-1262dfb48ff9",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-09-24T04:08:33.164002Z",
|
||||
"iopub.status.busy": "2025-09-24T04:08:33.163761Z",
|
||||
"iopub.status.idle": "2025-09-24T04:08:35.375599Z",
|
||||
"shell.execute_reply": "2025-09-24T04:08:35.374666Z",
|
||||
"shell.execute_reply.started": "2025-09-24T04:08:33.163978Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"모델 학습이 완료되었습니다.\n",
|
||||
"X (피처 데이터):\n",
|
||||
" age income city\n",
|
||||
"0 25 50000 Seoul\n",
|
||||
"1 34 75000 Busan\n",
|
||||
"2 45 120000 Seoul\n",
|
||||
"3 23 45000 Jeju\n",
|
||||
"4 56 90000 Busan\n",
|
||||
"\n",
|
||||
"y (타겟 데이터):\n",
|
||||
"[0 1 1 0 1]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import xgboost as xgb\n",
|
||||
"\n",
|
||||
"# 모델 정의 (제공된 모델 파라미터 사용)\n",
|
||||
"model = xgb.XGBClassifier(\n",
|
||||
" device='cuda',\n",
|
||||
" tree_method='hist',\n",
|
||||
" enable_categorical=True,\n",
|
||||
" eval_metric='aucpr',\n",
|
||||
" objective='binary:logistic',\n",
|
||||
" max_depth=3,\n",
|
||||
" n_estimators=5\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# 1. 샘플 데이터 X 생성\n",
|
||||
"# 숫자형(수치형) 피처 'age'와 'income'\n",
|
||||
"# 범주형 피처 'city'를 포함합니다.\n",
|
||||
"# enable_categorical=True 설정에 맞춰 'city' 열을 'category' dtype으로 지정합니다.\n",
|
||||
"data = {\n",
|
||||
" 'age': [25, 34, 45, 23, 56],\n",
|
||||
" 'income': [50000, 75000, 120000, 45000, 90000],\n",
|
||||
" 'city': ['Seoul', 'Busan', 'Seoul', 'Jeju', 'Busan']\n",
|
||||
"}\n",
|
||||
"X = pd.DataFrame(data)\n",
|
||||
"X['city'] = X['city'].astype('category')\n",
|
||||
"\n",
|
||||
"# 2. 샘플 타겟 데이터 y 생성\n",
|
||||
"# 이진 분류를 위한 레이블 (0 또는 1)\n",
|
||||
"y = np.array([0, 1, 1, 0, 1])\n",
|
||||
"\n",
|
||||
"# 3. 모델 학습\n",
|
||||
"# model.fit(X, y)를 사용하여 모델에 데이터 주입\n",
|
||||
"model.fit(X, y)\n",
|
||||
"\n",
|
||||
"print(\"모델 학습이 완료되었습니다.\")\n",
|
||||
"print(\"X (피처 데이터):\")\n",
|
||||
"print(X)\n",
|
||||
"print(\"\\ny (타겟 데이터):\")\n",
|
||||
"print(y)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "08df20fd-1f32-42e6-839b-1301df4d9bfe",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-09-24T04:08:37.983399Z",
|
||||
"iopub.status.busy": "2025-09-24T04:08:37.982660Z",
|
||||
"iopub.status.idle": "2025-09-24T04:08:38.002455Z",
|
||||
"shell.execute_reply": "2025-09-24T04:08:38.000715Z",
|
||||
"shell.execute_reply.started": "2025-09-24T04:08:37.983337Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.save_model('xgboost.json')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d57d4529-1e88-4214-9efe-4633bd388f1a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "torch2.8.0-py3.12-cuda12.8",
|
||||
"language": "python",
|
||||
"name": "torch2.8.0-py3.12-cuda12.8"
|
||||
},
|
||||
"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.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user