{"id":827,"date":"2023-07-28T15:10:19","date_gmt":"2023-07-28T15:10:19","guid":{"rendered":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/"},"modified":"2023-07-28T15:10:19","modified_gmt":"2023-07-28T15:10:19","slug":"matriz-de-correlacao-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/","title":{"rendered":"Como criar uma matriz de correla\u00e7\u00e3o em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Uma forma de quantificar a rela\u00e7\u00e3o entre duas vari\u00e1veis \u00e9 utilizar o <a href=\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-pearson-1\/\" target=\"_blank\" rel=\"noopener\">coeficiente de correla\u00e7\u00e3o de Pearson<\/a> , que \u00e9 uma medida da associa\u00e7\u00e3o linear entre duas vari\u00e1veis <em>.<\/em><\/span><\/p>\n<p> <span style=\"color: #000000;\">Assume um valor entre -1 e 1 onde:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">-1 indica uma correla\u00e7\u00e3o linear perfeitamente negativa.<\/span><\/li>\n<li> <span style=\"color: #000000;\">0 indica nenhuma correla\u00e7\u00e3o linear.<\/span><\/li>\n<li> <span style=\"color: #000000;\">1 indica uma correla\u00e7\u00e3o linear perfeitamente positiva.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Quanto mais longe o coeficiente de correla\u00e7\u00e3o estiver de zero, mais forte ser\u00e1 a rela\u00e7\u00e3o entre as duas vari\u00e1veis.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Mas, em alguns casos, queremos compreender a correla\u00e7\u00e3o entre m\u00faltiplos pares de vari\u00e1veis. Nestes casos, podemos criar uma <a href=\"https:\/\/statorials.org\/pt\/como-ler-uma-matriz-de-correlacao\/\" target=\"_blank\" rel=\"noopener\">matriz de correla\u00e7\u00e3o<\/a> , que \u00e9 uma tabela quadrada que mostra os coeficientes de correla\u00e7\u00e3o entre v\u00e1rias combina\u00e7\u00f5es de vari\u00e1veis aos pares.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica como criar e interpretar uma matriz de correla\u00e7\u00e3o em Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Como criar uma matriz de correla\u00e7\u00e3o em Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Use as etapas a seguir para criar uma matriz de correla\u00e7\u00e3o em Python.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Etapa 1: crie o conjunto de dados.<\/strong><\/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 = {'assists': [4, 5, 5, 6, 7, 8, 8, 10],\n        'rebounds': [12, 14, 13, 7, 8, 8, 9, 13],\n        'points': [22, 24, 26, 26, 29, 32, 20, 14]\n        }\n\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> (data, columns=['assists','rebounds','points'])\ndf\n\n   assist rebound points\n0 4 12 22\n1 5 14 24\n2 5 13 26\n3 6 7 26\n4 7 8 29\n5 8 8 32\n6 8 9 20\n7 10 13 14\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Etapa 2: Crie a matriz de correla\u00e7\u00e3o.<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create correlation matrix<\/span>\ndf. <span style=\"color: #3366ff;\">corr<\/span> ()\n\n                assists rebound points\nassists 1.000000 -0.244861 -0.329573\nrebounds -0.244861 1.000000 -0.522092\npoints -0.329573 -0.522092 1.000000\n\n<span style=\"color: #008080;\">#create same correlation matrix with coefficients rounded to 3 decimals<\/span> \ndf. <span style=\"color: #3366ff;\">corr<\/span> (). <span style=\"color: #3366ff;\">round<\/span> (3)\n\t       assists rebound points\nassists 1.000 -0.245 -0.330\nrebounds -0.245 1.000 -0.522\npoints -0.330 -0.522 1.000\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Etapa 3: Interprete a matriz de correla\u00e7\u00e3o.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Os coeficientes de correla\u00e7\u00e3o ao longo da diagonal da tabela s\u00e3o todos iguais a 1 porque cada vari\u00e1vel est\u00e1 perfeitamente correlacionada consigo mesma.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Todos os outros coeficientes de correla\u00e7\u00e3o indicam a correla\u00e7\u00e3o entre diferentes combina\u00e7\u00f5es de vari\u00e1veis aos pares. Por exemplo:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">O coeficiente de correla\u00e7\u00e3o entre assist\u00eancias e rebotes \u00e9 <strong>de -0,245<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">O coeficiente de correla\u00e7\u00e3o entre assist\u00eancias e pontos \u00e9 <strong>-0,330<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">O coeficiente de correla\u00e7\u00e3o entre rebotes e pontos \u00e9 <strong>-0,522<\/strong> .<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Passo 4: Visualize a matriz de correla\u00e7\u00e3o (opcional).<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Voc\u00ea pode visualizar a matriz de correla\u00e7\u00e3o usando as <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/user_guide\/style.html\" target=\"_blank\" rel=\"noopener\">op\u00e7\u00f5es de estilo<\/a> dispon\u00edveis no pandas:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>corr = df. <span style=\"color: #3366ff;\">corr<\/span> ()\ncorr. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">background_gradient<\/span> (cmap='coolwarm')\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9176 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython1.png\" alt=\"Matriz de Correla\u00e7\u00e3o em Python\" width=\"309\" height=\"135\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Voc\u00ea tamb\u00e9m pode modificar o argumento <strong>cmap<\/strong> para produzir uma matriz de correla\u00e7\u00e3o com cores diferentes.<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>corr = df. <span style=\"color: #3366ff;\">corr<\/span> ()\ncorr. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">background_gradient<\/span> (cmap=' <span style=\"color: #800080;\">RdYlGn<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9177 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython2.png\" alt=\"Matriz de correla\u00e7\u00e3o com matplotlib em Python\" width=\"297\" height=\"125\" srcset=\"\" sizes=\"auto, \"><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>corr = df. <span style=\"color: #3366ff;\">corr<\/span> ()\ncorr. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">background_gradient<\/span> (cmap=' <span style=\"color: #800080;\">bwr<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9179 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython3.png\" alt=\"Matriz de correla\u00e7\u00e3o usando Pandas\" width=\"309\" height=\"125\" srcset=\"\" sizes=\"auto, \"><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>corr = df. <span style=\"color: #3366ff;\">corr<\/span> ()\ncorr. <span style=\"color: #3366ff;\">style<\/span> . <span style=\"color: #3366ff;\">background_gradient<\/span> (cmap=' <span style=\"color: #800080;\">PuOr<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-9180 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython4.png\" alt=\"Exemplo de matriz de correla\u00e7\u00e3o em Python\" width=\"306\" height=\"125\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : Para obter uma lista completa dos argumentos <strong>do cmap<\/strong> , consulte a <a href=\"https:\/\/matplotlib.org\/stable\/tutorials\/colors\/colormaps.html\" target=\"_blank\" rel=\"noopener\">documenta\u00e7\u00e3o do matplotlib<\/a> .<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uma forma de quantificar a rela\u00e7\u00e3o entre duas vari\u00e1veis \u00e9 utilizar o coeficiente de correla\u00e7\u00e3o de Pearson , que \u00e9 uma medida da associa\u00e7\u00e3o linear entre duas vari\u00e1veis . Assume um valor entre -1 e 1 onde: -1 indica uma correla\u00e7\u00e3o linear perfeitamente negativa. 0 indica nenhuma correla\u00e7\u00e3o linear. 1 indica uma correla\u00e7\u00e3o linear perfeitamente [&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-827","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.\" \/>\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\/pt\/matriz-de-correlacao-python\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T15:10:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython1.png\" \/>\n<meta name=\"author\" content=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/\",\"name\":\"Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T15:10:19+00:00\",\"dateModified\":\"2023-07-28T15:10:19+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como criar uma matriz de correla\u00e7\u00e3o em python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia","description":"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.","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\/pt\/matriz-de-correlacao-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia","og_description":"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T15:10:19+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/correlationmatrixpython1.png"}],"author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/","url":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/","name":"Como criar uma matriz de correla\u00e7\u00e3o em Python \u2013 Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T15:10:19+00:00","dateModified":"2023-07-28T15:10:19+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples de como criar uma matriz de correla\u00e7\u00e3o em Python, incluindo v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/matriz-de-correlacao-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como criar uma matriz de correla\u00e7\u00e3o em python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}