doc
This commit is contained in:
parent
28602d10a3
commit
79c44ac681
5 changed files with 152 additions and 4 deletions
|
|
@ -49,8 +49,8 @@
|
|||
file = {55771015:Attachments/55771015.pdf:application/pdf}
|
||||
}
|
||||
|
||||
|
||||
@InProceedings{ mckinney-proc-scipy-2010,
|
||||
%pandas
|
||||
@InProceedings{mckinney-proc-scipy-2010,
|
||||
author = { {W}es {M}c{K}inney },
|
||||
title = { {D}ata {S}tructures for {S}tatistical {C}omputing in {P}ython },
|
||||
booktitle = { {P}roceedings of the 9th {P}ython in {S}cience {C}onference },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,88 @@
|
|||
Machine leaning algorithms requires that their inputs have no missing values.
|
||||
Missing values encoded as NaNs or blanks are incompatible with estimators which represents as the numerical values and assumes all values have and hold meaning. Discarding the entire row and/or columns of a dataset containing the missing values could lead to losing valuable data. The process to fill (impute) missing values are referred to as imputation.
|
||||
|
||||
\subsection{Feature imputation}
|
||||
\section{Feature imputation / Regression imputation / Predictive Imputation}
|
||||
|
||||
Machine learning algorithm to predict values in a categorical variable based on other available features. Table \ref{table:feature_imputation} states the categorical features from the all the features mentioned in \ref{table:feature_decription}.
|
||||
|
||||
|
||||
\begin{table}[h]
|
||||
\centering
|
||||
\caption{Feature imputation}
|
||||
\label{table:feature_imputation}
|
||||
\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}
|
||||
|
||||
The \textit{dimension} column is also considered as a categorical value as it has few unique values.
|
||||
|
||||
If \textit{supplier} is the missing value from the set of row. The missing \textit{supplier} data must be predicted only from the available list of suppliers. A supervised machine learning with labeled dataset to train the model to classify the available features data to predict \textit{supplier}. A tensor size of the number of unique \textit{supplier} will be the output of the model.
|
||||
In an iterated round-robin fashion, at every step a missing feature column \textit{y} and other feature columns treated as input \textit{x} predicts the missing values of \textit{y}. Regression imputation is more accurate than mode imputation on categorical value.
|
||||
|
||||
|
||||
\section{Mode imputation}
|
||||
|
||||
Replacing the most frequent categorical value in a column is known as mode imputation. Pandas.DataFrame.mode \parencite{mckinney-proc-scipy-2010} function returns most often value. Code snippet will fill the missing values for each column using its own most frequent value.
|
||||
|
||||
\begin{lstlisting}[language=Python]
|
||||
df = df.fillna(df.mode().iloc[0])
|
||||
\end{lstlisting}
|
||||
|
||||
Mode imputation on categorical data are prone to fill incorrect data if the missing data is not the most frequent one.
|
||||
|
||||
\section{Mean/median imputation}
|
||||
|
||||
Pandas.DataFrame.median \parencite{mckinney-proc-scipy-2010} returns the median value. These can be applied to the features represented in numerical value. In reference to table \ref{table:feature_imputation}, \textit{price} could be a column on which median value can be filled. However, using median to fill missing value could underestimate or overestimate the value.
|
||||
|
||||
\begin{enumerate}
|
||||
\item Median - The mid point value
|
||||
\item Mean - The average value
|
||||
\end{enumerate}
|
||||
|
||||
\begin{lstlisting}[language=Python]
|
||||
df = df.fillna(df.median().iloc[0])
|
||||
\end{lstlisting}
|
||||
|
||||
\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.
|
||||
|
||||
The most common distance functions are:-
|
||||
|
||||
\begin{enumerate}
|
||||
\item Eulidean distance.
|
||||
\item Manhattan distance.
|
||||
\item Hamming distance.
|
||||
\end{enumerate}
|
||||
|
||||
sklearn.neighbors.KNeighborsClassifier \parencite{scikit-learn} does an instance-based learning, it does not construct a model, but stores instance of training data. Classification is computed from majority vote of nearest neighbors of each point.
|
||||
|
||||
The \textit{k}-neighbors classification implements learning based on \textit{k} nearest neighbors of each query point, where \textit{K} is integer value specified by user.
|
||||
|
||||
The optimal \textit{k} value can be evaluated by iterating the classifier with different \textit{n\textunderscore neighbors} parameter and finding the minimum value of error rate.
|
||||
|
||||
\begin{lstlisting}[language=Python]
|
||||
error_rate = []
|
||||
for i in range(1,40):
|
||||
knn = KNeighborsClassifier(n_neighbors=i)
|
||||
knn.fit(X_train,y_train)
|
||||
pred_i = knn.predict(X_test)
|
||||
error_rate.append(np.mean(pred_i != y_test))
|
||||
|
||||
print("Minimum error:-",min(error_rate),"at K =",error_rate.index(min(error_rate)))
|
||||
\end{lstlisting}
|
||||
|
||||
As per \parencite{scikit-learn}, larger \textit{k} suppresses the effects of noise, but makes the classification boundaries less distinct.
|
||||
|
||||
In an iterated round-robin fashion, at every step a missing feature column \textit{y} and other feature columns treated as input \textit{x} predicts the missing values of \textit{y}.
|
||||
|
|
|
|||
|
|
@ -60,3 +60,32 @@ Iterative Refinement: Product categorization is an iterative process, and the mo
|
|||
|
||||
It's important to note that the success of product categorization using machine learning heavily depends on the quality and representativeness of the labeled training data, as well as the selection and engineering of relevant features
|
||||
|
||||
|
||||
\begin{table}[h]
|
||||
\centering
|
||||
\caption{Feature imputation}
|
||||
\label{table:feature_imputation}
|
||||
\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{lstlisting}[language=Python]
|
||||
resp=self.es.search("english-name-category",{"_source":["id","name","category"],
|
||||
'from':_from,
|
||||
'size' :_size ,
|
||||
"query": {"match_all": {}}})
|
||||
\end{lstlisting}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,29 @@ class DataFrame:
|
|||
|
||||
self.es.ingest('english-taxonomy-all',val,'product_category')
|
||||
|
||||
def setDfProductTaxonomy(self,lang='en'):
|
||||
|
||||
resp=self.es.searchDevelopmentProducts()
|
||||
df = pd.DataFrame(columns=["id",'name','shortDesc','Desc','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)
|
||||
|
||||
list_row["id"]=hit['_id']
|
||||
for name in hit['_source']['nameSource']:
|
||||
if (name["language"]==lang):
|
||||
list_row["name"]=name["value"]
|
||||
|
||||
|
||||
for cats in hit['_source']['categoriesSource']:
|
||||
if (cats["language"]=="en"):
|
||||
list_row["category"]=cats["label"]
|
||||
|
||||
|
||||
if(list_row["name"]!=None and list_row["catL1"]!=None):
|
||||
new_row = pd.Series(list_row)
|
||||
df=pd.concat([df, new_row.to_frame().T], ignore_index=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -47,3 +47,18 @@ class ElasticSearchDb:
|
|||
for val in docDict:
|
||||
|
||||
self.ingest('english-false-prediction',val,'category_prediction')
|
||||
|
||||
def searchDevelopmentProducts(self):
|
||||
resp=self.es.search("retromotion-indexer_development_products",
|
||||
{"_source":
|
||||
["_id",
|
||||
"descriptions",
|
||||
"descriptionsSource",
|
||||
"nameSource",
|
||||
"shortDescriptionSource",
|
||||
"categoriesSource"
|
||||
],
|
||||
'size' : 65000,
|
||||
"query": {"match_all": {}}})
|
||||
|
||||
return resp
|
||||
|
|
|
|||
Loading…
Reference in a new issue