From d2925a3d0c8673a4f41e3b6a781b83d818274a62 Mon Sep 17 00:00:00 2001 From: "shoney.arickathil" Date: Sun, 16 Jul 2023 02:06:29 +0200 Subject: [PATCH] update doc --- doc/chapters/chapter3.tex | 9 +++--- doc/chapters/chapter4.tex | 36 +++++++++++---------- fetchDatafromDb/getProductDescriptionCat.es | 2 +- rm_clasificationmodel/DataFrameClass.py | 12 +++++-- rm_clasificationmodel/ElasticSearchClass.py | 7 ++-- rm_clasificationmodel/KNN.py | 4 +++ 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/doc/chapters/chapter3.tex b/doc/chapters/chapter3.tex index 0e9ac8d..f3625cd 100644 --- a/doc/chapters/chapter3.tex +++ b/doc/chapters/chapter3.tex @@ -19,7 +19,7 @@ In table \ref{table:TN}, displays the difference in text before and after normal \end{tabular} \end{table} -\subsection{Lower case} +\section{Lower case} Using Pandas - vectorized string method, a text can be lower cased across the document. These methos exclude the missing / NA values automatically \parencite{mckinney-proc-scipy-2010}. @@ -27,7 +27,7 @@ Using Pandas - vectorized string method, a text can be lower cased across the do df_de["name"]= df_de["name"].str.lower() \end{lstlisting} -\subsection{Html parsing} +\section{Html parsing} Probability of getting html tags in a document increases if the source of document is from web scraping or also if the document from database source has inline html tags. In such case, fetching normal texts from a html text is required. One of the method would be to use regular expressions to get text in between angel brackets \textless \textgreater text \textless \textgreater. However, this method would require to have the tags to be well formed. \begin{lstlisting}[language=Python] @@ -43,8 +43,7 @@ The better option would be to use Beautiful Soup \footnote{https://www.crummy.co text =soup.get_text() \end{lstlisting} -\subsection{Cleanning text} - +\section{Cleanning text} A product detail text may contain non-word characters represented in regular expression as \textbackslash W. It may also contain space seperated decimals describing the dimentional values of the product such as weight, height. Regular expressions could be used for removing the non-character words and spaces between the decimal values. \begin{lstlisting}[language=Python] @@ -52,7 +51,7 @@ A product detail text may contain non-word characters represented in regular exp text = (re.sub('(?<=\d) (?=\d)', '', text)) \end{lstlisting} -\subsection{Normal form D - Unicode database} +\section{Normal form D - Unicode database} A product name in Deutsch language may contain umlaute characters such as \"A. Pythons unicodedata \footnote{https://docs.python.org/3/library/unicodedata.html} module provides access to the Unicode Character Database (UCD) which defines the character properties for all Unicode characters. To change \"A to A, the Normal form D (NFD) should be applied which translated each character into its decomposed form. Further the text can be refined with the general category assigned to the character as string. Nonspacing mark characters \footnote{https://www.compart.com/en/unicode/category/Mn} are represented as "Mn". These characters could be removed by referring the the character category. \begin{lstlisting}[language=Python] diff --git a/doc/chapters/chapter4.tex b/doc/chapters/chapter4.tex index 3baaf3f..1dbe190 100644 --- a/doc/chapters/chapter4.tex +++ b/doc/chapters/chapter4.tex @@ -48,7 +48,7 @@ Mode imputation on categorical data are prone to fill incorrect data if the miss \section{\textit{k}-Nearest Neighbors imputation} -k-Nearest Neighbor is a supervised learning algorithm is used to search dataset with the most similar elements to a given query element, with similarity defined by a distance function. +k-Nearest Neighbor is a supervised learning algorithm is used to search dataset with the most similar elements to a given query element, with similarity defined by a distance function. This imputation method is suitable for categorical data. The most common distance functions are:- @@ -79,28 +79,30 @@ As per \parencite{scikit-learn}, larger \textit{k} suppresses the effects of noi \subsection{KNN model implementation} -In table \ref{table:KNN_implementation} there are nine columns. Target column is 'catL3' which is the category at level three. +In table \ref{table:KNN_implementation} there are 8 columns. Target column is 'catL3' which is the category at level three. + + \begin{table}[h] \centering \caption{Data frame head} \label{table:KNN_implementation} - \begin{tabular}{ lll } - \toprule - - \textbf{No}& \textbf{Feature} & \textbf{Categorical}\\ - \midrule - 1&Product name & No\\ - 3&Description & No\\ - 4&Short description & No\\ - 5&Supplier & Yes\\ - 6&Manufacturer & Yes\\ - 7&Price & No \\ - 8&Dimension & Yes\\ - \bottomrule - \end{tabular} -\end{table} + \begin{tabular}{llll} + \toprule id & name & shortDesc & Desc \\ + \midrule + 1&DENSO DTM82363 & NaN & NaN \\ + \bottomrule +\end{tabular} + +\begin{tabular}{llll} + \toprule catL1 & catL2 & catL3 & catL4\\ + \midrule + + SparePart & Cooling System & Thermostat & NaN \\ + \bottomrule +\end{tabular} +\end{table} diff --git a/fetchDatafromDb/getProductDescriptionCat.es b/fetchDatafromDb/getProductDescriptionCat.es index 2695fc6..641eb32 100644 --- a/fetchDatafromDb/getProductDescriptionCat.es +++ b/fetchDatafromDb/getProductDescriptionCat.es @@ -1,4 +1,4 @@ -Get retromotion-indexer_development_products/_search +POST retromotion-indexer_development_products/_search { "_source":["_id","descriptions","descriptionsSource","nameSource","shortDescriptionSource","categoriesSource"] // "query": { diff --git a/rm_clasificationmodel/DataFrameClass.py b/rm_clasificationmodel/DataFrameClass.py index 16dbb8a..292f63d 100644 --- a/rm_clasificationmodel/DataFrameClass.py +++ b/rm_clasificationmodel/DataFrameClass.py @@ -178,7 +178,7 @@ class DataFrame: def setDfProductTaxonomy(self,lang='en'): resp=self.es.searchDevelopmentProducts() - df = pd.DataFrame(columns=["id",'name','shortDesc','Desc','catL1','catL2','catL3','catL4','catL5']) + df = pd.DataFrame(columns=["id",'name','shortDesc','Desc','category','catL1','catL2','catL3','catL4','catL5']) for hit in resp['hits']['hits']: list_row = dict (id=None,name=None,shortDesc=None,Desc=None,catL1=None,catL2=None,catL3=None,catL4=None,catL5=None) @@ -186,7 +186,15 @@ class DataFrame: list_row["id"]=hit['_id'] for name in hit['_source']['nameSource']: if (name["language"]==lang): - list_row["name"]=name["value"] + list_row["name"]=name["value"] + + for sd in hit['_source']['shortDescriptionSource']: + if (name["language"]==lang): + list_row["shortDesc"]=sd["value"] + + for ds in hit['_source']['descriptionsSource']: + if (name["language"]==lang): + list_row["Desc"]=ds["value"] for cats in hit['_source']['categoriesSource']: diff --git a/rm_clasificationmodel/ElasticSearchClass.py b/rm_clasificationmodel/ElasticSearchClass.py index 0a87575..db8d970 100644 --- a/rm_clasificationmodel/ElasticSearchClass.py +++ b/rm_clasificationmodel/ElasticSearchClass.py @@ -50,8 +50,8 @@ class ElasticSearchDb: self.ingest('english-false-prediction', val, 'category_prediction') def searchDevelopmentProducts(self): - resp = self.es.search("retromotion-indexer_development_products", - { + resp = self.es.search(index="retromotion-indexer_development_products", + body={ "_source": ["_id", "descriptions", @@ -59,7 +59,8 @@ class ElasticSearchDb: "nameSource", "shortDescriptionSource", "categoriesSource" - ] + ], + "size":65000 }) diff --git a/rm_clasificationmodel/KNN.py b/rm_clasificationmodel/KNN.py index 569f341..105bbca 100644 --- a/rm_clasificationmodel/KNN.py +++ b/rm_clasificationmodel/KNN.py @@ -1,3 +1,7 @@ + +from sklearn.model_selection import train_test_split +from sklearn.neighbors import KNeighborsClassifier + class KNN(): def __init__(self) -> None: pass