{"id":832,"date":"2023-07-28T14:53:35","date_gmt":"2023-07-28T14:53:35","guid":{"rendered":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/"},"modified":"2023-07-28T14:53:35","modified_gmt":"2023-07-28T14:53:35","slug":"mahalanobis-uzak-pitonu","status":"publish","type":"post","link":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/","title":{"rendered":"Python&#39;da mahalanobis mesafesi nas\u0131l hesaplan\u0131r?"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Mahalanobis mesafesi<\/strong> \u00e7ok de\u011fi\u015fkenli bir uzayda iki nokta aras\u0131ndaki mesafedir. Birden fazla de\u011fi\u015fkeni i\u00e7eren istatistiksel analizlerde ayk\u0131r\u0131 de\u011ferleri tespit etmek i\u00e7in s\u0131kl\u0131kla kullan\u0131l\u0131r.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Bu e\u011fitimde Python&#8217;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131 a\u00e7\u0131klanmaktad\u0131r.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>\u00d6rnek: Python&#8217;da Mahalanobis Mesafesi<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Python&#8217;da bir veri k\u00fcmesindeki her g\u00f6zlemin Mahalanobis mesafesini hesaplamak i\u00e7in a\u015fa\u011f\u0131daki ad\u0131mlar\u0131 kullan\u0131n.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Ad\u0131m 1: Veri k\u00fcmesini olu\u015fturun.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">\u0130lk olarak 20 \u00f6\u011frencinin s\u0131nav puanlar\u0131n\u0131, ders \u00e7al\u0131\u015farak ge\u00e7irdikleri saat say\u0131s\u0131n\u0131, girdikleri uygulama s\u0131nav say\u0131s\u0131n\u0131 ve dersteki mevcut notlar\u0131n\u0131 g\u00f6steren bir veri seti olu\u015fturaca\u011f\u0131z:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> numpy <span style=\"color: #107d3f;\">as<\/span> np\n<span style=\"color: #107d3f;\">import<\/span> pandas <span style=\"color: #107d3f;\">as<\/span> pd<span style=\"color: #107d3f;\">\nimport<\/span> scipy <span style=\"color: #107d3f;\">as<\/span> stats\n\ndata = {'score': [91, 93, 72, 87, 86, 73, 68, 87, 78, 99, 95, 76, 84, 96, 76, 80, 83, 84, 73, 74],\n        'hours': [16, 6, 3, 1, 2, 3, 2, 5, 2, 5, 2, 3, 4, 3, 3, 3, 4, 3, 4, 4],\n        'prep': [3, 4, 0, 3, 4, 0, 1, 2, 1, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2, 2],\n        'grade': [70, 88, 80, 83, 88, 84, 78, 94, 90, 93, 89, 82, 95, 94, 81, 93, 93, 90, 89, 89]\n        }\n\ndf = pd.DataFrame(data,columns=['score', 'hours', 'prep','grade'])\ndf.head()\n\n score hours prep grade\n0 91 16 3 70\n1 93 6 4 88\n2 72 3 0 80\n3 87 1 3 83\n4 86 2 4 88\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Ad\u0131m 2: Her g\u00f6zlem i\u00e7in Mahalanobis mesafesini hesaplay\u0131n.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Daha sonra Mahalanobis mesafesini hesaplamak i\u00e7in k\u0131sa bir fonksiyon yazaca\u011f\u0131z.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\"><span style=\"color: #008080;\">#create function to calculate Mahalanobis distance<\/span>\ndef<\/span> mahalanobis(x= <span style=\"color: #107d3f;\">None<\/span> , data= <span style=\"color: #107d3f;\">None<\/span> , cov= <span style=\"color: #107d3f;\">None<\/span> ):\n\n    x_mu = x - np.mean(data)\n    if not cov:\n        cov = np.cov(data.values.T)\n    inv_covmat = np.linalg.inv(cov)\n    left = np.dot(x_mu, inv_covmat)\n    mahal = np.dot(left, x_mu.T)\n    return mahal.diagonal()\n\n<span style=\"color: #107d3f;\"><span style=\"color: #008080;\">#create new column in dataframe that contains Mahalanobis distance for each row<\/span><\/span>\ndf['mahalanobis'] = mahalanobis(x=df, data=df[['score', 'hours', 'prep', 'grade']])\n\n<span style=\"color: #008080;\">#display first five rows of dataframe\n<\/span>df.head()\n\n score hours prep grade mahalanobis\n0 91 16 3 70 16.501963\n1 93 6 4 88 2.639286\n2 72 3 0 80 4.850797\n3 87 1 3 83 5.201261\n4 86 2 4 88 3.828734\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Ad\u0131m 3: Her Mahalanobis mesafesi i\u00e7in p de\u011ferini hesaplay\u0131n.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Baz\u0131 Mahalanobis mesafelerinin di\u011ferlerinden \u00e7ok daha b\u00fcy\u00fck oldu\u011funu g\u00f6rebiliriz. Mesafelerden herhangi birinin istatistiksel olarak anlaml\u0131 olup olmad\u0131\u011f\u0131n\u0131 belirlemek i\u00e7in p de\u011ferlerini hesaplamam\u0131z gerekir.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Her mesafe i\u00e7in p de\u011feri, k = de\u011fi\u015fken say\u0131s\u0131 olmak \u00fczere, k-1 serbestlik derecesine sahip Mahalanobis mesafesinin ki-kare istatisti\u011fine kar\u015f\u0131l\u0131k gelen p de\u011feri olarak hesaplan\u0131r. Bu durumda serbestlik derecesi 4-1 = 3&#8217;\u00fc kullanaca\u011f\u0131z.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> scipy.stats <span style=\"color: #107d3f;\">import<\/span> chi2\n\n<span style=\"color: #008080;\">#calculate p-value for each mahalanobis distance<\/span> \ndf['p'] = 1 - chi2.cdf(df['mahalanobis'], 3)\n\n<span style=\"color: #008080;\">#display p-values for first five rows in dataframe<\/span>\ndf.head()\n\n score hours prep grade mahalanobis p\n0 91 16 3 70 16.501963 0.000895\n1 93 6 4 88 2.639286 0.450644\n2 72 3 0 80 4.850797 0.183054\n3 87 1 3 83 5.201261 0.157639\n4 86 2 4 88 3.828734 0.280562\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Genellikle <strong>0,001&#8217;den k\u00fc\u00e7\u00fck<\/strong> bir p de\u011feri ayk\u0131r\u0131 de\u011fer olarak kabul edilir.<\/span> <span style=\"color: #000000;\">\u0130lk g\u00f6zlemin veri setinde bir ayk\u0131r\u0131 de\u011fer oldu\u011funu g\u00f6rebiliriz \u00e7\u00fcnk\u00fc p de\u011feri 0,001&#8217;den k\u00fc\u00e7\u00fckt\u00fcr.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Sorunun ba\u011flam\u0131na ba\u011fl\u0131 olarak, ayk\u0131r\u0131 bir de\u011fer oldu\u011fundan ve analiz sonu\u00e7lar\u0131n\u0131 etkileyebilece\u011finden bu g\u00f6zlemi veri k\u00fcmesinden \u00e7\u0131karmaya karar verebilirsiniz.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mahalanobis mesafesi \u00e7ok de\u011fi\u015fkenli bir uzayda iki nokta aras\u0131ndaki mesafedir. Birden fazla de\u011fi\u015fkeni i\u00e7eren istatistiksel analizlerde ayk\u0131r\u0131 de\u011ferleri tespit etmek i\u00e7in s\u0131kl\u0131kla kullan\u0131l\u0131r. Bu e\u011fitimde Python&#8217;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131 a\u00e7\u0131klanmaktad\u0131r. \u00d6rnek: Python&#8217;da Mahalanobis Mesafesi Python&#8217;da bir veri k\u00fcmesindeki her g\u00f6zlemin Mahalanobis mesafesini hesaplamak i\u00e7in a\u015fa\u011f\u0131daki ad\u0131mlar\u0131 kullan\u0131n. Ad\u0131m 1: Veri k\u00fcmesini olu\u015fturun. \u0130lk olarak [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-832","post","type-post","status-publish","format-standard","hentry","category-rehber"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python&#039;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials<\/title>\n<meta name=\"description\" content=\"Python&#039;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python&#039;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials\" \/>\n<meta property=\"og:description\" content=\"Python&#039;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T14:53:35+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Yazan:\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/\",\"url\":\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/\",\"name\":\"Python&#39;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/tr\/#website\"},\"datePublished\":\"2023-07-28T14:53:35+00:00\",\"dateModified\":\"2023-07-28T14:53:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/tr\/#\/schema\/person\/365dc158a39a7c8ae256355451e3de48\"},\"description\":\"Python&#39;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ev\",\"item\":\"https:\/\/statorials.org\/tr\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python&#39;da mahalanobis mesafesi nas\u0131l hesaplan\u0131r?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/tr\/#website\",\"url\":\"https:\/\/statorials.org\/tr\/\",\"name\":\"Statorials\",\"description\":\"\u0130statistik okuryazarl\u0131\u011f\u0131 rehberiniz!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/tr\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"tr\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/tr\/#\/schema\/person\/365dc158a39a7c8ae256355451e3de48\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"tr\",\"@id\":\"https:\/\/statorials.org\/tr\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/tr\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/tr\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Merhaba, ben Benjamin, emekli bir istatistik profes\u00f6r\u00fc ve Statorials \u00f6\u011fretmenine d\u00f6n\u00fc\u015ft\u00fcm. \u0130statistik alan\u0131ndaki kapsaml\u0131 deneyimim ve uzmanl\u0131\u011f\u0131mla, \u00f6\u011frencilerimi Statorials arac\u0131l\u0131\u011f\u0131yla g\u00fc\u00e7lendirmek i\u00e7in bilgilerimi payla\u015fmaya can at\u0131yorum. Daha fazlas\u0131n\u0131 bil\",\"sameAs\":[\"https:\/\/statorials.org\/tr\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python&#39;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials","description":"Python&#39;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.","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:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/","og_locale":"tr_TR","og_type":"article","og_title":"Python&#39;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials","og_description":"Python&#39;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.","og_url":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/","og_site_name":"Statorials","article_published_time":"2023-07-28T14:53:35+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Yazan:":"Dr.benjamin anderson","Tahmini okuma s\u00fcresi":"2 dakika"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/","url":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/","name":"Python&#39;da Mahalanobis mesafesi nas\u0131l hesaplan\u0131r - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/tr\/#website"},"datePublished":"2023-07-28T14:53:35+00:00","dateModified":"2023-07-28T14:53:35+00:00","author":{"@id":"https:\/\/statorials.org\/tr\/#\/schema\/person\/365dc158a39a7c8ae256355451e3de48"},"description":"Python&#39;da Mahalanobis mesafesinin nas\u0131l hesaplanaca\u011f\u0131na dair basit bir a\u00e7\u0131klama.","breadcrumb":{"@id":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/#breadcrumb"},"inLanguage":"tr","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/tr\/mahalanobis-uzak-pitonu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Ev","item":"https:\/\/statorials.org\/tr\/"},{"@type":"ListItem","position":2,"name":"Python&#39;da mahalanobis mesafesi nas\u0131l hesaplan\u0131r?"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/tr\/#website","url":"https:\/\/statorials.org\/tr\/","name":"Statorials","description":"\u0130statistik okuryazarl\u0131\u011f\u0131 rehberiniz!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/tr\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"tr"},{"@type":"Person","@id":"https:\/\/statorials.org\/tr\/#\/schema\/person\/365dc158a39a7c8ae256355451e3de48","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"tr","@id":"https:\/\/statorials.org\/tr\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/tr\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/tr\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Merhaba, ben Benjamin, emekli bir istatistik profes\u00f6r\u00fc ve Statorials \u00f6\u011fretmenine d\u00f6n\u00fc\u015ft\u00fcm. \u0130statistik alan\u0131ndaki kapsaml\u0131 deneyimim ve uzmanl\u0131\u011f\u0131mla, \u00f6\u011frencilerimi Statorials arac\u0131l\u0131\u011f\u0131yla g\u00fc\u00e7lendirmek i\u00e7in bilgilerimi payla\u015fmaya can at\u0131yorum. Daha fazlas\u0131n\u0131 bil","sameAs":["https:\/\/statorials.org\/tr"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/posts\/832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/comments?post=832"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/posts\/832\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/media?parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/categories?post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/tr\/wp-json\/wp\/v2\/tags?post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}