

{"id":5809,"date":"2018-01-17T09:27:24","date_gmt":"2018-01-17T09:27:24","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=5809"},"modified":"2018-09-17T17:01:05","modified_gmt":"2018-09-17T11:31:05","slug":"apache-spark-mllib","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/","title":{"rendered":"Featurization in Apache Spark MLlib Algorithms"},"content":{"rendered":"<h2>1. Objective<\/h2>\n<p>In this blog, we will learn a tool Featurization in Apache\u00a0Spark<strong>\u00a0<\/strong>MLlib. We will also learn spark\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/machine-learning-tutorial\/\">Machine Learning<\/a> Algorithms to understand well.<\/p>\n<div id=\"attachment_5810\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5810\" class=\"wp-image-5810 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01.jpg\" alt=\"Apache Spark MLlib\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-5810\" class=\"wp-caption-text\">Apache Spark Machine Learning &#8211; Featurization<\/p><\/div>\n<h2>2. Featurization in Apache Spark MLlib<\/h2>\n<p><span style=\"font-weight: 400\">Apache Spark MLlib includes algorithms for working with <a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-features\/\">Spark features<\/a>. Moreover, it divided into these groups:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>Extraction:<\/b><span style=\"font-weight: 400\"> Extracting features from \u201craw\u201d data.<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Transformation<\/b><span style=\"font-weight: 400\">: Scaling, converting, or modifying features.<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Selection<\/b><span style=\"font-weight: 400\">: Selecting a subset of a larger set of features.<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Locality Sensitive Hashing (LSH)<\/b><span style=\"font-weight: 400\">: This class of algorithms combines aspects of feature transformation with other algorithms.<\/span><\/li>\n<\/ul>\n<p>Let&#8217;s learn all Apache Spark MLlib Featurization in detail:<\/p>\n<h3>a. Extraction in\u00a0Featurization of Apache\u00a0Spark MLlib<\/h3>\n<p><span style=\"font-weight: 400\">Here, we have 3 types of MLlib in Apache Spark Extractions:<\/span><br \/>\n<strong>i. TF-IDF<\/strong><br \/>\n<span style=\"font-weight: 400\">There is a feature vectorization method widely used in text mining to reflect the importance of a term to a document in the corpus. That is what we call a Term Frequency-Inverse Document Frequency (TF-IDF). Here we are denoting a term by t, also a document by d, whereas the corpus by D. Moreover, Term frequency TF(t,d) is the number of times that term t appears in document d. While document frequency DF(t, D)DF(t, D) is the number of documents that contain term t.<\/span><\/p>\n<div id=\"attachment_5818\" style=\"width: 215px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5818\" class=\"wp-image-5818 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture.png\" alt=\"Apache\u00a0Spark MLlib\" width=\"205\" height=\"79\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture.png 205w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture-150x58.png 150w\" sizes=\"auto, (max-width: 205px) 100vw, 205px\" \/><\/a><p id=\"caption-attachment-5818\" class=\"wp-caption-text\">Extraction in\u00a0Featurization of Apache\u00a0Spark MLlib<\/p><\/div>\n<p><strong>ii. Word2Vec<\/strong><br \/>\n<span style=\"font-weight: 400\">An estimator that takes sequences of words representing documents and trains a Word2VecModel is Word2Vec. It is the model that maps each word to a unique fixed-size vector. Moreover, Word2VecModel helps to transform each document into a vector using the average of all words in the document. Afterward, this vector can then be used as features for prediction, document similarity calculations and many more.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/create-rdds-in-apache-spark\/\">Have a look at Spark RDD<\/a><\/strong><br \/>\n<b>iii. CountVectorizer<\/b><br \/>\n<span style=\"font-weight: 400\">To convert a collection of text documents to vectors of token counts, we use CountVectorizer and CountVectorizerModel. We can use CountVectorizer as an estimator to extract the vocabulary when an a-priori dictionary is not available. Also generates a CountVectorizerModel. In addition, this model produces sparse representations for the documents over the vocabulary. Also, that can be passed to other algorithms like LDA.<\/span><\/p>\n<h3>b. Feature Transformers in\u00a0Featurization of Apache Spark MLlib<\/h3>\n<p><strong>i. Tokenizer<\/strong><br \/>\n<span style=\"font-weight: 400\">The process of taking the text (such as a sentence) and breaking it into individual terms (usually words), is known as Tokenization. Although, it is a functionality which is offered by a simple Tokenizer class.<\/span><br \/>\n<b>ii. StopWordsRemover<\/b><br \/>\n<span style=\"font-weight: 400\">There are some words which are Stop words. It is a compulsion that these words should be excluded from the input. Since the words appear frequently. Also, don\u2019t carry as much meaning.<\/span><br \/>\n<b>iii. n-gram<\/b><br \/>\n<span style=\"font-weight: 400\">A sequence of n tokens (typically words) for some integer n is an n-gram. Moreover, we use N-Gram class to transform input features into n-grams.<\/span><br \/>\n<b>iv. Binarizer<\/b><br \/>\n<span style=\"font-weight: 400\">The process of thresholding numerical features to binary (0\/1) features, is Binarization.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/structured-streaming-in-sparkr\/\">Do you know about Structured Streaming in SparkR<\/a><\/strong><br \/>\n<span style=\"font-weight: 400\">Basically, it takes the common parameters. Such as inputCol, outputCol, and the threshold for binarization. Moreover, the feature values greater than the threshold are binarized to 1.0. Whereas, values equal to or less than the threshold are binarized to 0.0. Although, inputCol support both vector and double types.<\/span><br \/>\n<b>v. PCA<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it is a statistical procedure. It uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables, that is called as principal components. Moreover, it trains a model to project vectors to a low-dimensional space.<\/span><br \/>\n<b>vi. PolynomialExpansion<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, a process of expanding features into a polynomial space is Polynomial expansion. In addition, it is formulated by an n-degree combination of original dimensions. Moreover, a Polynomial expansion class offers this functionality.<\/span><br \/>\n<b>vii. StringIndexer<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, StringIndexer encodes a string column of labels to a column of label indices. Moreover, the indices are in [0, numLabels), ordered by label frequencies. Hence, the most frequent label gets index 0.<\/span><br \/>\n<b>viii. IndexToString<\/b><br \/>\n<span style=\"font-weight: 400\">As same as StringIndexer, it also maps a column of label indices back to a column containing the original labels as strings.<\/span><br \/>\n<b>ix. OneHotEncoder<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it maps a column of label indices to a column of binary vectors, with at most a single one-value. Moreover, this encoding allows algorithms. That expect continuous features, such as Logistic Regression, to use categorical features.<\/span><br \/>\n<b>x. VectorIndexer<\/b><br \/>\n<span style=\"font-weight: 400\">In datasets of vectors, VectorIndexer helps index categorical features. Basically, it can both automatically decide which features are categorical. Also, converts original values to category indices. More specifically, it does all this following:<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/data-type-mapping-between-r-and-spark\/\">Have a look at data type mapping between R and Spark<\/a><\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It takes an input column of type vector and a parameter maxCategories.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Basically, it decides which features should be categorical. On the basis of the number of distinct values, where features with at most maxCategories are declared categorical.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Also, compute 0-based category indices for each categorical feature.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Moreover, index categorical features and transforms original feature values to indices.<\/span><\/li>\n<\/ol>\n<p><b>xi. Interaction<\/b><br \/>\n<span style=\"font-weight: 400\">It is a type of transformer that takes vector or double-valued columns. Afterwards generates a single vector column. Basically, that contains the product of all combinations of one value from each input column.<\/span><br \/>\n<b>xii. Normalizer<\/b><br \/>\n<span style=\"font-weight: 400\">It is a type of transformer that transforms a dataset of vector rows, normalizing each vector to have unit norm. Basically, it takes parameter p, that specifies the p-norm used for normalization.<\/span><br \/>\n<b>xiii. StandardScaler<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, StandardScaler transforms a dataset of vector rows. Also, normalizes each feature to have unit standard deviation and\/or zero mean.\u00a0<\/span><br \/>\n<b>xiv. withStd<\/b><br \/>\n<span style=\"font-weight: 400\">It is true by default. Moreover, it Scales the data to a unit standard deviation.<\/span><br \/>\n<b>xv. withMean<\/b><br \/>\nIt is false by default. Basically, it centers the data with mean before scaling. Also builds a dense output, so take care when applying to sparse input.<br \/>\n<b>xvi. MinMaxScaler<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it transforms a dataset of vector rows. Also, rescales each feature to a specific range (often [0, 1]). It takes parameters:<\/span><\/p>\n<div id=\"attachment_5813\" style=\"width: 227px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5813\" class=\"wp-image-5813 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture2.png\" alt=\"Apache Spark MLlib\" width=\"217\" height=\"82\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture2.png 217w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture2-150x57.png 150w\" sizes=\"auto, (max-width: 217px) 100vw, 217px\" \/><\/a><p id=\"caption-attachment-5813\" class=\"wp-caption-text\">MinMaxScaler<\/p><\/div>\n<ul>\n<li><b>Min<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\"> It takes 0.0 by default. Lower bound after transformation, shared by all features.<\/span><\/p>\n<ul>\n<li><b>max<\/b><\/li>\n<\/ul>\n<p>Featurization<span style=\"font-weight: 400\"> It takes \u00a01.0 by default. Upper bound after transformation, shared by all features.<\/span><br \/>\n<b>xvii. MaxAbsScaler<\/b><br \/>\n<span style=\"font-weight: 400\">It transforms a dataset of vector rows. Also, rescales each feature to the range [-1, 1] by dividing by the maximum absolute value in each feature. Moreover, it does not shift\/center the data. Therefore, it does not destroy any sparsity.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-machine-learning-with-r\/\">Let&#8217;s revise Spark machine Learning with R<\/a><\/strong><br \/>\n<b>xviii. Bucketizer<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it transforms a column of continuous features to a column of feature buckets. However, the buckets are specified by users.<\/span><br \/>\n<b>xix. ElementwiseProduct<\/b><br \/>\n<span style=\"font-weight: 400\"> By using element-wise multiplication, it multiplies each input vector by a provided \u201cweight\u201d vector. Also, we can define it as it scales each column of the dataset by a scalar multiplier. Moreover, this shows the Hadamard product between the input vector, v and transforming vector, w. Thus it yields a result vector.<\/span><br \/>\n<b>xx. SQLTransformer<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it implements the transformations those are defined by<a href=\"https:\/\/data-flair.training\/blogs\/sql-tutorial\/\"> <strong>SQL<\/strong> <\/a>statement. Although, recently we only support SQL syntax like &#8220;SELECT &#8230; FROM __THIS__ &#8230;&#8221; where &#8220;__THIS__&#8221;.<\/span><br \/>\n<b>xxi. VectorAssembler<\/b><br \/>\n<span style=\"font-weight: 400\">It is also a transformer. Basically, it combines a given list of columns into a single vector column. Although, it is useful for combining raw features. Also with features generated by different feature transformers into a single feature vector.\u00a0\u00a0<\/span><br \/>\n<b>xxii. Imputer<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, the Imputer transformer completes missing values in a dataset. Either using the mean or the median of the columns in which the missing values are located. Moreover, the input columns should be of DoubleType or FloatType.<\/span><\/p>\n<h3>c. Feature Selectors in\u00a0Featurization Apache\u00a0Spark MLlib<\/h3>\n<p><strong>i. VectorSlicer<\/strong><br \/>\n<span style=\"font-weight: 400\">It is nothing but a transformer, that takes a feature vector and outputs a new feature vector. Even with a sub-array of the original features. Moreover, it is beneficial for extracting features from a vector column.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-rdd-features\/\">Have a look at Spark RDD features<br \/>\n<\/a><\/strong><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">In addition, VectorSlicer accepts a vector column with specified indices. Afterwards, it outputs a new vector column. Basically, whose values are selected via those indices. Moreover, we have two types of indices, such as:<\/span><span style=\"font-weight: 400\"><br \/>\n<b style=\"font-family: Verdana, Geneva, sans-serif\"><\/b><\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\"><b style=\"font-family: Verdana, Geneva, sans-serif\">Integer indices<\/b><\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It represents the indices into the vector, setIndices().<\/span><\/p>\n<ul>\n<li><b>String indices<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It represents the names of features in the vector, setNames(). Also, requires the vector column to have an AttributeGroup. Since the implementation matches on the name field of an Attribute.<\/span><br \/>\n<b>ii. RFormula<\/b><br \/>\n<span style=\"font-weight: 400\">By an R model formula, RFormula selects columns. Basically, we support a limited subset of the R operators. It includes \u2018~\u2019, \u2018.\u2019, \u2018:\u2019, \u2018+\u2019, and \u2018-\u2018. Let\u2019s discuss all the basic operators:<\/span><br \/>\n1. ~ separate target and terms<br \/>\n2. + concat terms, \u201c+ 0\u201d means removing intercept<br \/>\n3. &#8211; remove a term, \u201c- 1\u201d means removing intercept<br \/>\n4. : interaction (multiplication for numeric values, or binarized categorical values)<br \/>\n5. . all columns except the target<br \/>\n<strong>iii.<\/strong> <strong>ChiSqSelector<\/strong><br \/>\n<span style=\"font-weight: 400\">ChiSqSelector refers to Chi-Squared feature selection. Basically, it operates on labeled data with categorical features. Moreover, it uses the Chi-Squared test of independence to decide which features to choose. Also supports five selection methods, such as numTopFeatures, percentile, fpr, fdr, fwe. Lets discuss all one by one:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/spark-sql-optimization-catalyst-optimizer\/\"><strong>Do you know about Spark SQL Optimization<\/strong><\/a><\/p>\n<ul>\n<li><span style=\"font-weight: 400\"><strong> numTopFeatures<\/strong> &#8211;<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It chooses a fixed number of top features according to a chi-squared test. This is akin to yielding the features with the most predictive power. <\/span><\/p>\n<ul>\n<li><strong> percentile <\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It is similar to numTopFeatures but chooses a fraction of all features instead of a fixed number. <\/span><\/p>\n<ul>\n<li><strong> fpr <\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It chooses all features whose p-values are below a threshold, thus controlling the false positive rate of selection. <\/span><\/p>\n<ul>\n<li><strong> fdr <\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It uses the Benjamini-Hochberg procedure to choose all features whose false discovery rate is below a threshold. <\/span><\/p>\n<ul>\n<li><strong> fwe <\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It chooses all features whose p-values are below a threshold.<\/span><\/p>\n<h3>d. Locality Sensitive Hashing in\u00a0Featurization in Apache Spark\u00a0MLlib<\/h3>\n<p><span style=\"font-weight: 400\">An important class of hashing techniques is Locality Sensitive Hashing (LSH). Basically, we use it in following. Such as clustering, approximate nearest neighbor search and outlier detection with large datasets.<\/span><br \/>\n<b>i. LSH Operations<\/b><br \/>\n<span style=\"font-weight: 400\">LSH can be used for the major types of operations. Basically, for each of these operations, a fitted LSH model has methods.<\/span><br \/>\n<b>Feature Transformation<\/b><br \/>\n<span style=\"font-weight: 400\">To add hashed values as a new column it is the basic functionality. Moreover, it is very useful for dimensionality reduction. Also, by setting inputCol and outputCol, users can specify input and output column names.<\/span><\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-mcqs-part-3\/\">Test yourself with Spark Quiz<\/a><\/strong><br \/>\n<b>Approximate Similarity Join<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it takes two datasets and approximately returns pairs of rows in the datasets whose distance is smaller than a user-defined threshold. Also, supports both joining two different datasets and self-joining. Moreover, self-joining will produce some duplicate pairs also.<\/span><br \/>\n<b>Approximate Nearest Neighbor Search<\/b><br \/>\n<span style=\"font-weight: 400\">Basically, it takes a dataset and a key then returns a specified number of rows in the dataset that are closest to the vector.<\/span><br \/>\n<b>ii. LSH Algorithms<\/b><br \/>\n<b>Bucketed Random Projection for Euclidean Distance<\/b><br \/>\n<span style=\"font-weight: 400\">For Euclidean distance, Bucketed Random Projection is an LSH family. We can define Euclidean distance as follows:<\/span><\/p>\n<div id=\"attachment_5814\" style=\"width: 186px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture5.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5814\" class=\"wp-image-5814 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture5.png\" alt=\"Apache Spark MLlib\" width=\"176\" height=\"51\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture5.png 176w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture5-150x43.png 150w\" sizes=\"auto, (max-width: 176px) 100vw, 176px\" \/><\/a><p id=\"caption-attachment-5814\" class=\"wp-caption-text\">Bucketed Random Projection for Euclidean Distanc<\/p><\/div>\n<p><b>MinHash for Jaccard Distance<\/b><br \/>\nFor Jaccard distance, MinHash is an LSH family. Where input features are sets of natural numbers. Moreover, Jaccard distance of two sets is the cardinality of their intersection &amp; union<\/p>\n<div id=\"attachment_5815\" style=\"width: 182px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5815\" class=\"wp-image-5815 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture3.png\" alt=\"Apache Spark MLlib\" width=\"172\" height=\"51\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture3.png 172w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture3-150x44.png 150w\" sizes=\"auto, (max-width: 172px) 100vw, 172px\" \/><\/a><p id=\"caption-attachment-5815\" class=\"wp-caption-text\">MinHash for Jaccard Distance<\/p><\/div>\n<p><span style=\"font-weight: 400\">Basically, MinHash applies a random hash function g to each element in the set. Also take the minimum of all hashed values:<\/span><\/p>\n<div id=\"attachment_5816\" style=\"width: 156px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture4.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5816\" class=\"wp-image-5816 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Capture4.png\" alt=\"Apache Spark MLlib\" width=\"146\" height=\"55\" \/><\/a><p id=\"caption-attachment-5816\" class=\"wp-caption-text\">LSH Algorithms<\/p><\/div>\n<h2>3. Conclusion<\/h2>\n<p>As a result, we have seen all Featurization methods in Apache\u00a0Spark MLlib. However, if any query occurs, please ask in the comment section. We will definitely get back to You.<br \/>\n<a href=\"https:\/\/spark.apache.org\/\">For reference<\/a><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2052,&quot;href&quot;:&quot;https:\\\/\\\/spark.apache.org&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251009215151\\\/https:\\\/\\\/spark.apache.org\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:11:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-14 03:24:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-17 05:06:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-20 07:19:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-23 14:10:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-26 19:03:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-30 13:05:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-02 13:25:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-05 14:08:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 10:16:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 11:04:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 17:09:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-18 18:39:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-21 19:15:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-26 04:14:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-29 05:32:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-01 07:55:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-04 10:44:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-07 12:28:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-11 00:52:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-14 12:51:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 14:17:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 17:49:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 04:42:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 06:25:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 08:44:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 10:27:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 11:13:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 12:04:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 12:32:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 01:16:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 21:29:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-25 06:37:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 07:59:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 10:36:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 11:16:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-07 18:11:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 05:09:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 06:26:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 15:58:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 11:10:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-27 06:59:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-30 12:38:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-03 15:24:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-06 17:05:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-10 12:07:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-14 23:33:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-19 11:27:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-23 02:59:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 05:05:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-01 06:55:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-04 20:59:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-08 05:37:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-11 15:39:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-14 16:52:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-18 01:16:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-22 04:29:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-25 16:10:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-29 06:57:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-02 07:09:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-07 02:05:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-10 04:47:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-13 04:57:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-16 23:55:43&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-16 23:55:43&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Objective In this blog, we will learn a tool Featurization in Apache\u00a0Spark\u00a0MLlib. We will also learn spark\u00a0Machine Learning Algorithms to understand well. 2. Featurization in Apache Spark MLlib Apache Spark MLlib includes algorithms&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":6362,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[4654,13081,13087],"class_list":["post-5809","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spark","tag-featurization","tag-spark-machine-learning-library","tag-spark-mllib"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Featurization in Apache Spark MLlib Algorithms - DataFlair<\/title>\n<meta name=\"description\" content=\"Apache Spark MLlib-Featurization algorithms in Spark MLlib,Extraction, Transformers, Selectors,Sensitive Hashing Spark featurization in MLlib\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Featurization in Apache Spark MLlib Algorithms - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Apache Spark MLlib-Featurization algorithms in Spark MLlib,Extraction, Transformers, Selectors,Sensitive Hashing Spark featurization in MLlib\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-17T09:27:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-09-17T11:31:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Featurization in Apache Spark MLlib Algorithms - DataFlair","description":"Apache Spark MLlib-Featurization algorithms in Spark MLlib,Extraction, Transformers, Selectors,Sensitive Hashing Spark featurization in MLlib","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/","og_locale":"en_US","og_type":"article","og_title":"Featurization in Apache Spark MLlib Algorithms - DataFlair","og_description":"Apache Spark MLlib-Featurization algorithms in Spark MLlib,Extraction, Transformers, Selectors,Sensitive Hashing Spark featurization in MLlib","og_url":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-17T09:27:24+00:00","article_modified_time":"2018-09-17T11:31:05+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Featurization in Apache Spark MLlib Algorithms","datePublished":"2018-01-17T09:27:24+00:00","dateModified":"2018-09-17T11:31:05+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/"},"wordCount":1930,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg","keywords":["Featurization","Spark Machine Learning Library","Spark MLlib"],"articleSection":["Apache Spark Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/","url":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/","name":"Featurization in Apache Spark MLlib Algorithms - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg","datePublished":"2018-01-17T09:27:24+00:00","dateModified":"2018-09-17T11:31:05+00:00","description":"Apache Spark MLlib-Featurization algorithms in Spark MLlib,Extraction, Transformers, Selectors,Sensitive Hashing Spark featurization in MLlib","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Featurization-in-Machine-Learning-in-Apache-Spark-01-1.jpg","width":1200,"height":628,"caption":"Featurization in Spark Machine Learning"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-mllib\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Apache Spark Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/spark\/"},{"@type":"ListItem","position":3,"name":"Featurization in Apache Spark MLlib Algorithms"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=5809"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5809\/revisions"}],"predecessor-version":[{"id":34420,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5809\/revisions\/34420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/6362"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=5809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=5809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=5809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}