{"id":824,"date":"2023-07-28T15:21:12","date_gmt":"2023-07-28T15:21:12","guid":{"rendered":"https:\/\/statorials.org\/de\/korrelation-in-python\/"},"modified":"2023-07-28T15:21:12","modified_gmt":"2023-07-28T15:21:12","slug":"korrelation-in-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/korrelation-in-python\/","title":{"rendered":"So berechnen sie die korrelation in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Eine M\u00f6glichkeit, die Beziehung zwischen zwei Variablen zu quantifizieren, ist die Verwendung des <a href=\"https:\/\/statorials.org\/de\/pearson-korrelationskoeffizient-1\/\" target=\"_blank\" rel=\"noopener\">Pearson-Korrelationskoeffizienten<\/a> , der ein Ma\u00df f\u00fcr den linearen Zusammenhang zwischen zwei Variablen ist <em>.<\/em> Es nimmt immer einen Wert zwischen -1 und 1 an, wobei:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">-1 zeigt eine vollkommen negative lineare Korrelation zwischen zwei Variablen an<\/span><\/li>\n<li> <span style=\"color: #000000;\">0 bedeutet, dass zwischen zwei Variablen keine lineare Korrelation besteht<\/span><\/li>\n<li> <span style=\"color: #000000;\">1 zeigt eine vollkommen positive lineare Korrelation zwischen zwei Variablen an<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Je weiter der Korrelationskoeffizient von Null entfernt ist, desto st\u00e4rker ist die Beziehung zwischen den beiden Variablen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In diesem Tutorial wird erl\u00e4utert, wie Sie die Korrelation zwischen Variablen in Python berechnen.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">So berechnen Sie die Korrelation in Python<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Um die Korrelation zwischen zwei Variablen in Python zu berechnen, k\u00f6nnen wir die Funktion Numpy <strong>corrcoef()<\/strong> verwenden.<\/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\nnp.random.seed(100)\n\n<span style=\"color: #008080;\">#create array of 50 random integers between 0 and 10<\/span>\nvar1 = np.random.randint(0, 10, 50)\n\n<span style=\"color: #008080;\">#create a positively correlated array with some random noise\n<\/span>var2 = var1 + np.random.normal(0, 10, 50)\n\n<span style=\"color: #008080;\">#calculate the correlation between the two arrays\n<\/span>np.corrcoef(var1, var2)\n\n[[ 1. 0.335]\n[ 0.335 1. ]]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Es ist ersichtlich, dass der Korrelationskoeffizient zwischen diesen beiden Variablen <strong>0,335<\/strong> betr\u00e4gt, was einer positiven Korrelation entspricht.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Standardm\u00e4\u00dfig erzeugt diese Funktion eine Matrix von Korrelationskoeffizienten. Wenn wir nur den Korrelationskoeffizienten zwischen den beiden Variablen zur\u00fcckgeben wollten, k\u00f6nnten wir die folgende Syntax verwenden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>np.corrcoef(var1, var2)[0,1]\n\n0.335\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Um zu testen, ob diese Korrelation statistisch signifikant ist, k\u00f6nnen wir den mit dem Pearson-Korrelationskoeffizienten verbundenen p-Wert mithilfe der Scipy-Funktion \u201e <strong>pearsonr()\u201c<\/strong> berechnen, die sowohl den Pearson-Korrelationskoeffizienten als auch den zweiseitigen p-Wert zur\u00fcckgibt.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> scipy.stats.stats <span style=\"color: #107d3f;\">import<\/span> pearsonr\n\npearsonr(var1, var2)\n\n(0.335, 0.017398)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Der Korrelationskoeffizient betr\u00e4gt <strong>0,335<\/strong> und der zweiseitige p-Wert betr\u00e4gt <strong>0,017<\/strong> . Da dieser p-Wert kleiner als 0,05 ist, w\u00fcrden wir daraus schlie\u00dfen, dass eine statistisch signifikante Korrelation zwischen den beiden Variablen besteht.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wenn Sie die Korrelation zwischen mehreren Variablen in einem Pandas DataFrame berechnen m\u00f6chten, k\u00f6nnen Sie einfach die Funktion <strong>.corr()<\/strong> verwenden.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> pandas <span style=\"color: #107d3f;\">as<\/span> pd\n\ndata = pd.DataFrame(np.random.randint(0, 10, size=(5, 3)), columns=['A', 'B', 'C'])\ndata\n\n  ABC\n0 8 0 9\n1 4 0 7\n2 9 6 8\n3 1 8 1\n4 8 0 8\n\n<span style=\"color: #008080;\">#calculate correlation coefficients for all pairwise combinations\n<\/span>data.corr()\n\n          ABC\nA 1.000000 -0.775567 -0.493769\nB -0.775567 1.000000 0.000000\nC -0.493769 0.000000 1.000000\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Und wenn Sie nur die Korrelation zwischen zwei bestimmten Variablen im DataFrame berechnen m\u00f6chten, k\u00f6nnen Sie die Variablen angeben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>data['A'].corr(data['B'])\n\n-0.775567\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Zus\u00e4tzliche Ressourcen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Die folgenden Tutorials erkl\u00e4ren, wie Sie andere h\u00e4ufige Aufgaben in Python ausf\u00fchren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/de\/python-korrelationsmatrix\/\" target=\"_blank\" rel=\"noopener\">So erstellen Sie eine Korrelationsmatrix in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/korrelation-spearman-python\/\" target=\"_blank\" rel=\"noopener\">So berechnen Sie die Spearman-Rangkorrelation in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/autokorrelations-python\/\" target=\"_blank\" rel=\"noopener\">So berechnen Sie die Autokorrelation in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eine M\u00f6glichkeit, die Beziehung zwischen zwei Variablen zu quantifizieren, ist die Verwendung des Pearson-Korrelationskoeffizienten , der ein Ma\u00df f\u00fcr den linearen Zusammenhang zwischen zwei Variablen ist . Es nimmt immer einen Wert zwischen -1 und 1 an, wobei: -1 zeigt eine vollkommen negative lineare Korrelation zwischen zwei Variablen an 0 bedeutet, dass zwischen zwei Variablen [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>So berechnen Sie die Korrelation in Python \u2013 Statistik<\/title>\n<meta name=\"description\" content=\"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.\" \/>\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\/de\/korrelation-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So berechnen Sie die Korrelation in Python \u2013 Statistik\" \/>\n<meta property=\"og:description\" content=\"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/korrelation-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T15:21:12+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=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/korrelation-in-python\/\",\"url\":\"https:\/\/statorials.org\/de\/korrelation-in-python\/\",\"name\":\"So berechnen Sie die Korrelation in Python \u2013 Statistik\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-28T15:21:12+00:00\",\"dateModified\":\"2023-07-28T15:21:12+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/korrelation-in-python\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/korrelation-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/korrelation-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So berechnen sie die korrelation in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/de\/#website\",\"url\":\"https:\/\/statorials.org\/de\/\",\"name\":\"Statorials\",\"description\":\"Ihr Leitfaden f\u00fcr statistische Kompetenz !\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de-DE\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\",\"name\":\"Dr. Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de-DE\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. Benjamin Anderson\"},\"description\":\"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen\",\"sameAs\":[\"https:\/\/statorials.org\/de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"So berechnen Sie die Korrelation in Python \u2013 Statistik","description":"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.","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\/de\/korrelation-in-python\/","og_locale":"de_DE","og_type":"article","og_title":"So berechnen Sie die Korrelation in Python \u2013 Statistik","og_description":"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.","og_url":"https:\/\/statorials.org\/de\/korrelation-in-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T15:21:12+00:00","author":"Dr. Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr. Benjamin Anderson","Gesch\u00e4tzte Lesezeit":"2 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/korrelation-in-python\/","url":"https:\/\/statorials.org\/de\/korrelation-in-python\/","name":"So berechnen Sie die Korrelation in Python \u2013 Statistik","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-28T15:21:12+00:00","dateModified":"2023-07-28T15:21:12+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"Eine einfache Erkl\u00e4rung, wie man die Korrelation zwischen Variablen in Python berechnet.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/korrelation-in-python\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/korrelation-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/korrelation-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So berechnen sie die korrelation in python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/de\/#website","url":"https:\/\/statorials.org\/de\/","name":"Statorials","description":"Ihr Leitfaden f\u00fcr statistische Kompetenz !","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de-DE"},{"@type":"Person","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0","name":"Dr. Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"de-DE","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Dr. Benjamin Anderson"},"description":"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen","sameAs":["https:\/\/statorials.org\/de"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/824"}],"collection":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/comments?post=824"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/824\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}