{"id":3543,"date":"2023-07-16T22:41:00","date_gmt":"2023-07-16T22:41:00","guid":{"rendered":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/"},"modified":"2023-07-16T22:41:00","modified_gmt":"2023-07-16T22:41:00","slug":"nessun-modulo-chiamato-sklearn-cross-validation","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/","title":{"rendered":"Come risolvere: nessun modulo denominato &quot;sklearn.cross_validation&quot;;"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un errore che potresti riscontrare quando usi Python \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #ff0000;\">ModuleNotFoundError <span style=\"color: #000000;\">: No module named 'sklearn.cross_validation'\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore di solito si verifica quando si tenta di importare la funzione <strong>train_test_split<\/strong> da <strong>sklearn<\/strong> utilizzando la seguente riga:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">cross_validation<\/span> <span style=\"color: #008000;\">import<\/span> train_test_split<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tuttavia, il sottomodulo <strong>cross_validation<\/strong> \u00e8 stato sostituito dal sottomodulo <strong>model_selection<\/strong> , quindi \u00e8 necessario utilizzare la seguente riga:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">model_selection<\/span> <span style=\"color: #008000;\">import<\/span> train_test_split<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come risolvere questo errore nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Come riprodurre l&#8217;errore<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di voler utilizzare la funzione <strong>train_test_split<\/strong> di <strong>sklearn<\/strong> per dividere un DataFrame panda in set di training e test.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Supponiamo di provare a utilizzare il seguente codice per importare la funzione <strong>train_test_split<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">cross_validation<\/span> <span style=\"color: #008000;\">import<\/span> train_test_split\n\n<span style=\"color: #ff0000;\">ModuleNotFoundError <span style=\"color: #000000;\">: No module named 'sklearn.cross_validation'<\/span><\/span>\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Riceviamo un errore perch\u00e9 abbiamo utilizzato il nome del sottomodulo sbagliato durante il tentativo di importare la funzione <strong>train_test_split<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Come correggere l&#8217;errore<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Per correggere questo errore, dobbiamo semplicemente utilizzare invece il sottomodulo <strong>model_selection<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">model_selection<\/span> <span style=\"color: #008000;\">import<\/span> train_test_split\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa volta non riceviamo alcun errore.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Potremmo quindi utilizzare la funzione <strong>train_test_split<\/strong> per dividere un DataFrame panda in un set di training e test:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">model_selection<\/span> <span style=\"color: #008000;\">import<\/span> train_test_split\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#make this example reproducible\n<\/span>n.p. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\">#create DataFrame with 1000 rows and 3 columns\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">x1<\/span> ': np.random.randint(30, size=1000),\n                   ' <span style=\"color: #ff0000;\">x2<\/span> ': np.random.randint(12, size=1000),\n                   ' <span style=\"color: #ff0000;\">y<\/span> ': np.random.randint(2, size=1000)})\n\n<span style=\"color: #008080;\">#split original DataFrame into training and testing sets\n<\/span>train, test = train_test_split(df, test_size=0.2, random_state=0)\n\n<span style=\"color: #008080;\">#view first few rows of each set\n<\/span><span style=\"color: #008000;\">print<\/span> ( <span style=\"color: #3366ff;\">train.head<\/span> ())\n\n     x1 x2 y\n687 16 2 0\n500 18 2 1\n332 4 10 1\n979 2 8 1\n817 11 1 0\n\n<span style=\"color: #008000;\">print<\/span> ( <span style=\"color: #3366ff;\">test.head<\/span> ())\n\n     x1 x2 y\n993 22 1 1\n859 27 6 0\n298 27 8 1\n553 20 6 0\n672 9 2 1<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Riusciamo a utilizzare con successo la funzione <strong>train_test_split<\/strong> senza errori.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come correggere altri errori comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/le-colonne-si-sovrappongono-ma-non-e-specificato-alcun-suffisso\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: le colonne si sovrappongono ma non \u00e8 specificato alcun suffisso<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/loggetto-numpy-ndarray-non-ha-attributi-aggiunti\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: l&#8217;oggetto &#8220;numpy.ndarray&#8221; non ha un attributo &#8220;append&#8221;.<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/errore-di-valore-se-si-utilizzano-tutti-i-valori-scalari-e-necessario-passare-un-indice\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: se utilizzi tutti i valori scalari, devi passare un indice<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/valueerror-non-puo-convertire-float-nan-in-intero\/\">Come risolvere il problema: ValueError: impossibile convertire float NaN in int<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare quando usi Python \u00e8: ModuleNotFoundError : No module named &#8216;sklearn.cross_validation&#8217; Questo errore di solito si verifica quando si tenta di importare la funzione train_test_split da sklearn utilizzando la seguente riga: from sklearn. cross_validation import train_test_split Tuttavia, il sottomodulo cross_validation \u00e8 stato sostituito dal sottomodulo model_selection , quindi \u00e8 necessario utilizzare [&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 risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.\" \/>\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\/nessun-modulo-chiamato-sklearn-cross-validation\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-16T22:41:00+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\/nessun-modulo-chiamato-sklearn-cross-validation\/\",\"url\":\"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/\",\"name\":\"Come risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-16T22:41:00+00:00\",\"dateModified\":\"2023-07-16T22:41:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere: nessun modulo denominato &quot;sklearn.cross_validation&quot;;\"}]},{\"@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 risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials","description":"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.","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\/nessun-modulo-chiamato-sklearn-cross-validation\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials","og_description":"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.","og_url":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/","og_site_name":"Statorials","article_published_time":"2023-07-16T22:41:00+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\/nessun-modulo-chiamato-sklearn-cross-validation\/","url":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/","name":"Come risolvere il problema: nessun modulo denominato &quot;sklearn.cross_validation&quot; - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-16T22:41:00+00:00","dateModified":"2023-07-16T22:41:00+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in Python: Nessun modulo denominato sklearn.cross_validation.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/nessun-modulo-chiamato-sklearn-cross-validation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere: nessun modulo denominato &quot;sklearn.cross_validation&quot;;"}]},{"@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\/3543"}],"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=3543"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3543\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}