{"id":1863,"date":"2022-02-08T16:41:43","date_gmt":"2022-02-08T07:41:43","guid":{"rendered":"https:\/\/aiacademy.jp\/media\/?p=1863"},"modified":"2024-10-29T16:10:38","modified_gmt":"2024-10-29T07:10:38","slug":"%e3%80%90%e7%b5%b1%e8%a8%88%e7%94%a8%e8%aa%9e%e3%80%91%e8%b5%a4%e6%b1%a0%e6%83%85%e5%a0%b1%e9%87%8f%e5%9f%ba%e6%ba%96%ef%bc%88aic%ef%bc%89%e3%81%a8%e3%81%af","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=1863","title":{"rendered":"\u3010\u7d71\u8a08\u7528\u8a9e\u3011\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff08AIC\uff09\u3068\u306f"},"content":{"rendered":"\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <span><\/span>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-0\">\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff08AIC\uff09\u3068\u306f<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-1\">Python\u3067AIC\u3092\u8a08\u7b97\u3059\u308b\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-2\">\u7d71\u8a08\u5b66\u3084\u6a5f\u68b0\u5b66\u7fd2\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 class=\"wp-block-heading\" id=\"i-0\">\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff08AIC\uff09\u3068\u306f<\/h2>\n\n\n\n<p>AIC\uff08Akaike\u2019s Information Criterion \/ \u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff09\u3068\u306f\u3001\u30e2\u30c7\u30eb\u306e\u5f53\u3066\u306f\u307e\u308a\u5ea6\u5408\u3044\u3092\u8868\u3059\u6307\u6a19\u3067\u3001AIC\u306e\u5024\u304c\u5c0f\u3055\u3044\u307b\u3069\u300c\u3088\u3044\u300d\u30e2\u30c7\u30eb\u3068\u307f\u306a\u305b\u308b\u6307\u6a19\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u7684\u306b\u4ee5\u4e0b\u306e\u6570\u5f0f\u3067\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AIC = -2 ln(L) + 2k<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ln(L) \u306f\u6700\u5927\u5316\u3055\u308c\u305f\u5bfe\u6570\u5c24\u5ea6<\/li>\n\n\n\n<li>k \u306f\u30e2\u30c7\u30eb\u306e\u81ea\u7531\u5ea6\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u6570\uff09<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"144\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47-1024x144.png\" alt=\"\" class=\"wp-image-1866\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47-1024x144.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47-300x42.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47-768x108.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47-940x132.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-02-08-16.38.47.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-1\">Python\u3067AIC\u3092\u8a08\u7b97\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n\n<p>Python\u3067\u306f\u3001<code>statsmodels<\/code>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u7dda\u5f62\u56de\u5e30\u30e2\u30c7\u30eb\u3092\u9069\u5408\u3055\u305b\u3001AIC\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-codebox pre_tag\"><span><i class=\"fa fa-code\"><\/i><\/span><pre><code>pip install statsmodels numpy<\/code><\/pre><\/div>\n\n\n\n<p>\u4ee5\u4e0b\u306f\u3001\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-codebox pre_tag\"><span><i class=\"fa fa-code\"><\/i>python<\/span><pre><code>import numpy as np\nimport statsmodels.api as sm\n\n# \u30c7\u30fc\u30bf\u751f\u6210\nnp.random.seed(0)  # \u518d\u73fe\u6027\u306e\u305f\u3081\u306e\u30e9\u30f3\u30c0\u30e0\u30b7\u30fc\u30c9\u3092\u8a2d\u5b9a\nX = np.random.rand(100, 1)  # \u4e00\u69d8\u5206\u5e03\u304b\u3089100\u500b\u306e\u30c7\u30fc\u30bf\u3092\u751f\u6210\uff08\u7279\u5fb4\u91cf\uff09\nX = sm.add_constant(X)  # \u5b9a\u6570\u9805\uff08\u30d0\u30a4\u30a2\u30b9\u3001\u5207\u7247\uff09\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u3001\u56de\u5e30\u30e2\u30c7\u30eb\u306b\u304a\u3051\u308b\u5207\u7247\u3092\u63a8\u5b9a\u53ef\u80fd\u306b\u3059\u308b\ny = 3 * X[:, 1] + np.random.randn(100) * 0.5  # \u771f\u306e\u95a2\u4fc2\u5f0f\u3092\u8a2d\u5b9a\u3057\u3001\u30ce\u30a4\u30ba\u3092\u52a0\u3048\u305f\u76ee\u7684\u5909\u6570\u3092\u751f\u6210\n\n# \u30e2\u30c7\u30eb\u9069\u5408\nmodel = sm.OLS(y, X).fit()  # \u6700\u5c0f\u4e8c\u4e57\u6cd5\uff08OLS: Ordinary Least Squares\uff09\u3067\u56de\u5e30\u30e2\u30c7\u30eb\u3092\u9069\u5408\u3055\u305b\u308b\n\n# AIC\u306e\u8868\u793a\nprint(f\"AIC: {model.aic}\")  # AIC\uff08\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff09\u3092\u51fa\u529b\u3057\u3066\u30e2\u30c7\u30eb\u306e\u9069\u5408\u5ea6\u3092\u8a55\u4fa1<\/code><\/pre><\/div>\n\n\n\n<p><code>statsmodels<\/code>\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u7c21\u6f54\u306bAIC\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u30e2\u30c7\u30eb\u9078\u629e\u306e\u969b\u306b\u306f\u3001AIC\u4ee5\u5916\u306e\u6307\u6a19\u3068\u3057\u3066\u3001\u4f8b\u3048\u3070<a href=\"https:\/\/aiacademy.jp\/media\/?p=5339\" title=\"BIC\uff08\u30d9\u30a4\u30ba\u60c5\u5831\u91cf\u57fa\u6e96\uff09\">BIC\uff08\u30d9\u30a4\u30ba\u60c5\u5831\u91cf\u57fa\u6e96\uff09<\/a>\u3082\u4f75\u305b\u3066\u691c\u8a0e\u3059\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-2\">\u7d71\u8a08\u5b66\u3084\u6a5f\u68b0\u5b66\u7fd2\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f<\/h1>\n\n\n\n<p><meta charset=\"utf-8\">\u7d71\u8a08\u5b66\u3084\u6a5f\u68b0\u5b66\u7fd2\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\u3001\u666e\u6bb5\u304b\u3089\u30c7\u30fc\u30bf\u89e3\u6790\u3057\u3066\u3044\u308b\u73fe\u5f79\u306e\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30c6\u30a3\u30b9\u30c8\u3084\u6a5f\u68b0\u5b66\u7fd2\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u8cea\u554f\u3067\u304d\u308b\u74b0\u5883\u3067\u5b66\u3076\u3053\u3068\u3067\u3059\u3002<br>\u8cea\u554f\u3057\u653e\u984c\u304b\u3064\u3001\u4f53\u7cfb\u7684\u306b\u5b66\u3079\u308b\u52d5\u753b\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u30c7\u30fc\u30bf\u5206\u6790\u6280\u8853\u3092\u5b66\u3073\u305f\u3044\u65b9\u306f\u3001\u30aa\u30f3\u30e9\u30a4\u30f3\u3067\u597d\u304d\u306a\u6642\u9593\u306b\u52c9\u5f37\u3067\u304d\u308b<a href=\"https:\/\/aiacademy.jp\/bootcamp\">AI Academy Bootcamp<\/a>\u304c\u30aa\u30b9\u30b9\u30e1\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 \u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff08AIC\uff09\u3068\u306f Python\u3067AIC\u3092\u8a08\u7b97\u3059\u308b\u65b9\u6cd5 \u7d71\u8a08\u5b66\u3084\u6a5f\u68b0\u5b66\u7fd2\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f \u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff08AIC\uff09\u3068\u306f AIC\uff08Akaike\u2019s Information Criterion \/ \u8d64\u6c60\u60c5 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1868,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[154,131],"tags":[],"class_list":{"0":"post-1863","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-154","8":"category-131"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1863"}],"version-history":[{"count":9,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1863\/revisions"}],"predecessor-version":[{"id":5348,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1863\/revisions\/5348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/1868"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}