{"id":876,"date":"2023-07-28T11:11:00","date_gmt":"2023-07-28T11:11:00","guid":{"rendered":"https:\/\/statorials.org\/de\/autokorrelations-python\/"},"modified":"2023-07-28T11:11:00","modified_gmt":"2023-07-28T11:11:00","slug":"autokorrelations-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/autokorrelations-python\/","title":{"rendered":"So berechnen sie die autokorrelation in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Die Autokorrelation<\/strong> misst den Grad der \u00c4hnlichkeit zwischen einer Zeitreihe und einer verz\u00f6gerten Version ihrer selbst \u00fcber aufeinanderfolgende Zeitintervalle.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Sie wird manchmal auch als \u201eserielle Korrelation\u201c oder \u201everz\u00f6gerte Korrelation\u201c bezeichnet, da sie die Beziehung zwischen den aktuellen Werten einer Variablen und ihren historischen Werten misst.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wenn die Autokorrelation in einer Zeitreihe hoch ist, ist es einfach, zuk\u00fcnftige Werte vorherzusagen, indem einfach auf vergangene Werte verwiesen wird.<\/span><\/p>\n<h3> <strong>So berechnen Sie die Autokorrelation in Python<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Angenommen, wir haben die folgende Zeitreihe in Python, die den Wert einer bestimmten Variablen f\u00fcr 15 verschiedene Zeitr\u00e4ume zeigt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define data<\/span>\nx = [22, 24, 25, 25, 28, 29, 34, 37, 40, 44, 51, 48, 47, 50, 51]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen die Autokorrelation f\u00fcr jede Verz\u00f6gerung in der Zeitreihe mithilfe der <a href=\"https:\/\/www.statsmodels.org\/stable\/generated\/statsmodels.tsa.stattools.acf.html\" target=\"_blank\" rel=\"noopener noreferrer\">Funktion acf()<\/a> aus der Statsmodels-Bibliothek berechnen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> statsmodels.api <span style=\"color: #107d3f;\">as<\/span> sm\n\n<span style=\"color: #008080;\">#calculate autocorrelations<\/span>\nsm.tsa.acf(x)\n\narray([ 1. , 0.83174224, 0.65632458, 0.49105012, 0.27863962,\n        0.03102625, -0.16527446, -0.30369928, -0.40095465, -0.45823389,\n       -0.45047733])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Das Ergebnis l\u00e4sst sich wie folgt interpretieren:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Die Autokorrelation bei Verz\u00f6gerung 0 ist <strong>1<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Die Autokorrelation bei Verz\u00f6gerung 1 betr\u00e4gt <strong>0,8317<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Die Autokorrelation bei Verz\u00f6gerung 2 betr\u00e4gt <strong>0,6563<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Die Autokorrelation bei Verz\u00f6gerung 3 betr\u00e4gt <strong>0,4910<\/strong> .<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Und so weiter.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Mit dem Argument <strong>nlags<\/strong> k\u00f6nnen wir auch die Anzahl der zu verwendenden Verz\u00f6gerungen angeben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sm.tsa.acf(x, nlags= <span style=\"color: #008000;\">5<\/span> )\n\narray([1.0, 0.83174224, 0.65632458, 0.49105012, 0.27863962, 0.03102625])<\/strong><\/pre>\n<h3> <strong>So zeichnen Sie eine Autokorrelationsfunktion in Python auf<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen die Autokorrelationsfunktion f\u00fcr eine Zeitreihe in Python mit der <a href=\"https:\/\/www.statsmodels.org\/dev\/generated\/statsmodels.graphics.tsaplots.plot_acf.html\" target=\"_blank\" rel=\"noopener noreferrer\">Funktion tsaplots.plot_acf()<\/a> aus der statsmodels-Bibliothek zeichnen:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> statsmodels.graphics <span style=\"color: #107d3f;\">import<\/span> tsaplots\n<span style=\"color: #107d3f;\">import<\/span> matplotlib.pyplot <span style=\"color: #107d3f;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#plot autocorrelation function<\/span>\nfig = tsaplots.plot_acf(x, lags=10)\nplt.show()<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9480 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/autocorrelationpython1.png\" alt=\"Autokorrelationsfunktion in Python\" width=\"495\" height=\"343\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Die x-Achse zeigt die Anzahl der Verz\u00f6gerungen und die y-Achse zeigt die Autokorrelation bei dieser Anzahl von Verz\u00f6gerungen an. Standardm\u00e4\u00dfig beginnt die Darstellung bei Lag = 0 und die Autokorrelation ist bei Lag = 0 immer <strong>1<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen die ersten Verz\u00f6gerungen auch vergr\u00f6\u00dfern, indem wir mit dem Argument <strong>\u201eLags\u201c<\/strong> die Verwendung weniger Verz\u00f6gerungen ausw\u00e4hlen:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> statsmodels.graphics <span style=\"color: #107d3f;\">import<\/span> tsaplots\n<span style=\"color: #107d3f;\">import<\/span> matplotlib.pyplot <span style=\"color: #107d3f;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#plot autocorrelation function<\/span>\nfig = tsaplots.plot_acf(x, lags= <span style=\"color: #008000;\">5<\/span> )\nplt.show()<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9481 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/autocorrelationpython2.png\" alt=\"Zeichnen einer Autokorrelationsfunktion in Python\" width=\"495\" height=\"329\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Sie k\u00f6nnen auch den Titel und die Farbe der im Plot verwendeten Kreise mit den Argumenten <strong>title<\/strong> und <strong>color<\/strong> \u00e4ndern:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> statsmodels.graphics <span style=\"color: #107d3f;\">import<\/span> tsaplots\n<span style=\"color: #107d3f;\">import<\/span> matplotlib.pyplot <span style=\"color: #107d3f;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#plot autocorrelation function<\/span>\nfig = tsaplots.plot_acf(x, lags= <span style=\"color: #008000;\"><span style=\"color: #000000;\">5, color='g', title='Autocorrelation function'<\/span><\/span> <span style=\"color: #000000;\">)<\/span>\nplt.show()<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9482 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/autocorrelationpython4.png\" alt=\"Autokorrelationsfunktion in Python mit benutzerdefiniertem Titel\" width=\"499\" height=\"342\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\"><em>Weitere Python-Tutorials finden Sie auf <a href=\"https:\/\/statorials.org\/de\/die-statistik-erklart-konzepte-auf-einfache-und-direkte-weise.-wir-erleichtern-das-erlernen-von-statistiken\/\" target=\"_blank\" rel=\"noopener noreferrer\">dieser Seite<\/a> .<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Die Autokorrelation misst den Grad der \u00c4hnlichkeit zwischen einer Zeitreihe und einer verz\u00f6gerten Version ihrer selbst \u00fcber aufeinanderfolgende Zeitintervalle. Sie wird manchmal auch als \u201eserielle Korrelation\u201c oder \u201everz\u00f6gerte Korrelation\u201c bezeichnet, da sie die Beziehung zwischen den aktuellen Werten einer Variablen und ihren historischen Werten misst. Wenn die Autokorrelation in einer Zeitreihe hoch ist, ist es [&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 Autokorrelation in Python - Statorials<\/title>\n<meta name=\"description\" content=\"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.\" \/>\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\/autokorrelations-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 Autokorrelation in Python - Statorials\" \/>\n<meta property=\"og:description\" content=\"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/autokorrelations-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T11:11:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/autocorrelationpython1.png\" \/>\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\/autokorrelations-python\/\",\"url\":\"https:\/\/statorials.org\/de\/autokorrelations-python\/\",\"name\":\"So berechnen Sie die Autokorrelation in Python - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-28T11:11:00+00:00\",\"dateModified\":\"2023-07-28T11:11:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/autokorrelations-python\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/autokorrelations-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/autokorrelations-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So berechnen sie die autokorrelation 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 Autokorrelation in Python - Statorials","description":"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.","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\/autokorrelations-python\/","og_locale":"de_DE","og_type":"article","og_title":"So berechnen Sie die Autokorrelation in Python - Statorials","og_description":"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.","og_url":"https:\/\/statorials.org\/de\/autokorrelations-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T11:11:00+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/autocorrelationpython1.png"}],"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\/autokorrelations-python\/","url":"https:\/\/statorials.org\/de\/autokorrelations-python\/","name":"So berechnen Sie die Autokorrelation in Python - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-28T11:11:00+00:00","dateModified":"2023-07-28T11:11:00+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"Eine einfache Erkl\u00e4rung zum Berechnen und Zeichnen einer Autokorrelationsfunktion in Python.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/autokorrelations-python\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/autokorrelations-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/autokorrelations-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So berechnen sie die autokorrelation 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\/876"}],"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=876"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/876\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}