{"id":985,"date":"2023-07-28T02:22:40","date_gmt":"2023-07-28T02:22:40","guid":{"rendered":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/"},"modified":"2023-07-28T02:22:40","modified_gmt":"2023-07-28T02:22:40","slug":"shapiro-wilk-teste-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/","title":{"rendered":"Como realizar um teste shapiro-wilk em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">O <strong>teste Shapiro-Wilk<\/strong> \u00e9 um teste de normalidade. \u00c9 usado para determinar se uma amostra vem ou n\u00e3o de uma <a href=\"https:\/\/statorials.org\/pt\/a-distribuicao-normal\/\" target=\"_blank\" rel=\"noopener noreferrer\">distribui\u00e7\u00e3o normal<\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para realizar um teste Shapiro-Wilk em Python podemos usar a fun\u00e7\u00e3o <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.shapiro.html\" target=\"_blank\" rel=\"noopener noreferrer\">scipy.stats.shapiro()<\/a> , que utiliza a seguinte sintaxe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>scipy.stats.shapiro(x)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>x:<\/strong> uma tabela de dados de amostra.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Esta fun\u00e7\u00e3o retorna uma estat\u00edstica de teste e um valor p correspondente.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se o valor p estiver abaixo de um certo n\u00edvel de signific\u00e2ncia, ent\u00e3o temos evid\u00eancias suficientes para dizer que os dados da amostra n\u00e3o prov\u00eam de uma distribui\u00e7\u00e3o normal.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial mostra alguns exemplos de como usar esse recurso na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: teste Shapiro-Wilk em dados normalmente distribu\u00eddos<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que tenhamos os seguintes dados de amostra:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> numpy.random <span style=\"color: #008000;\">import<\/span> seed\n<span style=\"color: #008000;\">from<\/span> numpy.random <span style=\"color: #008000;\">import<\/span> randn\n\n<span style=\"color: #008080;\">#set seed (eg make this example reproducible)<\/span>\nseed(0)\n\n<span style=\"color: #008080;\">#generate dataset of 100 random values that follow a standard normal distribution\n<\/span>data = randn(100)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como realizar um teste de Shapiro-Wilk nesta amostra de 100 valores de dados para determinar se eles v\u00eam de uma distribui\u00e7\u00e3o normal:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> scipy.stats <span style=\"color: #008000;\">import<\/span> shapiro\n\n<span style=\"color: #008080;\">#perform Shapiro-Wilk test<\/span>\nshapiro(data)\n\nShapiroResult(statistic=0.9926937818527222, pvalue=0.8689165711402893)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A partir do resultado, podemos ver que a estat\u00edstica de teste \u00e9 <strong>0,9927<\/strong> e o valor p correspondente \u00e9 <strong>0,8689<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Como o valor p n\u00e3o \u00e9 inferior a 0,05, n\u00e3o rejeitamos a hip\u00f3tese nula. N\u00e3o temos evid\u00eancias suficientes para afirmar que os dados da amostra n\u00e3o prov\u00eam de uma distribui\u00e7\u00e3o normal.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este resultado n\u00e3o deve ser surpreendente, uma vez que geramos os dados amostrais usando a fun\u00e7\u00e3o <strong>randn()<\/strong> , que gera valores aleat\u00f3rios que seguem uma distribui\u00e7\u00e3o normal padr\u00e3o.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 2: teste de Shapiro-Wilk em dados distribu\u00eddos n\u00e3o normalmente<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Agora suponha que temos os seguintes dados de amostra:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> numpy.random <span style=\"color: #008000;\">import<\/span> seed\n<span style=\"color: #008000;\">from<\/span> numpy.random <span style=\"color: #008000;\">import<\/span> fish\n\n<span style=\"color: #008080;\">#set seed (eg make this example reproducible)<\/span>\nseed(0)\n\n<span style=\"color: #008080;\">#generate dataset of 100 values that follows a Poisson distribution with mean=5\n<\/span>data = fish(5, 100)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como realizar um teste de Shapiro-Wilk nesta amostra de 100 valores de dados para determinar se eles v\u00eam de uma distribui\u00e7\u00e3o normal:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> scipy.stats <span style=\"color: #008000;\">import<\/span> shapiro\n\n<span style=\"color: #008080;\">#perform Shapiro-Wilk test<\/span>\nshapiro(data)\n\nShapiroResult(statistic=0.9581913948059082, pvalue=0.002994443289935589)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A partir do resultado, podemos ver que a estat\u00edstica de teste \u00e9 <strong>0,9582<\/strong> e o valor p correspondente \u00e9 <strong>0,00299<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Como o valor p \u00e9 inferior a 0,05, rejeitamos a hip\u00f3tese nula. Temos evid\u00eancias suficientes para dizer que os dados da amostra n\u00e3o prov\u00eam de uma distribui\u00e7\u00e3o normal.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este resultado tamb\u00e9m n\u00e3o deve surpreender, j\u00e1 que geramos os dados amostrais utilizando a fun\u00e7\u00e3o <strong>Poisson()<\/strong> , que gera valores aleat\u00f3rios que seguem uma <a href=\"https:\/\/statorials.org\/pt\/distribuicao-de-peixe\/\" target=\"_blank\" rel=\"noopener noreferrer\">distribui\u00e7\u00e3o de Poisson<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outros testes de normalidade em v\u00e1rios softwares estat\u00edsticos:<\/span><\/p>\n<p><a href=\"https:\/\/statorials.org\/pt\/teste-shapiro-wilk-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Como realizar um teste de Shapiro-Wilk em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/anderson-cheri-teste-python\/\" target=\"_blank\" rel=\"noopener noreferrer\">Como realizar um teste Anderson-Darling em Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/\">Como realizar um teste Kolmogorov-Smirnov em Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O teste Shapiro-Wilk \u00e9 um teste de normalidade. \u00c9 usado para determinar se uma amostra vem ou n\u00e3o de uma distribui\u00e7\u00e3o normal . Para realizar um teste Shapiro-Wilk em Python podemos usar a fun\u00e7\u00e3o scipy.stats.shapiro() , que utiliza a seguinte sintaxe: scipy.stats.shapiro(x) Ouro: x: uma tabela de dados de amostra. Esta fun\u00e7\u00e3o retorna uma estat\u00edstica [&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-985","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 realizar um teste Shapiro-Wilk em Python - Estatologia<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.\" \/>\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\/shapiro-wilk-teste-python\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como realizar um teste Shapiro-Wilk em Python - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T02:22:40+00:00\" \/>\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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/\",\"name\":\"Como realizar um teste Shapiro-Wilk em Python - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T02:22:40+00:00\",\"dateModified\":\"2023-07-28T02:22:40+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como realizar um teste shapiro-wilk 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 realizar um teste Shapiro-Wilk em Python - Estatologia","description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.","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\/shapiro-wilk-teste-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como realizar um teste Shapiro-Wilk em Python - Estatologia","og_description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.","og_url":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T02:22:40+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/","url":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/","name":"Como realizar um teste Shapiro-Wilk em Python - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T02:22:40+00:00","dateModified":"2023-07-28T02:22:40+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Shapiro-Wilk de normalidade em Python, incluindo um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como realizar um teste shapiro-wilk 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\/985","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=985"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/985\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}