{"id":2141,"date":"2023-07-23T12:36:51","date_gmt":"2023-07-23T12:36:51","guid":{"rendered":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/"},"modified":"2023-07-23T12:36:51","modified_gmt":"2023-07-23T12:36:51","slug":"python-matrix-verwirrung","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/","title":{"rendered":"So erstellen sie eine verwirrungsmatrix in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/de\/logistische-regression-1\/\" target=\"_blank\" rel=\"noopener\">Die logistische Regression<\/a> ist eine Art Regression, die wir verwenden k\u00f6nnen, wenn die Antwortvariable bin\u00e4r ist.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Eine g\u00e4ngige Methode zur Beurteilung der Qualit\u00e4t eines logistischen Regressionsmodells besteht darin, eine <strong>Verwirrungsmatrix<\/strong> zu erstellen, bei der es sich um eine 2 \u00d7 2-Tabelle handelt, die die vorhergesagten Werte des Modells im Vergleich zu den tats\u00e4chlichen Werten des Testdatensatzes zeigt.<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-15654 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/confusionr1.png\" alt=\"\" width=\"292\" height=\"129\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Um eine Verwirrungsmatrix f\u00fcr ein logistisches Regressionsmodell in Python zu erstellen, k\u00f6nnen wir die Funktion <strong>confusion_matrix()<\/strong> aus dem <a href=\"https:\/\/scikit-learn.org\/stable\/\" target=\"_blank\" rel=\"noopener\">sklearn-<\/a> Paket verwenden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn <span style=\"color: #008000;\">import<\/span> metrics\nmetrics.metrics. <span style=\"color: #3366ff;\">confusion_matrix<\/span> (y_actual, y_predicted)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Das folgende Beispiel zeigt, wie Sie mit dieser Funktion eine Verwirrungsmatrix f\u00fcr ein logistisches Regressionsmodell in Python erstellen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Beispiel: Erstellen einer Verwirrungsmatrix in Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Angenommen, wir haben die folgenden zwei Tabellen, die die tats\u00e4chlichen Werte einer Antwortvariablen sowie die von einem logistischen Regressionsmodell vorhergesagten Werte enthalten:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define array of actual values\n<\/span>y_actual = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n\n<span style=\"color: #008080;\">#define array of predicted values\n<\/span>y_predicted = [0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen die Funktion <strong>\u201econfusion_matrix()\u201c<\/strong> von sklearn verwenden, um eine Verwirrungsmatrix f\u00fcr diese Daten zu erstellen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn <span style=\"color: #008000;\">import<\/span> metrics\n\n<span style=\"color: #008080;\">#create confusion matrix\n<\/span>c_matrix = metrics. <span style=\"color: #3366ff;\">confusion_matrix<\/span> (y_actual, y_predicted)\n\n<span style=\"color: #008080;\">#print confusion matrix\n<\/span><span style=\"color: #ff0000;\">print<\/span> (c_matrix)\n\n[[6 4]\n [2 8]]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wenn wir m\u00f6chten, k\u00f6nnen wir die Funktion <strong>crosstab()<\/strong> von Pandas verwenden, um eine optisch ansprechendere Verwirrungsmatrix zu erstellen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\ny_actual = pd. <span style=\"color: #3366ff;\">Series<\/span> (y_actual, name=' <span style=\"color: #ff0000;\">Actual<\/span> ')\ny_predicted = pd. <span style=\"color: #3366ff;\">Series<\/span> (y_predicted, name=' <span style=\"color: #ff0000;\">Predicted<\/span> ')\n\n<span style=\"color: #008080;\">#create confusion matrix<\/span>\n<span style=\"color: #ff0000;\">print<\/span> (pd. <span style=\"color: #3366ff;\">crosstab<\/span> (y_actual, y_predicted))\n\nPredicted 0 1\nCurrent         \n0 6 4\n1 2 8<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Die Spalten zeigen die vorhergesagten Werte f\u00fcr die Antwortvariable und die Zeilen zeigen die tats\u00e4chlichen Werte.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen Genauigkeit, Pr\u00e4zision und R\u00fcckruf auch mithilfe der Funktionen im sklearn-Paket berechnen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#print accuracy of model\n<\/span><span style=\"color: #ff0000;\">print<\/span> ( <span style=\"color: #3366ff;\">metrics.accuracy_score<\/span> (y_actual, y_predicted))\n\n0.7\n\n<span style=\"color: #008080;\">#print precision value of model\n<\/span><span style=\"color: #ff0000;\">print<\/span> ( <span style=\"color: #3366ff;\">metrics.precision_score<\/span> (y_actual, y_predicted))\n\n0.667\n\n<span style=\"color: #008080;\">#print recall value of model\n<\/span><span style=\"color: #ff0000;\">print<\/span> (metrics. <span style=\"color: #3366ff;\">recall_score<\/span> (y_actual, y_predicted))\n\n0.8\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Hier ist eine kurze Auffrischung zu Genauigkeit, Pr\u00e4zision und R\u00fcckruf:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Genauigkeit<\/strong> : Prozentsatz der richtigen Vorhersagen<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Genauigkeit<\/strong> : Korrigieren Sie positive Vorhersagen im Verh\u00e4ltnis zur Gesamtzahl der positiven Vorhersagen<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Erinnerung<\/strong> : Korrigieren Sie positive Vorhersagen anhand der gesamten tats\u00e4chlichen positiven Ergebnisse<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Und so wurde jede dieser Metriken in unserem Beispiel tats\u00e4chlich berechnet:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Genauigkeit<\/strong> : (6+8) \/ (6+4+2+8) = <strong>0,7<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Genauigkeit<\/strong> : 8 \/ (8+4) = <strong>0,667<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Erinnerung<\/strong> : 8 \/ (2+8) = <strong>0,8<\/strong><\/span><\/li>\n<\/ul>\n<h3> <span style=\"color: #000000;\"><strong>Zus\u00e4tzliche Ressourcen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/de\/logistische-regression-1\/\" target=\"_blank\" rel=\"noopener\">Einf\u00fchrung in die logistische Regression<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/arten-der-logistischen-regression\/\" target=\"_blank\" rel=\"noopener\">Die 3 Arten der logistischen Regression<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/logistische-regression-vs.-lineare-regression\/\" target=\"_blank\" rel=\"noopener\">Logistische Regression vs. lineare Regression<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Die logistische Regression ist eine Art Regression, die wir verwenden k\u00f6nnen, wenn die Antwortvariable bin\u00e4r ist. Eine g\u00e4ngige Methode zur Beurteilung der Qualit\u00e4t eines logistischen Regressionsmodells besteht darin, eine Verwirrungsmatrix zu erstellen, bei der es sich um eine 2 \u00d7 2-Tabelle handelt, die die vorhergesagten Werte des Modells im Vergleich zu den tats\u00e4chlichen Werten des [&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 erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.\" \/>\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\/python-matrix-verwirrung\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T12:36:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/confusionr1.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\/python-matrix-verwirrung\/\",\"url\":\"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/\",\"name\":\"So erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-23T12:36:51+00:00\",\"dateModified\":\"2023-07-23T12:36:51+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So erstellen sie eine verwirrungsmatrix 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 erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials","description":"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.","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\/python-matrix-verwirrung\/","og_locale":"de_DE","og_type":"article","og_title":"So erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials","og_description":"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.","og_url":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/","og_site_name":"Statorials","article_published_time":"2023-07-23T12:36:51+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/confusionr1.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\/python-matrix-verwirrung\/","url":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/","name":"So erstellen Sie eine Verwirrungsmatrix in Python \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-23T12:36:51+00:00","dateModified":"2023-07-23T12:36:51+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird anhand von Beispielen erl\u00e4utert, wie Sie eine Verwirrungsmatrix in Python erstellen.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/python-matrix-verwirrung\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/python-matrix-verwirrung\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So erstellen sie eine verwirrungsmatrix 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\/2141"}],"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=2141"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/2141\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=2141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=2141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=2141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}