{"id":1751,"date":"2023-07-25T03:30:46","date_gmt":"2023-07-25T03:30:46","guid":{"rendered":"https:\/\/statorials.org\/nl\/aic-in-python\/"},"modified":"2023-07-25T03:30:46","modified_gmt":"2023-07-25T03:30:46","slug":"aic-in-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/aic-in-python\/","title":{"rendered":"Hoe aic van regressiemodellen in python te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Het Akaike Information Criterion (AIC) is een maatstaf die wordt gebruikt om de fit van verschillende regressiemodellen te vergelijken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het wordt als volgt berekend:<\/span><\/p>\n<p> <span style=\"color: #000000;\">AIC = 2K \u2013 2 <em>ln<\/em> (L)<\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>K:<\/strong> Het aantal modelparameters. De standaardwaarde van K is 2, dus een model met slechts \u00e9\u00e9n voorspellende variabele heeft een K-waarde van 2+1 = 3.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong><em>ln<\/em> (L)<\/strong> : De log-waarschijnlijkheid van het model. Dit vertelt ons de waarschijnlijkheid van het model, gegeven de gegevens.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">AIC is ontworpen om het model te vinden dat de meeste variatie in de gegevens verklaart, terwijl modellen worden bestraft die een buitensporig aantal parameters gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Nadat u meerdere regressiemodellen heeft ge\u00efnstalleerd, kunt u<\/span> <span style=\"color: #000000;\">de AIC-waarde van elk model vergelijken. Het model met de laagste AIC biedt de beste pasvorm.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om de AIC van meerdere regressiemodellen in Python te berekenen, kunnen we de functie <strong>statsmodels.regression.linear_model.OLS()<\/strong> gebruiken, die een eigenschap heeft genaamd <strong>aic<\/strong> die ons de AIC-waarde voor een bepaald model vertelt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In het volgende voorbeeld ziet u hoe u deze functie kunt gebruiken om AIC te berekenen en te interpreteren voor verschillende regressiemodellen in Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: bereken en interpreteer AIC in Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat we twee verschillende <a href=\"https:\/\/statorials.org\/nl\/meerdere-lineaire-regressie\/\" target=\"_blank\" rel=\"noopener\">meervoudige lineaire regressiemodellen<\/a> willen passen met behulp van variabelen uit de <strong>mtcars-<\/strong> dataset.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Eerst laden we deze dataset:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">linear_model<\/span> <span style=\"color: #008000;\">import<\/span> LinearRegression\n<span style=\"color: #008000;\">import<\/span> statsmodels. <span style=\"color: #3366ff;\">api<\/span> <span style=\"color: #008000;\">as<\/span> sm\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#define URL where dataset is located\n<\/span>url = \"https:\/\/raw.githubusercontent.com\/Statorials\/Python-Guides\/main\/mtcars.csv\"\n\n<span style=\"color: #008080;\">#read in data\n<\/span>data = pd. <span style=\"color: #3366ff;\">read_csv<\/span> (url)\n\n<span style=\"color: #008080;\">#view head of data\n<\/span>data. <span style=\"color: #3366ff;\">head<\/span> ()\n\n        model mpg cyl disp hp drat wt qsec vs am gear carb\n0 Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4\n1 Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4\n2 Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1\n3 Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1\n4 Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dit zijn de voorspellende variabelen die we in elk model zullen gebruiken:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Voorspellervariabelen in model 1: disp, hp, wt, qsec<\/span><\/li>\n<li> <span style=\"color: #000000;\">Voorspellende variabelen in model 2: disp, qsec<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u het eerste model past en de AIC berekent:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define response variable\n<\/span>y = data['mpg']\n\n<span style=\"color: #008080;\">#define predictor variables\n<\/span>x = data[['disp', 'hp', 'wt', 'qsec']]\n\n<span style=\"color: #008080;\">#add constant to predictor variables\n<\/span>x = sm. <span style=\"color: #3366ff;\">add_constant<\/span> (x)\n\n<span style=\"color: #008080;\">#fit regression model\n<\/span>model = sm. <span style=\"color: #3366ff;\">OLS<\/span> (y,x). <span style=\"color: #3366ff;\">fit<\/span> ()\n\n<span style=\"color: #008080;\">#view AIC of model\n<\/span><span style=\"color: #993300;\">print<\/span> (model. <span style=\"color: #3366ff;\">aic<\/span> )\n\n157.06960941462438<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De AIC van dit model blijkt <strong>157.07<\/strong> te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vervolgens passen we het tweede model aan en berekenen we de AIC:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define response variable\n<\/span>y = data['mpg']\n\n<span style=\"color: #008080;\">#define predictor variables\n<\/span>x = data[['disp', 'qsec']]\n\n<span style=\"color: #008080;\">#add constant to predictor variables\n<\/span>x = sm. <span style=\"color: #3366ff;\">add_constant<\/span> (x)\n\n<span style=\"color: #008080;\">#fit regression model\n<\/span>model = sm. <span style=\"color: #3366ff;\">OLS<\/span> (y,x). <span style=\"color: #3366ff;\">fit<\/span> ()\n\n<span style=\"color: #008080;\">#view AIC of model\n<\/span><span style=\"color: #993300;\">print<\/span> (model. <span style=\"color: #3366ff;\">aic<\/span> )\n\n169.84184864154588<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De AIC van dit model blijkt <strong>169,84<\/strong> te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Omdat het eerste model een lagere AIC-waarde heeft, is dit het best passende model.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Zodra we dit model als het beste hebben ge\u00efdentificeerd, kunnen we doorgaan met het aanpassen van het model en de resultaten analyseren, inclusief de R-kwadraatwaarde en b\u00e8taco\u00ebffici\u00ebnten, om de exacte relatie tussen de reeks voorspellende variabelen en de<a href=\"https:\/\/statorials.org\/nl\/variabelen-verklarende-reacties\/\" target=\"_blank\" rel=\"noopener\">responsvariabele<\/a> te bepalen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/lineaire-regressiepython\/\" target=\"_blank\" rel=\"noopener\">Een complete gids voor lineaire regressie in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/r-vierkant-in-python-wordt-aangepast\/\" target=\"_blank\" rel=\"noopener\">Hoe het aangepaste R-kwadraat in Python te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Het Akaike Information Criterion (AIC) is een maatstaf die wordt gebruikt om de fit van verschillende regressiemodellen te vergelijken. Het wordt als volgt berekend: AIC = 2K \u2013 2 ln (L) Goud: K: Het aantal modelparameters. De standaardwaarde van K is 2, dus een model met slechts \u00e9\u00e9n voorspellende variabele heeft een K-waarde van 2+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-1751","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe AIC van regressiemodellen in Python te berekenen<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.\" \/>\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\/nl\/aic-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe AIC van regressiemodellen in Python te berekenen\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/aic-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T03:30:46+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/aic-in-python\/\",\"url\":\"https:\/\/statorials.org\/nl\/aic-in-python\/\",\"name\":\"Hoe AIC van regressiemodellen in Python te berekenen\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-25T03:30:46+00:00\",\"dateModified\":\"2023-07-25T03:30:46+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/aic-in-python\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/aic-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/aic-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe aic van regressiemodellen in python te berekenen\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe AIC van regressiemodellen in Python te berekenen","description":"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.","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\/nl\/aic-in-python\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe AIC van regressiemodellen in Python te berekenen","og_description":"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.","og_url":"https:\/\/statorials.org\/nl\/aic-in-python\/","og_site_name":"Statorials","article_published_time":"2023-07-25T03:30:46+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/aic-in-python\/","url":"https:\/\/statorials.org\/nl\/aic-in-python\/","name":"Hoe AIC van regressiemodellen in Python te berekenen","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-25T03:30:46+00:00","dateModified":"2023-07-25T03:30:46+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de Akaike Information Criterion (AIC)-waarde van regressiemodellen in Python kunt berekenen.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/aic-in-python\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/aic-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/aic-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe aic van regressiemodellen in python te berekenen"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=1751"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1751\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}