{"id":14449,"date":"2018-12-21T16:34:35","date_gmt":"2018-12-21T21:34:35","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/?p=14449"},"modified":"2018-12-21T16:34:42","modified_gmt":"2018-12-21T21:34:42","slug":"different-types-of-distance-for-ml-algorithms","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=14449","title":{"rendered":"Different types of Distance for ML Algorithms"},"content":{"rendered":"<p>Manhattan,  Cosine, Ln Form<br \/>\n# http:\/\/dataaspirant.com\/2015\/04\/11\/five-most-popular-similarity-measures-implementation-in-python\/<\/p>\n<p># Manhattan<br \/>\ndef manhattan(x, y):<br \/>\nreturn sum( abs(a-b)  for a, b in zip(x,y))<\/p>\n<p>d = manhattan([5,10], [30,20])<br \/>\nprint(d)<\/p>\n<p>#&#8212;&#8212; Cosine Distance<br \/>\nimport math<br \/>\ndef square_rooted(x):<br \/>\nreturn math.sqrt(sum([a * a  for a in x]))<\/p>\n<p>def cosine_distance(x, y):<br \/>\nnumerator = sum ( a * b for a, b in zip(x, y ) )<br \/>\ndenominator = square_rooted(x) * square_rooted(y)<br \/>\nreturn numerator\/denominator<br \/>\nprint ( cosine_distance([3, 45, 7, 2], [2, 54, 13, 15]) )<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n#Ln Form Distance<\/p>\n<p>def ln_form_distance(x,y, dim):<br \/>\nreturn pow(sum([ pow(abs(a-b),dim) for a,b in zip(x,y)]), 1\/dim)<\/p>\n<p>print (ln_form_distance([3, 45, 7, 2], [2, 54, 13, 15], 3))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Manhattan, Cosine, Ln Form # http:\/\/dataaspirant.com\/2015\/04\/11\/five-most-popular-similarity-measures-implementation-in-python\/ # Manhattan def manhattan(x, y): return sum( abs(a-b) for a, b in zip(x,y)) d = manhattan([5,10], [30,20]) print(d) #&#8212;&#8212; Cosine Distance import math def square_rooted(x): return math.sqrt(sum([a * a for a in x])) def cosine_distance(x, y): numerator = sum ( a * b for a, b in zip(x, y &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=14449\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[182],"tags":[],"class_list":["post-14449","post","type-post","status-publish","format-standard","hentry","category---blog","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":14575,"url":"http:\/\/bangla.sitestree.com\/?p=14575","url_meta":{"origin":14449,"position":0},"title":"\u09ae\u09c7\u09b6\u09bf\u09a8 \u09b2\u09be\u09b0\u09a8\u09bf\u0982 \u0983 Implement: Multivariate Regression: Python","author":"Sayed","date":"January 7, 2019","format":false,"excerpt":"\u09ae\u09c7\u09b6\u09bf\u09a8 \u09b2\u09be\u09b0\u09a8\u09bf\u0982 \u0983 Implement: Multivariate Regression: Python \u09b6\u09a4 \u09ad\u09be\u0997 \u09b8\u09a0\u09bf\u0995 \u09a8\u09be\u0989 \u09b9\u09a4\u09c7 \u09aa\u09be\u09b0\u09c7\u0964 Theory reference: https:\/\/www.cmpe.boun.edu.tr\/~ethem\/i2ml\/slides\/v1-1\/i2ml-chap5-v1-1.pdf . This is an approximate solution to start with. Understand the theory and then adjust\/fix\/improve import numpy as np import random print('Iterations: rows: Please enter the number of samples for each variable\/dimension') n_number_of_samples_rows =\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11095,"url":"http:\/\/bangla.sitestree.com\/?p=11095","url_meta":{"origin":14449,"position":1},"title":"\u09aa\u09be\u0987\u09a5\u09a8 \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae\u09bf\u0982 : \u09a8\u09be\u09ae\u09cd\u09ac\u09be\u09b0 (Python Numbers in bangla)","author":"","date":"October 26, 2015","format":false,"excerpt":"1.9 Python Numbers Number \u09a1\u09be\u099f\u09be \u099f\u09be\u0987\u09aa\u09c7\u09b0 \u09b8\u09be\u09b9\u09be\u09af\u09cd\u09af\u09c7 \u09b8\u0982\u0996\u09cd\u09af\u09be \u09b8\u09cd\u099f\u09cb\u09b0 \u0995\u09b0\u09be \u09af\u09be\u09df\u0964 \u09af\u0996\u09a8\u0987 \u098f\u0995\u099f\u09bf number \u09a1\u09be\u099f\u09be \u099f\u09be\u0987\u09aa\u09c7\u09b0 \u09ae\u09be\u09a8 \u09aa\u09b0\u09bf\u09ac\u09b0\u09cd\u09a4\u09a8 \u0995\u09b0\u09be \u09b9\u09ac\u09c7 \u09a4\u0996\u09a8 \u098f\u0995\u099f\u09bf \u09a8\u09a4\u09c1\u09a8 \u0985\u09ac\u099c\u09c7\u0995\u09cd\u099f \u09a4\u09c8\u09b0\u09bf \u09b9\u09ac\u09c7\u0964 var1 = 1 var2 = 10 \u00a0 del statement \u098f\u09b0 \u09b8\u09be\u09b9\u09be\u09af\u09cd\u09af\u09c7 number \u0985\u09ac\u099c\u09c7\u0995\u09cd\u099f\u09c7\u09b0 \u09b0\u09c7\u09ab\u09be\u09b0\u09c7\u09a8\u09cd\u09b8 \u09a1\u09bf\u09b2\u09c7\u099f \u0995\u09b0\u09be \u09af\u09be\u09df\u0964 \u09af\u09c7\u09ae\u09a8, del var1[,var2[,var3[....,varN]]]] \u00a0 del\u00a0statement \u098f\u09b0 \u09b8\u09be\u09b9\u09be\u09af\u09cd\u09af\u09c7\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/bangla.sitestree.com\/?cat=1613"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19914,"url":"http:\/\/bangla.sitestree.com\/?p=19914","url_meta":{"origin":14449,"position":2},"title":"IPywidgets, interactive","author":"Sayed","date":"February 7, 2021","format":false,"excerpt":"Justetc Social Services (non-profit)\u00b7Jan 31 from __future__ import print_functionfrom ipywidgets import interact, interactive, fixed, interact_manualimport ipywidgets as widgetsdef f(x): return xinteract(f, x=10);interactive(children=(IntSlider(value=10, description='x', max=30, min=-10), Output()), _dom_classes=('widget-\u2026interact(f, x=True);interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))interact(f, x='Hi there!');interactive(children=(Text(value='Hi there!', description='x'), Output()), _dom_classes=('widget-interact',))@interact(x=True, y=1.0)def g(x, y): return (x, y)interactive(children=(Checkbox(value=True, description='x'), FloatSlider(value=1.0, description='y', max=3.0, \u2026interact(f, x=['apples','oranges']);interactive(children=(Dropdown(description='x', options=('apples',\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19924,"url":"http:\/\/bangla.sitestree.com\/?p=19924","url_meta":{"origin":14449,"position":3},"title":"non_med_determinants_visualizations, Health System Performance, Canada and Others","author":"Sayed","date":"February 7, 2021","format":false,"excerpt":"Justetc Social Services (non-profit)Jan 31\u00a0\u00b7\u00a05\u00a0min read import pandas as pdimport matplotlib.pyplot as plt%matplotlib inlinefrom __future__ import print_functionfrom ipywidgets import interact, interactive, fixed, interact_manualimport ipywidgets as widgetsnon_med_determinants = pd.read_excel('..\/data\/non-med-determinants.xls')non_med_determinants.head() # find all indicatorsnon_med_determinants.set_index(['Indicator'])indicators = pd.Index(non_med_determinants['Indicator']).unique()# find all yearsyears = non_med_determinants['Data year'].dropna().unique()indicators[0], years('Alcohol Consumption: Adults', array(['2014', '2015', '2013', 2015, 'Not applicable', '2016'],\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19922,"url":"http:\/\/bangla.sitestree.com\/?p=19922","url_meta":{"origin":14449,"position":4},"title":"interactive_health_status_visualizations, Health System Performance, Canada and Others","author":"Sayed","date":"February 7, 2021","format":false,"excerpt":"Justetc Social Services (non-profit)Jan 31\u00a0\u00b7\u00a05\u00a0min read import pandas as pdimport matplotlib.pyplot as plt%matplotlib inlinefrom __future__ import print_functionfrom ipywidgets import interact, interactive, fixed, interact_manualimport ipywidgets as widgetshealth_status = pd.read_excel('..\/data\/health-status.xls')health_status.head() # find all indicatorshealth_status.set_index(['Indicator'])indicators = pd.Index(health_status['Indicator']).unique()# find all yearsyears = health_status['Data year'].unique()indicators[0], years[0]('Cancer Mortality (F)', '2013')# sort yearsyears = [ int(aYear) for\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19916,"url":"http:\/\/bangla.sitestree.com\/?p=19916","url_meta":{"origin":14449,"position":5},"title":"How to use ipywidgets, interactive as used in the project","author":"Sayed","date":"February 7, 2021","format":false,"excerpt":"Justetc Social Services (non-profit)Jan 31\u00a0\u00b7\u00a01\u00a0min read from __future__ import print_functionfrom ipywidgets import interact, interactive, fixed, interact_manualimport ipywidgets as widgetsdef f(x): return xinteract(f, x=10);interactive(children=(IntSlider(value=10, description='x', max=30, min=-10), Output()), _dom_classes=('widget-\u2026interact(f, x=True);interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))interact(f, x='Hi there!');interactive(children=(Text(value='Hi there!', description='x'), Output()), _dom_classes=('widget-interact',))@interact(x=True, y=1.0)def g(x, y): return (x, y)interactive(children=(Checkbox(value=True, description='x'), FloatSlider(value=1.0, description='y', max=3.0, \u2026interact(f, x=['apples','oranges']);interactive(children=(Dropdown(description='x',\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/14449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14449"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/14449\/revisions"}],"predecessor-version":[{"id":14450,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/14449\/revisions\/14450"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14449"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}