{"id":983,"date":"2023-07-28T02:35:28","date_gmt":"2023-07-28T02:35:28","guid":{"rendered":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/"},"modified":"2023-07-28T02:35:28","modified_gmt":"2023-07-28T02:35:28","slug":"kwadratische-regressiepython","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/","title":{"rendered":"Hoe kwadratische regressie uit te voeren in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Kwadratische regressie<\/strong> is een type regressie dat we kunnen gebruiken om de relatie tussen een voorspellende variabele en een responsvariabele te kwantificeren wanneer de werkelijke relaties kwadratisch zijn, wat er in een grafiek uit kan zien als een &#8222;U&#8220; of een omgekeerde &#8222;U&#8220;.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dat wil zeggen dat naarmate de voorspellende variabele toeneemt, de responsvariabele de neiging heeft ook toe te nemen, maar na een bepaald punt begint de responsvariabele af te nemen naarmate de voorspellende variabele blijft toenemen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In deze tutorial wordt uitgelegd hoe u kwadratische regressie in Python uitvoert.<\/span><\/p>\n<h2> <strong><span style=\"color: #000000;\">Voorbeeld: kwadratische regressie in Python<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we gegevens hebben over het aantal gewerkte uren per week en het gerapporteerde geluksniveau (op een schaal van 0 tot 100) voor 16 verschillende mensen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> numpy <span style=\"color: #107d3f;\">as<\/span> np\n<span style=\"color: #107d3f;\">import<\/span> scipy.stats <span style=\"color: #107d3f;\">as<\/span> stats\n\n<span style=\"color: #008080;\">#define variables<\/span>\nhours = [6, 9, 12, 12, 15, 21, 24, 24, 27, 30, 36, 39, 45, 48, 57, 60]\nhapp = [12, 18, 30, 42, 48, 78, 90, 96, 96, 90, 84, 78, 66, 54, 36, 24]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Als we een eenvoudig spreidingsdiagram van deze gegevens maken, kunnen we zien dat de relatie tussen de twee variabelen een \u201cU\u201d-vorm heeft:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import <span style=\"color: #000000;\">matplotlib.pyplot<\/span> as <span style=\"color: #000000;\">plt<\/span>\n\n<span style=\"color: #000000;\"><span style=\"color: #008080;\">#create scatterplot\n<\/span>plt.scatter(hours, happ)<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10240 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/quadregpython1.png\" alt=\"\" width=\"376\" height=\"248\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Naarmate het aantal gewerkte uren toeneemt, neemt het geluk ook toe, maar zodra het aantal gewerkte uren de 35 uur per week overschrijdt, begint het geluk af te nemen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vanwege deze &#8222;U&#8220;-vorm betekent dit dat kwadratische regressie waarschijnlijk een goede kandidaat is om de relatie tussen de twee variabelen te kwantificeren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om daadwerkelijk een kwadratische regressie uit te voeren, kunnen we een polynomiaal regressiemodel met een graad van 2 fitten met behulp van de<\/span> <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.polyfit.html\" target=\"_blank\" rel=\"noopener noreferrer\">numpy.polyfit()<\/a> <span style=\"color: #000000;\">functie<\/span> : <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> numpy <span style=\"color: #107d3f;\">as<\/span> np\n\n<span style=\"color: #008080;\">#polynomial fit with degree = 2\n<\/span>model = np.poly1d(np.polyfit(hours, happ, 2))\n\n<span style=\"color: #008080;\">#add fitted polynomial line to scatterplot\n<\/span>polyline = np.linspace(1, 60, 50)\nplt.scatter(hours, happ)\nplt.plot(polyline, model(polyline))\nplt.show()<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10242\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/quadregpython2.png\" alt=\"Kwadratische regressie in Python\" width=\"412\" height=\"273\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">We kunnen de gepaste polynomiale regressievergelijking verkrijgen door de modelco\u00ebffici\u00ebnten af te drukken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">print<\/span> (model)\n\n-0.107x <sup>2<\/sup> + 7.173x - 30.25\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De aangepaste kwadratische regressievergelijking is:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Geluk = -0,107(uren) <sup>2<\/sup> + 7,173(uren) \u2013 30,25<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen deze vergelijking gebruiken om het verwachte geluksniveau van een individu te berekenen op basis van zijn gewerkte uren. Het verwachte geluksniveau van iemand die 30 uur per week werkt, is bijvoorbeeld:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Geluk = -0,107(30) <sup>2<\/sup> + 7,173(30) \u2013 30,25 = <strong>88,64<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen ook een korte functie schrijven om het R-kwadraat van het model te verkrijgen, wat het deel van de variantie in de responsvariabele is dat kan worden verklaard door de voorspellende variabelen.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define function to calculate r-squared<\/span>\n<span style=\"color: #008000;\">def<\/span> polyfit(x, y, degree):\n    results = {}\n    coeffs = np.polyfit(x, y, degree)\n    p = np.poly1d(coeffs)\n    <span style=\"color: #008080;\">#calculate r-squared<\/span>\n    yhat = p(x)\n    ybar = np.sum(y)\/len(y)\n    ssreg = np.sum((yhat-ybar)**2)\n    sstot = np.sum((y - ybar)**2)\n    results['r_squared'] = ssreg \/ sstot\n\n    <span style=\"color: #008000;\">return<\/span> results\n\n<span style=\"color: #008080;\">#find r-squared of polynomial model with degree = 3\n<\/span>polyfit(hours, happ, 2)\n\n{'r_squared': 0.9092114182131691}\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">In dit voorbeeld is het R-kwadraat van het model <strong>0,9092<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit betekent dat 90,92% van de variatie in gerapporteerde geluksniveaus kan worden verklaard door de voorspellende variabelen.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <a href=\"https:\/\/statorials.org\/nl\/polynomiale-regressiepython\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hoe polynomiale regressie uit te voeren in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/kwadratische-regressie-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hoe kwadratische regressie uit te voeren in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/kwadratische-regressie-excel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hoe kwadratische regressie uit te voeren in Excel<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kwadratische regressie is een type regressie dat we kunnen gebruiken om de relatie tussen een voorspellende variabele en een responsvariabele te kwantificeren wanneer de werkelijke relaties kwadratisch zijn, wat er in een grafiek uit kan zien als een &#8222;U&#8220; of een omgekeerde &#8222;U&#8220;. Dat wil zeggen dat naarmate de voorspellende variabele toeneemt, de responsvariabele de [&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-983","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 kwadratische regressie uit te voeren in Python - Statorials<\/title>\n<meta name=\"description\" content=\"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.\" \/>\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\/kwadratische-regressiepython\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe kwadratische regressie uit te voeren in Python - Statorials\" \/>\n<meta property=\"og:description\" content=\"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T02:35:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/quadregpython1.png\" \/>\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=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/\",\"url\":\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/\",\"name\":\"Hoe kwadratische regressie uit te voeren in Python - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-28T02:35:28+00:00\",\"dateModified\":\"2023-07-28T02:35:28+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe kwadratische regressie uit te voeren in python\"}]},{\"@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 kwadratische regressie uit te voeren in Python - Statorials","description":"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.","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\/kwadratische-regressiepython\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe kwadratische regressie uit te voeren in Python - Statorials","og_description":"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/","og_site_name":"Statorials","article_published_time":"2023-07-28T02:35:28+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/quadregpython1.png"}],"author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/","url":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/","name":"Hoe kwadratische regressie uit te voeren in Python - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-28T02:35:28+00:00","dateModified":"2023-07-28T02:35:28+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"Een eenvoudige uitleg over het uitvoeren van kwadratische regressie in Python, met een voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/kwadratische-regressiepython\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe kwadratische regressie uit te voeren in python"}]},{"@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\/983","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=983"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/983\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}