classification model
This commit is contained in:
parent
8e90a00db7
commit
32b50e3cde
2 changed files with 257 additions and 68 deletions
|
|
@ -22,4 +22,7 @@ Eingabe Ausgabe
|
|||
\Iac{ecu} A ECU
|
||||
\acused{ecu}
|
||||
\acsu{ecu} ECU
|
||||
\aclu{ecu} European currency unit
|
||||
\aclu{ecu} European currency unit
|
||||
|
||||
|
||||
https://www.kaggle.com/datasets/lakritidis/product-classification-and-categorization
|
||||
|
|
@ -1,5 +1,43 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"15865.52s - pydevd: Sending message related to process being replaced timed-out after 5 seconds\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Collecting scikit-learn\n",
|
||||
" Downloading scikit_learn-1.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.6 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.6/9.6 MB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: numpy>=1.17.3 in /home/shoney/.local/lib/python3.10/site-packages (from scikit-learn) (1.24.3)\n",
|
||||
"Collecting scipy>=1.3.2\n",
|
||||
" Downloading scipy-1.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.4 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m34.4/34.4 MB\u001b[0m \u001b[31m6.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting joblib>=1.1.1\n",
|
||||
" Downloading joblib-1.2.0-py3-none-any.whl (297 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m298.0/298.0 KB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting threadpoolctl>=2.0.0\n",
|
||||
" Downloading threadpoolctl-3.1.0-py3-none-any.whl (14 kB)\n",
|
||||
"Installing collected packages: threadpoolctl, scipy, joblib, scikit-learn\n",
|
||||
"Successfully installed joblib-1.2.0 scikit-learn-1.2.2 scipy-1.10.1 threadpoolctl-3.1.0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!python3 -m pip install scikit-learn"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
|
|
@ -53,26 +91,44 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 55,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ModuleNotFoundError",
|
||||
"evalue": "No module named 'seaborn'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[55], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39msklearn\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mmatplotlib\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpyplot\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mplt\u001b[39;00m\n\u001b[0;32m----> 7\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mseaborn\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39msns\u001b[39;00m\n",
|
||||
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'seaborn'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd"
|
||||
"import pandas as pd\n",
|
||||
"import re\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"import sklearn\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import seaborn as sns"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_eng = pd.DataFrame(columns=['name','sdesc','desc','category','categorypath'])\n",
|
||||
"df_eng = pd.DataFrame(columns=['name','sdesc','category','catlevel0','catlevel1','catlevel2','catlevel3','catlevel4','catlevel5'])\n",
|
||||
"df_de = pd.DataFrame(columns=['name','sdesc','desc','category','categorypath'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
|
@ -98,9 +154,13 @@
|
|||
" <th></th>\n",
|
||||
" <th>name</th>\n",
|
||||
" <th>sdesc</th>\n",
|
||||
" <th>desc</th>\n",
|
||||
" <th>category</th>\n",
|
||||
" <th>categorypath</th>\n",
|
||||
" <th>catlevel0</th>\n",
|
||||
" <th>catlevel1</th>\n",
|
||||
" <th>catlevel2</th>\n",
|
||||
" <th>catlevel3</th>\n",
|
||||
" <th>catlevel4</th>\n",
|
||||
" <th>catlevel5</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
|
|
@ -110,11 +170,11 @@
|
|||
],
|
||||
"text/plain": [
|
||||
"Empty DataFrame\n",
|
||||
"Columns: [name, sdesc, desc, category, categorypath]\n",
|
||||
"Columns: [name, sdesc, category, catlevel0, catlevel1, catlevel2, catlevel3, catlevel4, catlevel5]\n",
|
||||
"Index: []"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
|
@ -125,7 +185,42 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def cleanStr(text):\n",
|
||||
" \n",
|
||||
" # remove numbers\n",
|
||||
" # no_number_string = re.sub(r'\\d+','',lower_string)\n",
|
||||
"\n",
|
||||
" # remove all punctuation except words and space\n",
|
||||
" # text = re.sub(r'[^\\w\\s]','', lower_string)\n",
|
||||
"\n",
|
||||
" # clean = re.compile('<.*?>')\n",
|
||||
"\n",
|
||||
" # text = re.sub(clean,'',text)\n",
|
||||
" text = re.sub('<[^>]*>', '', text)\n",
|
||||
" emoticons = re.findall('(?::|;|=)(?:-)?(?:\\)|\\(|D|P)', text)\n",
|
||||
" text = (re.sub('[\\W]+', ' ', text.lower()) + ' ' .join(emoticons).replace('-', ''))\n",
|
||||
"\n",
|
||||
" return text\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def readHtml(html):\n",
|
||||
" dftable = pd.read_html(html)\n",
|
||||
" return dftable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -145,47 +240,65 @@
|
|||
"catpath_de=[]\n",
|
||||
"\n",
|
||||
"for hit in resp['hits']['hits']:\n",
|
||||
" list_row =[]\n",
|
||||
" for name in hit['_source']['nameSource']:\n",
|
||||
" if (name[\"language\"]==\"en\"):\n",
|
||||
" name_en.append(name[\"value\"])\n",
|
||||
" list_row.append(cleanStr(name[\"value\"]))\n",
|
||||
" else:\n",
|
||||
" name_de.append(name[\"value\"])\n",
|
||||
" \n",
|
||||
" for sdesc in hit['_source']['shortDescriptionSource']:\n",
|
||||
" if (sdesc[\"language\"]==\"en\"):\n",
|
||||
" sdesc_en.append(sdesc[\"value\"])\n",
|
||||
" list_row.append(cleanStr(sdesc[\"value\"]))\n",
|
||||
" else:\n",
|
||||
" sdesc_de.append(sdesc[\"value\"])\n",
|
||||
"\n",
|
||||
" for desc in hit['_source']['descriptionsSource']:\n",
|
||||
" if (desc[\"language\"]==\"en\"):\n",
|
||||
" desc_en.append(desc[\"value\"])\n",
|
||||
" else:\n",
|
||||
" desc_de.append(desc[\"value\"])\n",
|
||||
" # for desc in hit['_source']['descriptionsSource']:\n",
|
||||
" # if (desc[\"language\"]==\"en\"):\n",
|
||||
" # desc_en.append(readHtml(desc[\"value\"]))\n",
|
||||
" # else:\n",
|
||||
" # desc_de.append(desc[\"value\"])\n",
|
||||
" \n",
|
||||
" for cats in hit['_source']['categoriesSource']:\n",
|
||||
" if (cats[\"language\"]==\"en\"):\n",
|
||||
" cat_en.append(cats[\"label\"])\n",
|
||||
" list_row.append(cleanStr(cats[\"label\"]))\n",
|
||||
" else:\n",
|
||||
" desc_de.append(cats[\"label\"])\n",
|
||||
"\n",
|
||||
" if (cats[\"language\"]==\"en\"):\n",
|
||||
" catpath_en.append(cats[\"path\"])\n",
|
||||
" categories =cats[\"path\"].split('/')\n",
|
||||
" i =0\n",
|
||||
" catls=[]\n",
|
||||
" for category in categories:\n",
|
||||
"\n",
|
||||
" list_row.append(cleanStr(category))\n",
|
||||
" i= i+1\n",
|
||||
" \n",
|
||||
" else:\n",
|
||||
" catpath_de.append(cats[\"path\"])\n"
|
||||
" catpath_de.append(cats[\"path\"])\n",
|
||||
" \n",
|
||||
" # new_row = pd.DataFrame({'name':_name, 'sdesc':_sdesc, 'category':_cat_en }, index=[0])\n",
|
||||
"\n",
|
||||
" # pd.concat([new_row,df_eng.loc[:]]).reset_index(drop=True)\n",
|
||||
"\n",
|
||||
" for i in range (0,9-len(list_row)):\n",
|
||||
" list_row.append(np.nan)\n",
|
||||
"\n",
|
||||
" df_eng.loc[len(df_eng)] = list_row\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_en = pd.DataFrame({'name':name_en,\n",
|
||||
" 'sdesc':sdesc_en,\n",
|
||||
" 'desc':desc_en,\n",
|
||||
" 'category':cat_en,\n",
|
||||
" 'categorypath':catpath_en})\n",
|
||||
"# df_en = pd.DataFrame({'name':name_en,\n",
|
||||
"# 'sdesc':sdesc_en,\n",
|
||||
"# # 'desc':desc_en,\n",
|
||||
"# 'category':cat_en,\n",
|
||||
"# 'categorypath':catpath_en})\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# df_de = pd.DataFrame({'name':name_de,\n",
|
||||
|
|
@ -197,7 +310,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 50,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
|
@ -223,51 +336,75 @@
|
|||
" <th></th>\n",
|
||||
" <th>name</th>\n",
|
||||
" <th>sdesc</th>\n",
|
||||
" <th>desc</th>\n",
|
||||
" <th>category</th>\n",
|
||||
" <th>categorypath</th>\n",
|
||||
" <th>catlevel0</th>\n",
|
||||
" <th>catlevel1</th>\n",
|
||||
" <th>catlevel2</th>\n",
|
||||
" <th>catlevel3</th>\n",
|
||||
" <th>catlevel4</th>\n",
|
||||
" <th>catlevel5</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>DENSO DTM82363 Thermostat, coolant</td>\n",
|
||||
" <td>Thermostat, coolant</td>\n",
|
||||
" <td><div class='criterias'><table class='criterias...</td>\n",
|
||||
" <td>denso dtm82363 thermostat coolant</td>\n",
|
||||
" <td>thermostat coolant</td>\n",
|
||||
" <td>thermostat</td>\n",
|
||||
" <td>SparePart</td>\n",
|
||||
" <td>Cooling System</td>\n",
|
||||
" <td>Thermostat</td>\n",
|
||||
" <td>SparePart/Cooling System/Thermostat</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>ZF 1043.010.297 Automatic Transmission</td>\n",
|
||||
" <td>zf 1043 010 297 automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>SparePart</td>\n",
|
||||
" <td>Transmission</td>\n",
|
||||
" <td>Automatic Transmission</td>\n",
|
||||
" <td><div class='criterias'><table class='criterias...</td>\n",
|
||||
" <td>Automatic Transmission</td>\n",
|
||||
" <td>SparePart/Transmission/Automatic Transmission/...</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>ZF 1060.040.003 Automatic Transmission</td>\n",
|
||||
" <td>zf 1060 040 003 automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>SparePart</td>\n",
|
||||
" <td>Transmission</td>\n",
|
||||
" <td>Automatic Transmission</td>\n",
|
||||
" <td><div class='criterias'><table class='criterias...</td>\n",
|
||||
" <td>Automatic Transmission</td>\n",
|
||||
" <td>SparePart/Transmission/Automatic Transmission/...</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>VAICO V10-0131 Camshaft</td>\n",
|
||||
" <td>vaico v10 0131 camshaft</td>\n",
|
||||
" <td>camshaft</td>\n",
|
||||
" <td>camshaft</td>\n",
|
||||
" <td>SparePart</td>\n",
|
||||
" <td>Engine</td>\n",
|
||||
" <td>Engine Timing</td>\n",
|
||||
" <td>Camshaft</td>\n",
|
||||
" <td><div class='criterias'><table class='criterias...</td>\n",
|
||||
" <td>Camshaft</td>\n",
|
||||
" <td>SparePart/Engine/Engine Timing/Camshaft</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>VAICO V26-0302 Track Control Arm</td>\n",
|
||||
" <td>vaico v26 0302 track control arm</td>\n",
|
||||
" <td>track control arm</td>\n",
|
||||
" <td>track control arm</td>\n",
|
||||
" <td>SparePart</td>\n",
|
||||
" <td>Powertrain & Suspension</td>\n",
|
||||
" <td>Wheel Suspension</td>\n",
|
||||
" <td>Track Control Arm</td>\n",
|
||||
" <td><div class='criterias'><table class='criterias...</td>\n",
|
||||
" <td>Track Control Arm</td>\n",
|
||||
" <td>SparePart/Powertrain & Suspension/Wheel Suspen...</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" <td>na</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
|
|
@ -275,34 +412,83 @@
|
|||
],
|
||||
"text/plain": [
|
||||
" name sdesc \\\n",
|
||||
"0 DENSO DTM82363 Thermostat, coolant Thermostat, coolant \n",
|
||||
"1 ZF 1043.010.297 Automatic Transmission Automatic Transmission \n",
|
||||
"2 ZF 1060.040.003 Automatic Transmission Automatic Transmission \n",
|
||||
"3 VAICO V10-0131 Camshaft Camshaft \n",
|
||||
"4 VAICO V26-0302 Track Control Arm Track Control Arm \n",
|
||||
"0 denso dtm82363 thermostat coolant thermostat coolant \n",
|
||||
"1 zf 1043 010 297 automatic transmission automatic transmission \n",
|
||||
"2 zf 1060 040 003 automatic transmission automatic transmission \n",
|
||||
"3 vaico v10 0131 camshaft camshaft \n",
|
||||
"4 vaico v26 0302 track control arm track control arm \n",
|
||||
"\n",
|
||||
" desc category \\\n",
|
||||
"0 <div class='criterias'><table class='criterias... Thermostat \n",
|
||||
"1 <div class='criterias'><table class='criterias... Automatic Transmission \n",
|
||||
"2 <div class='criterias'><table class='criterias... Automatic Transmission \n",
|
||||
"3 <div class='criterias'><table class='criterias... Camshaft \n",
|
||||
"4 <div class='criterias'><table class='criterias... Track Control Arm \n",
|
||||
" category catlevel0 catlevel1 \\\n",
|
||||
"0 thermostat SparePart Cooling System \n",
|
||||
"1 automatic transmission SparePart Transmission \n",
|
||||
"2 automatic transmission SparePart Transmission \n",
|
||||
"3 camshaft SparePart Engine \n",
|
||||
"4 track control arm SparePart Powertrain & Suspension \n",
|
||||
"\n",
|
||||
" categorypath \n",
|
||||
"0 SparePart/Cooling System/Thermostat \n",
|
||||
"1 SparePart/Transmission/Automatic Transmission/... \n",
|
||||
"2 SparePart/Transmission/Automatic Transmission/... \n",
|
||||
"3 SparePart/Engine/Engine Timing/Camshaft \n",
|
||||
"4 SparePart/Powertrain & Suspension/Wheel Suspen... "
|
||||
" catlevel2 catlevel3 catlevel4 catlevel5 \n",
|
||||
"0 Thermostat na na na \n",
|
||||
"1 Automatic Transmission Automatic Transmission na na \n",
|
||||
"2 Automatic Transmission Automatic Transmission na na \n",
|
||||
"3 Engine Timing Camshaft na na \n",
|
||||
"4 Wheel Suspension Track Control Arm na na "
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"execution_count": 50,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df_en.head()"
|
||||
"df_eng.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 51,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"name 0\n",
|
||||
"sdesc 0\n",
|
||||
"category 0\n",
|
||||
"catlevel0 0\n",
|
||||
"catlevel1 0\n",
|
||||
"catlevel2 0\n",
|
||||
"catlevel3 6\n",
|
||||
"catlevel4 30\n",
|
||||
"catlevel5 30\n",
|
||||
"dtype: int64"
|
||||
]
|
||||
},
|
||||
"execution_count": 51,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df_eng.isna().sum()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 52,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(40, 9)"
|
||||
]
|
||||
},
|
||||
"execution_count": 52,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df_eng.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue