{"id":4789,"date":"2020-02-15T10:39:53","date_gmt":"2020-02-15T10:39:53","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=4789"},"modified":"2024-03-15T11:07:56","modified_gmt":"2024-03-15T11:07:56","slug":"k-nearest-neighbors-algorithm-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/","title":{"rendered":"k-Nearest Neighbors Algorithm Tutorial"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h1 style=\"text-align: center;\">k-Nearest Neighbors Algorithm Tutorial<\/h1>\n<p>&nbsp;<\/p>\n<p><strong>k-nearest neighbors Algorithm Tutorial<\/strong>, Are you the one who is looking forward to know about knn algorithm introduction in Machine Learning? Or the one who is looking forward to know How KNN algorithm works and benefits of knn or Are you dreaming to become to certified Pro Machine Learning Engineer or <a title=\"Data Scientist\" href=\"https:\/\/prwatech.in\/data-science-training-institutes-in-bangalore\/\">Data Scientist<\/a>, then stop just dreaming, get your <a title=\"Data Science certification course\" href=\"https:\/\/prwatech.in\/data-science-certification-course-in-bangalore\/\">Data Science certification course<\/a> with Machine Learning from India\u2019s Leading <a title=\"Data Science training institute\" href=\"https:\/\/prwatech.in\/data-science-training-institutes-in-bangalore\/\">Data Science training institute<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>Knn is part of supervised learning which will be used in many applications such as data mining, image processing and many more. It is simple and one of the most important Machine learning algorithms. In this blog, we will learn knn algorithm introduction, knn implementation in python and benefits of knn. Do you want to know How KNN algorithm works, So follow the below mentioned k-nearest neighbors algorithm tutorial from <a title=\"Prwatech\" href=\"https:\/\/prwatech.com\/\">Prwatech<\/a> and take advanced <a title=\"Data Science training\" href=\"https:\/\/prwatech.in\/data-science-certification-course-in-bangalore\/\">Data Science training with Machine Learning<\/a> like a pro from today itself under 10+ Years of hands-on experienced Professionals.<\/p>\n<p>&nbsp;<\/p>\n<h2>knn Algorithm Introduction<\/h2>\n<p>&nbsp;<\/p>\n<p>K nearest Neighbor (KNN) is a popular supervised machine learning algorithm that is used widely. Its popularity stems from its comfort of use, and its clearly reasonable results. The \u2018K\u2019 in KNN indicates the number of nearest neighbors, which are used to classify or predict outputs in a data set. The classification or prediction of every new data point is based on a specific distance calculated from nearest neighbors and their weighted averages.<\/p>\n<p>&nbsp;<\/p>\n<p>If there is very little prior knowledge about the distribution of data points, KNN emerges as the best algorithm for analysis. When dealing with labeled datasets, KNN aids in discovering the relationship between each observation in the training data. This relationship, often referred to as resemblance, is quantified using a distance metric between data points. Various methods exist to compute these intervals, including Euclidean, Manhattan, Chebyshev, and Hamming distance.<\/p>\n<p>KNN operates as a non-parametric algorithm, making no explicit assumptions about the functional form of the relationship. Instead, it directly operates on training instances without applying any predefined model. Although KNN can be utilized to tackle prediction problems in both classification and regression, its predominant usage lies in classification prediction within the industry.<\/p>\n<p>&nbsp;<\/p>\n<h2>How KNN algorithm works?<\/h2>\n<p>&nbsp;<\/p>\n<p>As mentioned above KNN basically works on the relationship of resemblance by means of calculating distance of data point from others.<\/p>\n<p>Let\u2019s take an example.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4790\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png\" alt=\"k-nearest neighbors Algorithm Tutorial\" width=\"850\" height=\"619\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png 350w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1-300x219.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Let\u2019s consider a set of some data points is given which includes red stars and blue squares. Now we have to categorize a new data point which is indicated with green circle. For applying KNN, first we have to decide value of K. Let\u2019s consider value of K be 3. Now based on K=3 we have to find 3 neighbors which are nearest to this green circle.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4791\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN2.png\" alt=\"k-nearest neighbors Algorithm Tutorial\" width=\"850\" height=\"655\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN2.png 348w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN2-300x231.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In this example the green circle has to find its nearest neighbors. And as we can see all the red stars are nearest to the circle compared to blue squares. So, the new data point i.e. green circle will be classified as \u2018red star\u2019.<\/p>\n<p>&nbsp;<\/p>\n<p>To get best possible fit for the data set, it is important to select the appropriate value of \u2018K\u2019 i.e. number of nearest neighbors. If K value is small, the region of prediction is restricted and it makes the classifier less sensitive the overall distribution. K should be most common class value in case of classification and it should be mean output variable in case of regression.<\/p>\n<p>&nbsp;<\/p>\n<h2>Methods of calculating distance between data points:<\/h2>\n<p>&nbsp;<\/p>\n<p>To find the distance of target data point means to measure the interval between new data point and each data point present around it. \u00a0To calculate this the most commonly used methods are: Euclidian, Manhattan and Hamming distance.<\/p>\n<p>&nbsp;<\/p>\n<h3>Euclidian Distance:<\/h3>\n<p>&nbsp;<\/p>\n<p>It is the square root of the sum of the squared differences between a new point and an existing point. Let\u2019s take new point as x and existing point y.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4792\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN3.png\" alt=\"Euclidian Distance\" width=\"850\" height=\"386\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Manhattan Distance:<\/h3>\n<p>&nbsp;<\/p>\n<p>It is the distance between real vectors using the sum of their absolute difference.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4793\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN4.png\" alt=\"Manhattan Distance\" width=\"850\" height=\"479\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Hamming Distance:<\/h3>\n<p>&nbsp;<\/p>\n<p>Hamming distance is helpful in case of categorical variables. If the x value and y value are same, the distance will be zero. Otherwise distance is:<\/p>\n<p>Here distance is indicated with \u2018D\u2019.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4794\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN5.png\" alt=\"Hamming Distance\" width=\"850\" height=\"748\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>How to decide K value?<\/h2>\n<p>&nbsp;<\/p>\n<p>The most important step in KNN is to determine the optimal value of K. The optimal value of\u00a0<em>k<\/em>\u00a0decreases effect of the noise on the classification. For this a technique called \u2018Elbow method\u2019 helps to select the optimal K value.<\/p>\n<p>&nbsp;<\/p>\n<p>Let\u2019s say we are applying K with different values to same dataset. Initially we have to observe the error rate changing with K values. Let\u2019s say we applied KNN on a data set and we got a curve of error rate Vs. K values as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4795\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6.png\" alt=\"How to decide K value?\" width=\"850\" height=\"519\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6.png 581w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6-300x183.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Here we can observe that initially error rate is decreasing up to nearly 6. After that it starts increasing. So, the value of K should be 6 i.e. it is optimum value of K for this model. This curve is called because it has a shape like an elbow and is usually used to regulate the k value. This is called Elbow method.<\/p>\n<p>&nbsp;<\/p>\n<h2>knn implementation in python<\/h2>\n<p>&nbsp;<\/p>\n<p>In the following example we will consider k=3, hence, we will take 3 nearest points to new or target point.<\/p>\n<p>&nbsp;<\/p>\n<h3>Importing Library<\/h3>\n<p>&nbsp;<\/p>\n<h3>Importing dataset<\/h3>\n<p>&nbsp;<\/p>\n<p>df= pd.read_csv(\u201c Your File Path\u201d)<\/p>\n<p>(We will consider that necessary cleaning part is done)<\/p>\n<p>&nbsp;<\/p>\n<h3>Divide the dataset into independent and dependent parts.<\/h3>\n<p>&nbsp;<\/p>\n<p>X = data.iloc[:,0:20]\u00a0 #independent columns<\/p>\n<p>y = data.iloc[:,-1] # target column<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Split the dataset into two parts for training and testing.<\/h3>\n<p>&nbsp;<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 10, test_size = 0.33)<\/p>\n<p>&nbsp;<\/p>\n<h3>Preprocessing \u2013 Scaling the features<\/h3>\n<p>&nbsp;<\/p>\n<p>from sklearn.preprocessing import MinMaxScaler<\/p>\n<p>scaler = MinMaxScaler(feature_range=(0, 1))<\/p>\n<p>x_train_scaled = scaler.fit_transform(x_train)<\/p>\n<p>x_train = pd.DataFrame(x_train_scaled)<\/p>\n<p>x_test_scaled = scaler.fit_transform(x_test)<\/p>\n<p>x_test = pd.DataFrame(x_test_scaled)<\/p>\n<p>&nbsp;<\/p>\n<h3>Visualize the error rate for different k values<\/h3>\n<p>&nbsp;<\/p>\n<p><strong>#import required packages<\/strong><\/p>\n<p>%matplotlib inline<\/p>\n<p>rmse_val = []<\/p>\n<p>&nbsp;<\/p>\n<p><strong>#to store rmse values for different k<\/strong><\/p>\n<p>for K in range(20):<\/p>\n<p>K = K+1<\/p>\n<p>model = neighbors.KNeighborsRegressor(n_neighbors = K)<\/p>\n<p>model.fit(x_train, y_train)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#fit the model<\/p>\n<p>pred=model.predict(x_test)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #make prediction on test set<\/p>\n<p>error = sqrt(mean_squared_error(y_test,pred))<\/p>\n<p>&nbsp;<\/p>\n<p><strong>#calculate rmse<\/strong><\/p>\n<p>rmse_val.append(error) #store rmse values<\/p>\n<p>print(&#8216;RMSE value for : &#8216; , K , &#8216;is:&#8217;, error)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>#plotting the rmse values against k values<\/strong><\/p>\n<p>curve = pd.DataFrame(rmse_val)\u00a0 \u00a0 \u00a0#elbow curve<\/p>\n<p>curve.plot()<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4908\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6-1.png\" alt=\"knn implementation in python\" width=\"850\" height=\"519\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6-1.png 581w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN6-1-300x183.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Implementing GridsearchCV<\/h3>\n<p>&nbsp;<\/p>\n<p>Plotting the elbow curve every time to determine K, is be a cumbersome and tedious process. You can simply use gridsearch to find the best value.<\/p>\n<p>&nbsp;<\/p>\n<p>from sklearn.model_selection import GridSearchCV<\/p>\n<p>params = {&#8216;n_neighbors&#8217;:[2,3,4,5,6,7,8,9]}<\/p>\n<p>knn = neighbors.KNeighborsRegressor()<\/p>\n<p>model = GridSearchCV(knn, params, cv=5)<\/p>\n<p>model.fit(x_train,y_train)<\/p>\n<p>model.best_params_<\/p>\n<p>&nbsp;<\/p>\n<h2>Benefits of knn:<\/h2>\n<p>&nbsp;<\/p>\n<p>The algorithm is useful in searching for similar documents. This algorithm can be used to find all the e-mails, briefs, contracts, etc. relevant to given problem statements. Recommendation systems prefer this algorithm to recommend customer different products based on past purchasing history. Also, it is used as a benchmark for more complex classifiers such as Artificial Neural Networks (ANN).<\/p>\n<p>&nbsp;<\/p>\n<p>We hope you understand k-nearest neighbors algorithm tutorial.Get success in your career as a <a title=\"Data Scientist\" href=\"https:\/\/prwatech.in\/data-science-certification-course-in-bangalore\/\">Data Scientist<\/a> by being a part of the <a title=\"Prwatech\" href=\"https:\/\/prwatech.com\/\">Prwatech<\/a>, India&#8217;s leading <a title=\"Data Science training institute in Bangalore\" href=\"https:\/\/prwatech.in\/data-science-training-institutes-in-bangalore\/\">Data Science training institute in Bangalore<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; k-Nearest Neighbors Algorithm Tutorial &nbsp; k-nearest neighbors Algorithm Tutorial, Are you the one who is looking forward to know about knn algorithm introduction in Machine Learning? Or the one who is looking forward to know How KNN algorithm works and benefits of knn or Are you dreaming to become to certified Pro Machine Learning [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,1696],"tags":[436,433,432,434,435],"class_list":["post-4789","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-machine-learning-modules","tag-benefits-of-knn","tag-how-knn-algorithm-works","tag-k-nearest-neighbors-algorithm-tutorial","tag-knn-algorithm-introduction","tag-knn-implementation-in-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>K-Nearest Neighbors Algorithm for Machine Learning - Prwatech<\/title>\n<meta name=\"description\" content=\"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"K-Nearest Neighbors Algorithm for Machine Learning - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-15T10:39:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-15T11:07:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/\",\"name\":\"K-Nearest Neighbors Algorithm for Machine Learning - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png\",\"datePublished\":\"2020-02-15T10:39:53+00:00\",\"dateModified\":\"2024-03-15T11:07:56+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png\",\"width\":350,\"height\":255},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"k-Nearest Neighbors Algorithm Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"K-Nearest Neighbors Algorithm for Machine Learning - Prwatech","description":"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"K-Nearest Neighbors Algorithm for Machine Learning - Prwatech","og_description":"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,","og_url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2020-02-15T10:39:53+00:00","article_modified_time":"2024-03-15T11:07:56+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/","url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/","name":"K-Nearest Neighbors Algorithm for Machine Learning - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png","datePublished":"2020-02-15T10:39:53+00:00","dateModified":"2024-03-15T11:07:56+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Explore k-Nearest Neighbors Algorithm Tutorial and learn knn algorithm introduction, How KNN algorithm works,","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/KNN1.png","width":350,"height":255},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/k-nearest-neighbors-algorithm-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"k-Nearest Neighbors Algorithm Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=4789"}],"version-history":[{"count":11,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4789\/revisions"}],"predecessor-version":[{"id":10906,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4789\/revisions\/10906"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=4789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=4789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=4789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}