{"id":986,"date":"2023-07-28T02:15:25","date_gmt":"2023-07-28T02:15:25","guid":{"rendered":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/"},"modified":"2023-07-28T02:15:25","modified_gmt":"2023-07-28T02:15:25","slug":"kolmogorov-smirnov-teste-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/","title":{"rendered":"Como realizar um teste kolmogorov-smirnov em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">O <strong>teste Kolmogorov-Smirnov<\/strong> \u00e9 usado para testar se uma amostra vem ou n\u00e3o de uma determinada distribui\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para realizar um teste Kolmogorov-Smirnov em Python, podemos usar <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.kstest.html\" target=\"_blank\" rel=\"noopener noreferrer\">scipy.stats.kstest()<\/a> para um teste de uma amostra ou <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.ks_2samp.html#scipy.stats.ks_2samp\" target=\"_blank\" rel=\"noopener noreferrer\">scipy.stats.ks_2samp()<\/a> para um teste de duas amostras.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial mostra um exemplo de como usar cada fun\u00e7\u00e3o na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: Uma amostra de teste Kolmogorov-Smirnov<\/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> 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 Kolmogorov-Smirnov 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> kstest\n\n<span style=\"color: #008080;\">#perform Kolmogorov-Smirnov test<\/span>\nkstest(data, ' <span style=\"color: #993300;\">norm<\/span> ')\n\nKstestResult(statistic=0.9072498680518208, pvalue=1.0908062873170218e-103)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A partir do resultado, podemos ver que a estat\u00edstica de teste \u00e9 <strong>0,9072<\/strong> e o valor p correspondente \u00e9 <strong>1,0908e-103<\/strong> . 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>Exemplo 2: Teste de Kolmogorov-Smirnov de duas amostras<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Digamos que temos os dois conjuntos de dados de amostra a seguir:<\/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<span style=\"color: #008000;\">from<\/span> numpy.random <span style=\"color: #008000;\">import<\/span> lognormal\n\n<span style=\"color: #008080;\">#set seed (eg make this example reproducible)<\/span>\nseed(0)\n\n<span style=\"color: #008080;\">#generate two datasets\n<\/span>data1 = randn(100)\ndata2 = lognormal(3, 1, 100)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como realizar um teste de Kolmogorov-Smirnov nessas duas amostras para determinar se elas v\u00eam da mesma distribui\u00e7\u00e3o:<\/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> ks_2samp\n\n<span style=\"color: #008080;\">#perform Kolmogorov-Smirnov test<\/span>\nks_2samp(data1, data2)\n\nKstestResult(statistic=0.99, pvalue=4.417521386399011e-57)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A partir do resultado, podemos ver que a estat\u00edstica de teste \u00e9 <strong>0,99<\/strong> e o valor p correspondente \u00e9 <strong>4,4175e-57<\/strong> . Como o valor p \u00e9 inferior a 0,05, rejeitamos a hip\u00f3tese nula. Temos evid\u00eancias suficientes para dizer que os dois conjuntos de dados de amostra n\u00e3o pertencem \u00e0 mesma distribui\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este resultado tamb\u00e9m n\u00e3o deve surpreender, uma vez que geramos valores para a primeira amostra usando a distribui\u00e7\u00e3o normal padr\u00e3o e valores para a segunda amostra usando a distribui\u00e7\u00e3o lognormal.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/shapiro-wilk-teste-python\/\">Como realizar um teste Shapiro-Wilk em Python<\/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><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O teste Kolmogorov-Smirnov \u00e9 usado para testar se uma amostra vem ou n\u00e3o de uma determinada distribui\u00e7\u00e3o. Para realizar um teste Kolmogorov-Smirnov em Python, podemos usar scipy.stats.kstest() para um teste de uma amostra ou scipy.stats.ks_2samp() para um teste de duas amostras. Este tutorial mostra um exemplo de como usar cada fun\u00e7\u00e3o na pr\u00e1tica. Exemplo 1: [&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-986","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 Kolmogorov-Smirnov em Python - Estatologia<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov 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\/kolmogorov-smirnov-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 Kolmogorov-Smirnov em Python - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov em Python, incluindo v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T02:15:25+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=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/\",\"name\":\"Como realizar um teste Kolmogorov-Smirnov em Python - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T02:15:25+00:00\",\"dateModified\":\"2023-07-28T02:15:25+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov em Python, incluindo v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como realizar um teste kolmogorov-smirnov 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 Kolmogorov-Smirnov em Python - Estatologia","description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov 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\/kolmogorov-smirnov-teste-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como realizar um teste Kolmogorov-Smirnov em Python - Estatologia","og_description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov em Python, incluindo v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T02:15:25+00:00","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\/kolmogorov-smirnov-teste-python\/","url":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/","name":"Como realizar um teste Kolmogorov-Smirnov em Python - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T02:15:25+00:00","dateModified":"2023-07-28T02:15:25+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples de como realizar um teste Kolmogorov-Smirnov em Python, incluindo v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/kolmogorov-smirnov-teste-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como realizar um teste kolmogorov-smirnov 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\/986","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=986"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/986\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}