{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>phase_no</th>\n",
|
|
" <th>ring_type</th>\n",
|
|
" <th>move_no</th>\n",
|
|
" <th>angle_code</th>\n",
|
|
" <th>inc_edge_id</th>\n",
|
|
" <th>out_edge_id</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>357140</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e6</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>357088</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e4</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>357140</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e6</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>142359</td>\n",
|
|
" <td>e5</td>\n",
|
|
" <td>e2</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" phase_no ring_type move_no angle_code inc_edge_id out_edge_id\n",
|
|
"0 1 A 4 357140 e1 e6\n",
|
|
"1 1 B 7 357088 e1 e4\n",
|
|
"2 2 A 4 357140 e1 e6\n",
|
|
"3 2 B 8 142359 e5 e2"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>phase_no</th>\n",
|
|
" <th>ring_type</th>\n",
|
|
" <th>move_no</th>\n",
|
|
" <th>angle_code</th>\n",
|
|
" <th>inc_edge_id</th>\n",
|
|
" <th>out_edge_id</th>\n",
|
|
" <th>inc_angle</th>\n",
|
|
" <th>out_angle</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>357140</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e6</td>\n",
|
|
" <td>357</td>\n",
|
|
" <td>140</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>357088</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e4</td>\n",
|
|
" <td>357</td>\n",
|
|
" <td>88</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>357140</td>\n",
|
|
" <td>e1</td>\n",
|
|
" <td>e6</td>\n",
|
|
" <td>357</td>\n",
|
|
" <td>140</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>142359</td>\n",
|
|
" <td>e5</td>\n",
|
|
" <td>e2</td>\n",
|
|
" <td>142</td>\n",
|
|
" <td>359</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" phase_no ring_type move_no angle_code inc_edge_id out_edge_id inc_angle \\\n",
|
|
"0 1 A 4 357140 e1 e6 357 \n",
|
|
"1 1 B 7 357088 e1 e4 357 \n",
|
|
"2 2 A 4 357140 e1 e6 357 \n",
|
|
"3 2 B 8 142359 e5 e2 142 \n",
|
|
"\n",
|
|
" out_angle \n",
|
|
"0 140 \n",
|
|
"1 88 \n",
|
|
"2 140 \n",
|
|
"3 359 "
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[[357]\n",
|
|
" [140]\n",
|
|
" [357]\n",
|
|
" [ 88]\n",
|
|
" [357]\n",
|
|
" [140]\n",
|
|
" [142]\n",
|
|
" [359]]\n",
|
|
"[0 1 0 2 0 1 1 0]\n",
|
|
"[[357.5 ]\n",
|
|
" [140.66666667]\n",
|
|
" [ 88. ]]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c:\\Github\\sts\\sts\\lib\\site-packages\\sklearn\\cluster\\_kmeans.py:1416: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning\n",
|
|
" super()._check_params_vs_input(X, default_n_init=10)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"data = [\n",
|
|
" [1, 'A', 4, '357140', 'e1', 'e6'],\n",
|
|
" [1, 'B', 7, '357088', 'e1', 'e4'],\n",
|
|
" [2, 'A', 4, '357140', 'e1', 'e6'],\n",
|
|
" [2, 'B', 8, '142359', 'e5', 'e2']\n",
|
|
"]\n",
|
|
"\n",
|
|
"df = pd.DataFrame(data,\n",
|
|
" columns=['phase_no', 'ring_type', 'move_no', 'angle_code', 'inc_edge_id', 'out_edge_id'])\n",
|
|
"display(df)\n",
|
|
"df['inc_angle'] = df['angle_code'].apply(lambda x:int(x[:3]))\n",
|
|
"df['out_angle'] = df['angle_code'].apply(lambda x:int(x[3:]))\n",
|
|
"display(df)\n",
|
|
"\n",
|
|
"angles = df[['inc_angle', 'out_angle']].values.flatten().reshape(-1, 1)\n",
|
|
"angles\n",
|
|
"\n",
|
|
"from sklearn.cluster import KMeans\n",
|
|
"# K-means 모델 생성 및 학습 (k=3)\n",
|
|
"kmeans = KMeans(n_clusters=3, random_state=0).fit(angles)\n",
|
|
"\n",
|
|
"# 클러스터링 결과\n",
|
|
"labels = kmeans.labels_\n",
|
|
"\n",
|
|
"# 클러스터 중심점 출력\n",
|
|
"centroids = kmeans.cluster_centers_\n",
|
|
"print(angles)\n",
|
|
"print(labels)\n",
|
|
"print(centroids)\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "sts",
|
|
"language": "python",
|
|
"name": "sts"
|
|
},
|
|
"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.8.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|