{"id":4248,"date":"2023-12-26T12:42:35","date_gmt":"2023-12-26T03:42:35","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=4248"},"modified":"2023-12-26T12:42:35","modified_gmt":"2023-12-26T03:42:35","slug":"%e6%a9%9f%e6%a2%b0%e5%ad%a6%e7%bf%92%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e6%89%8b%e6%b3%95-%e5%be%b9%e5%ba%95%e8%a7%a3%e8%aa%ac-part-2","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/%e6%a9%9f%e6%a2%b0%e5%ad%a6%e7%bf%92%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e6%89%8b%e6%b3%95-%e5%be%b9%e5%ba%95%e8%a7%a3%e8%aa%ac-part-2\/","title":{"rendered":"[\u6a5f\u68b0\u5b66\u7fd2]\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5 \u5fb9\u5e95\u89e3\u8aac Part.2"},"content":{"rendered":"\n<p>\r\n\u672c\u8a18\u4e8b Part.2\u3067\u306f\u3001\u524d\u56de Part.1\u306b\u3066\u7d39\u4ecb\u3057\u305f\u3088\u304f\u7528\u3044\u3089\u308c\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5\u306b\u3064\u3044\u3066\u30b3\u30fc\u30c9\u3092\u7528\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\uff01<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><span style=\"font-size: 14pt;\">\u672c\u8a18\u4e8b Part.2\u3067\u306f\u3001\u524d\u56de Part.1\u306b\u3066\u7d39\u4ecb\u3057\u305f\u3088\u304f\u7528\u3044\u3089\u308c\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5\u306b\u3064\u3044\u3066\u30b3\u30fc\u30c9\u3092\u7528\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/span><!-- notionvc: 0ba8e7c5-db91-459b-aaca-af1035ddc178 --><\/p>\r\n<p>[blogcard url=&#8221;https:\/\/blog.since2020.jp\/data_analysis\/%e6%a9%9f%e6%a2%b0%e5%ad%a6%e7%bf%92%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e6%89%8b%e6%b3%95-%e5%be%b9%e5%ba%95%e8%a7%a3%e8%aa%ac-part-1\/&#8221;]<\/p>\n\n<h2>\u306a\u305c\u3084\u308b\u306e\u304b<\/h2>\n<p><span style=\"font-size: 14pt;\">\u6a5f\u68b0\u5b66\u7fd2\u306e\u69d8\u3005\u306a\u624b\u6cd5\u3092\u521d\u3081\u3066\u89e6\u308c\u308b\u65b9\u3005\u306b\u3068\u3063\u3066\u3001scikit-learn\u306a\u3069\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u8aad\u3093\u3067\u3066\u697d\u3057\u3044\u3082\u306e\u306e\u3001\u60c5\u5831\u91cf\u304c\u591a\u304f\u3001\u7406\u89e3\u3057\u306b\u304f\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\">\u305d\u3053\u3067\u3001\u6587\u5b57\u3067\u306e\u8aac\u660e\u306b\u52a0\u3048\u3066\u30b3\u30fc\u30c9\u3092\u793a\u3059\u3053\u3068\u3067\u3001\u624b\u6cd5\u306e\u6982\u5ff5\u3092\u3088\u308a\u660e\u78ba\u306b\u3057\u3001\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u65b9\u6cd5\u3092\u8996\u899a\u7684\u306b\u7406\u89e3\u3057\u3084\u3059\u304f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\">\u79c1\u304c\u76ee\u6307\u3059\u306e\u306f\u3001\u8aad\u8005\u306e\u7686\u3055\u3093\u304c\u6a5f\u68b0\u5b66\u7fd2\u306e\u624b\u6cd5\u3092\u305f\u3060\u7406\u89e3\u3059\u308b\u3060\u3051\u3067\u306a\u304f\u3001\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3068\u3057\u3066\u5b9f\u88c5\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3053\u3068\u3092\u652f\u63f4\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/span><\/p>\r\n<p><!-- notionvc: ed19626a-2ec0-4b6b-8899-c6bcd3ece95f --><\/p>\n\n<h2>\u6587\u6cd5\u306e\u8aac\u660e<\/h2>\n<p><mark>test_size<\/mark>\uff1a\u30c6\u30b9\u30c8\u30bb\u30c3\u30c8\u306b\u5272\u308a\u5f53\u3066\u308b\u30c7\u30fc\u30bf\u306e\u5272\u5408\u307e\u305f\u306f\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059<strong>test_size=0.2<\/strong>\u306f\u30c7\u30fc\u30bf\u306e20%\u3092\u30c6\u30b9\u30c8\u30bb\u30c3\u30c8\u306b\u4f7f\u7528\u3057\u3001\u6b8b\u308a\u306e80%\u3092\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u30bb\u30c3\u30c8\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002<\/p>\r\n<p><mark>random_state<\/mark>\uff1a\u30c7\u30fc\u30bf\u5206\u5272\u306e\u969b\u306e\u4e71\u6570\u30b7\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059<\/p>\r\n<p><mark>n_splits<\/mark>\uff1a\u4ea4\u5dee\u691c\u8a3c\u306b\u304a\u3051\u308b\u5206\u5272\u306e\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001<strong>n_splits=5<\/strong>\u306f5\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\u3092\u610f\u5473\u3057\u307e\u3059\u3002<\/p>\r\n<p><mark>shuffle<\/mark>\uff1a\u30c7\u30fc\u30bf\u3092\u5206\u5272\u3059\u308b\u524d\u306b\u30b7\u30e3\u30c3\u30d5\u30eb\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001<strong>shuffle=True<\/strong>\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u304c\u30e9\u30f3\u30c0\u30e0\u306b\u30b7\u30e3\u30c3\u30d5\u30eb\u3055\u308c\u305f\u5f8c\u306b\u5206\u5272\u3055\u308c\u307e\u3059\u3002<\/p>\r\n<p><mark>.split(X)<\/mark> \uff1a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5206\u5272\u3059\u308b\u969b\u306b\u3001\u6587\u5b57\u5217\u3084\u7279\u5b9a\u306e\u7279\u5fb4\u91cf\u3092\u500b\u5225\u306b\u5206\u89e3\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u5168\u4f53\u306b\u5bfe\u3057\u3066\u884c\u308f\u308c\u308b\u5206\u5272\u64cd\u4f5c\u3067\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u6570\u306e\u30bb\u30b0\u30e1\u30f3\u30c8\u306b\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5206\u5272\u3057\u3001\u5404\u30bb\u30b0\u30e1\u30f3\u30c8\u306b\u5c5e\u3059\u308b\u884c\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n\n<h2>\u5b9f\u88c5<\/h2>\n<b><span style=\"font-size: 14pt;\"><strong>\u30db\u30fc\u30eb\u30c9\u30a2\u30a6\u30c8\u6cd5\uff08Holdout Method\uff09<\/strong>:<\/span><\/b>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u30db\u30fc\u30eb\u30c9\u30a2\u30a6\u30c8\uff08Holdout Method\uff09\r\nfrom sklearn.model_selection import train_test_split\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=28)<\/code><\/pre>\r\n<\/div>\r\n<b><span style=\"font-size: 14pt;\"><strong>K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08K-Fold Cross-Validation\uff09<\/strong>:<\/span><\/b>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08K-Fold Cross-Validation\uff09 \r\nfrom sklearn.model_selection import KFold \r\nkf = KFold(n_splits=5, shuffle=True, random_state=28) \r\nfor train_index, test_index in kf.split(X): \r\n    X_train, X_test = X.iloc[train_index], X.iloc[test_index] \r\n    y_train, y_test = y.iloc[train_index], y.iloc[test_index]<!-- notionvc: 0700fb78-4be7-49c1-a5b4-f01caf6fbc2b -->\r\n<\/code><\/pre>\r\n<\/div>\r\n<b><span style=\"font-size: 14pt;\"><strong>\u30b0\u30eb\u30fc\u30d7K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08Group K-Fold\uff09\uff1a<\/strong><\/span><\/b>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u30b0\u30eb\u30fc\u30d7K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08Group K-Fold\uff09 \r\nfrom sklearn.model_selection import GroupKFold \r\ngkf = GroupKFold(n_splits=5) \r\nfor train_index, test_index in gkf.split(X, y, groups=groups): \r\n    X_train, X_test = X.iloc[train_index], X.iloc[test_index] \r\n    y_train, y_test = y.iloc[train_index], y.iloc[test_index]<!-- notionvc: a5266cd8-8e30-4a3c-b2d3-c06dfd31a549 --><\/code><\/pre>\r\n<\/div>\r\n<b><span style=\"font-size: 14pt;\"><strong>\u5c64\u5316K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08Stratified K-Fold Cross-Validation\uff09<\/strong>:<\/span><\/b>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u5c64\u5316K\u5206\u5272\u4ea4\u5dee\u691c\u8a3c\uff08Stratified K-Fold Cross-Validation\uff09 \r\nfrom sklearn.model_selection import StratifiedKFold \r\nskf = StratifiedKFold(n_splits=5, shuffle=True, random_state=28) \r\nfor train_index, test_index in skf.split(X, y): \r\n    X_train, X_test = X.iloc[train_index], X.iloc[test_index] \r\n    y_train, y_test = y.iloc[train_index], y.iloc[test_index]<!-- notionvc: a9eac9d3-1d81-413f-8e6b-66f44d939d55 --><\/code><\/pre>\r\n<\/div>\r\n<b><span style=\"font-size: 14pt;\"><strong>\u30ea\u30fc\u30d6\u30fb\u30ef\u30f3\u30fb\u30a2\u30a6\u30c8\u6cd5\uff08Leave-One-Out Cross-Validation\uff09<\/strong>:<\/span><\/b>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u30ea\u30fc\u30d6\u30fb\u30ef\u30f3\u30fb\u30a2\u30a6\u30c8\u6cd5\uff08Leave-One-Out Cross-Validation\uff09 \r\nfrom sklearn.model_selection import LeaveOneOut \r\nloo = LeaveOneOut() \r\nfor train_index, test_index in loo.split(X): \r\n    X_train, X_test = X.iloc[train_index], X.iloc[test_index] \r\n    y_train, y_test = y.iloc[train_index], y.iloc[test_index]<!-- notionvc: c5d618fa-16f0-4d38-8fba-f82d98c0813d --><\/code><\/pre>\r\n<\/div>\n\n<h2>\u7d42\u308f\u308a\u306b<\/h2>\n<p><span style=\"font-size: 14pt;\">Part.1\u3001Part.2\u3092\u901a\u3057\u3066\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5\u306e\u8aac\u660e\u3068\u30b3\u30fc\u30c9\u306b\u3088\u308b\u5b9f\u88c5\u3092\u884c\u3044\u307e\u3057\u305f\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\">\u4eca\u56de\u306f\u4e00\u822c\u7684\u306a\u624b\u6cd5\u306b\u7126\u70b9\u3092\u5f53\u3066\u307e\u3057\u305f\u304c\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u3088\u3046\u306a\u7279\u6b8a\u306a\u30b1\u30fc\u30b9\u3067\u306f\u3001\u7570\u306a\u308b\u30a2\u30d7\u30ed\u30fc\u30c1\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002\u9069\u5207\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u306f\u3001\u30c7\u30fc\u30bf\u306e\u7279\u6027\u306b\u6df1\u304f\u6839\u3056\u3057\u3001\u30e2\u30c7\u30eb\u306e\u30ed\u30d0\u30b9\u30c8\u6027\u3068\u4e88\u6e2c\u7cbe\u5ea6\u306b\u5927\u304d\u306a\u5f71\u97ff\u3092\u4e0e\u3048\u307e\u3059\u3002<\/span><\/p>\r\n<p><span style=\"font-size: 14pt;\">\u3053\u306e\u8a18\u4e8b\u304c\u7406\u8ad6\u3068\u5b9f\u8df5\u306e\u6a4b\u6e21\u3057\u3068\u306a\u308a\u3001\u307f\u306a\u3055\u3093\u306e\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u306e\u5b66\u3073\u306b\u6709\u76ca\u306a\u60c5\u5831\u3092\u63d0\u4f9b\u3057\u3001\u7406\u89e3\u3092\u6df1\u3081\u308b\u624b\u52a9\u3051\u306b\u306a\u3063\u3066\u3044\u308c\u3070\u5e78\u3044\u3067\u3059\uff01<\/span><\/p>\r\n<p><!-- notionvc: a448f07e-5392-4886-9c9a-f9861cbb7755 --><\/p>\n\n<h2>\u53c2\u7167<\/h2>\n<p>[blogcard url=&#8221;https:\/\/scikit-learn.org\/stable\/modules\/cross_validation.html&#8221;]<\/p>","protected":false},"excerpt":{"rendered":"<p>\u672c\u8a18\u4e8b Part.2\u3067\u306f\u3001\u524d\u56de Part.1\u306b\u3066\u7d39\u4ecb\u3057\u305f\u3088\u304f\u7528\u3044\u3089\u308c\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b\u6cd5\u306b\u3064\u3044\u3066\u30b3\u30fc\u30c9\u3092\u7528\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\uff01 \u306f\u3058\u3081\u306b \u672c\u8a18\u4e8b Part.2\u3067\u306f\u3001\u524d\u56de Part.1\u306b\u3066\u7d39\u4ecb\u3057\u305f\u3088\u304f\u7528\u3044\u3089\u308c\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u624b [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":3123,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1246],"tags":[96,331,39,27,26],"class_list":["post-4248","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-infrastructure","tag-ai","tag-python","tag-39","tag-27","tag-26"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/4248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=4248"}],"version-history":[{"count":0,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/4248\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/3123"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=4248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=4248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=4248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}