{"id":987,"date":"2023-07-28T02:15:25","date_gmt":"2023-07-28T02:15:25","guid":{"rendered":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/"},"modified":"2023-07-28T02:15:25","modified_gmt":"2023-07-28T02:15:25","slug":"kolmogorov-smirnov-prova-pitone","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/","title":{"rendered":"Come eseguire un test di kolmogorov-smirnov in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Il <strong>test di Kolmogorov-Smirnov<\/strong> viene utilizzato per verificare se un campione proviene o meno da una determinata distribuzione.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Per eseguire un test di Kolmogorov-Smirnov in Python, possiamo utilizzare <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.kstest.html\" target=\"_blank\" rel=\"noopener noreferrer\">scipy.stats.kstest()<\/a> per un test a un campione o <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> per un test a due campioni.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial mostra un esempio di come utilizzare ciascuna funzione nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: campione del test Kolmogorov-Smirnov<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti dati di esempio:<\/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;\">Il codice seguente mostra come eseguire un test di Kolmogorov-Smirnov su questo campione di 100 valori di dati per determinare se provengono da una distribuzione normale:<\/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;\">Dal risultato, possiamo vedere che la statistica del test \u00e8 <strong>0,9072<\/strong> e il corrispondente valore p \u00e8 <strong>1,0908e-103<\/strong> . Poich\u00e9 il valore p \u00e8 inferiore a 0,05, rifiutiamo l&#8217;ipotesi nulla. Abbiamo prove sufficienti per affermare che i dati del campione non provengono da una distribuzione normale.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Anche questo risultato non dovrebbe sorprendere poich\u00e9 abbiamo generato i dati di esempio utilizzando la funzione <strong>Poisson()<\/strong> , che genera valori casuali che seguono una <a href=\"https:\/\/statorials.org\/it\/distribuzione-del-pesce\/\" target=\"_blank\" rel=\"noopener noreferrer\">distribuzione di Poisson<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: test di Kolmogorov-Smirnov a due campioni<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti due set di dati di esempio:<\/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;\">Il codice seguente mostra come eseguire un test di Kolmogorov-Smirnov su questi due campioni per determinare se provengono dalla stessa distribuzione:<\/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;\">Dal risultato, possiamo vedere che la statistica del test \u00e8 <strong>0,99<\/strong> e il corrispondente valore p \u00e8 <strong>4,4175e-57<\/strong> . Poich\u00e9 il valore p \u00e8 inferiore a 0,05, rifiutiamo l&#8217;ipotesi nulla. Abbiamo prove sufficienti per affermare che i due set di dati campione non provengono dalla stessa distribuzione.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Anche questo risultato non dovrebbe sorprendere poich\u00e9 abbiamo generato valori per il primo campione utilizzando la distribuzione normale standard e valori per il secondo campione utilizzando la distribuzione lognormale.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/pitone-di-prova-shapiro-wilk\/\">Come eseguire un test di Shapiro-Wilk in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/anderson-cheri-prova-pitone\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come eseguire un test di Anderson-Darling in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il test di Kolmogorov-Smirnov viene utilizzato per verificare se un campione proviene o meno da una determinata distribuzione. Per eseguire un test di Kolmogorov-Smirnov in Python, possiamo utilizzare scipy.stats.kstest() per un test a un campione o scipy.stats.ks_2samp() per un test a due campioni. Questo tutorial mostra un esempio di come utilizzare ciascuna funzione nella pratica. [&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>Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials<\/title>\n<meta name=\"description\" content=\"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.\" \/>\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\/it\/kolmogorov-smirnov-prova-pitone\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials\" \/>\n<meta property=\"og:description\" content=\"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/\" \/>\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=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/\",\"url\":\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/\",\"name\":\"Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-28T02:15:25+00:00\",\"dateModified\":\"2023-07-28T02:15:25+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire un test di kolmogorov-smirnov in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials","description":"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.","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\/it\/kolmogorov-smirnov-prova-pitone\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials","og_description":"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.","og_url":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/","og_site_name":"Statorials","article_published_time":"2023-07-28T02:15:25+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/","url":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/","name":"Come eseguire un test di Kolmogorov-Smirnov in Python - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-28T02:15:25+00:00","dateModified":"2023-07-28T02:15:25+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Una semplice spiegazione di come eseguire un test di Kolmogorov-Smirnov in Python, inclusi diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/kolmogorov-smirnov-prova-pitone\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire un test di kolmogorov-smirnov in python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/987"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}