{"id":1533,"date":"2018-08-18T13:34:52","date_gmt":"2018-08-18T04:34:52","guid":{"rendered":"https:\/\/plaza.umin.ac.jp\/~OIO\/?p=1533"},"modified":"2018-08-20T13:03:56","modified_gmt":"2018-08-20T04:03:56","slug":"%e3%83%8a%e3%82%a4%e3%83%bc%e3%83%96%e3%83%99%e3%82%a4%e3%82%ba%e5%88%86%e9%a1%9e%e5%99%a8","status":"publish","type":"post","link":"https:\/\/plaza.umin.ac.jp\/~OIO\/?p=1533","title":{"rendered":"\u30ca\u30a4\u30fc\u30d6\u30d9\u30a4\u30ba\u5206\u985e\u5668"},"content":{"rendered":"<h1>\u6a5f\u68b0\u5b66\u7fd2\u7684\u306a\u4f55\u304b<\/h1>\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>\u305d\u306e\u6614\u30012001\u5e74~2007\u5e74\u306b\u304b\u3051\u3066\u3001\u907a\u4f1d\u5b50\u767a\u73fe\u89e3\u6790\u3092\u3084\u3063\u3066\u3044\u305f\u9803\u3001SVM (support vector machine)\u3084Neural Network\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u809d\u81d3\u7531\u6765\u306e\u7d30\u80de\u306b\u5bfe\u3057\u809d\u81d3\u95a2\u9023\u306e\u526f\u4f5c\u7528\u304c\u77e5\u3089\u308c\u3066\u3044\u308b\u533b\u85ac\u54c1\u3068\u3001\u305d\u3046\u3067\u306a\u3044\u533b\u85ac\u54c1\u3092\u66dd\u9732\u3057\u3066\u3001\u66dd\u9732\u5f8c\u306e\u907a\u4f1d\u5b50\u767a\u73fe\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u3066\u3001\u533b\u85ac\u54c1\u306e\u809d\u6bd2\u6027\u3092<em>in vitro<\/em>\u3067\u4e88\u6e2c\u3059\u308b\u3001\u5b9f\u9a13\u30e2\u30c7\u30eb\u3092\u7d44\u307f\u7acb\u3066\u3088\u3046\u3068\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u3042\u307e\u308a\u3001\u57fa\u790e\u7684\u306a\u7d4c\u9a13\u306e\u306a\u3044\u4e2d\u3067\u3042\u308c\u3053\u308c\u8003\u3048\u3066\u3082\u6253\u958b\u7b56\u304c\u898b\u3064\u304b\u3089\u305a\u3001\u307e\u305f\u4eca\u601d\u3048\u3070\u3001\u6839\u672c\u7684\u306a\u30c7\u30b6\u30a4\u30f3\u306b\u7121\u7406\u304c\u3042\u3063\u305f\u3088\u3046\u3067\u3082\u3042\u308a\u3001\u7d50\u5c40\u306a\u304b\u306a\u304b\u3088\u3044\u51fa\u529b\u304c\u5f97\u3089\u308c\u306a\u304b\u3063\u305f\u82e6\u3044\u7d4c\u9a13\u3067\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306f\u57fa\u790e\u4f53\u529b\u3092\u3064\u3051\u308b\u610f\u5473\u3067\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u3059\u3067\u306b\u3046\u307e\u304f\u3044\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3084\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u57fa\u306b\u81ea\u5206\u306a\u308a\u306b\u8a66\u3057\u3066\u307f\u307e\u3059\u3002\u6b63\u89e3\u304c\u3042\u308b\u3082\u306e\u3092\u30c8\u30ec\u30fc\u30b9\u3059\u308b\u306e\u306f\u3001\u826f\u3044\u7df4\u7fd2\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30ca\u30a4\u30fc\u30d6\u30d9\u30a4\u30ba\u5206\u985e\u5668<\/h2>\n<p>\u4eca\u56de\u8a66\u3057\u305f\u306e\u306f\u3001\u300c<strong><a href=\"https:\/\/qiita.com\/aflc\/items\/13fe52243c35d3b678b0\">\u30ca\u30a4\u30fc\u30d6\u30d9\u30a4\u30ba\u5206\u985e\u5668<\/a><\/strong>\u300d\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u306a\u305c\u3053\u308c\u3092\u8a66\u3059\u304b\u3068\u8a00\u3046\u3068\u3001<a href=\"https:\/\/abicky.net\/2011\/01\/30\/183233\/\">\u826f\u3044\u8cc7\u6599<\/a>\u3092\u898b\u3064\u3051\u305f\u304b\u3089\u3067\u3059\u3002<a href=\"http:\/\/fujit33.hatenablog.com\/entry\/2015\/05\/14\/022624\">\u305d\u306e\u8cc7\u6599\u3092\u57fa\u306b\u3001\u8a66\u3057\u3066\u307f\u305f\u3068\u3044\u3046\u8a18\u4e8b<\/a>\u3082\u3042\u308b\u3088\u3046\u3067\u3059\u3002\u3056\u3063\u3068\u898b\u305f\u3068\u3053\u308d\u3001\u6570\u5f0f\u3067\u30af\u30e9\u30af\u30e9\u3059\u308b\u306e\u3092\u6211\u6162\u3059\u308b\u3068\u3001\u4f55\u3092\u3084\u3063\u3066\u3044\u308b\u306e\u304b\u304a\u307c\u308d\u3052\u306a\u304c\u3089\u898b\u3048\u3066\u304d\u307e\u3059\u3002\u3042\u308b\u30ab\u30c6\u30b4\u30ea\u3067\u76f8\u5bfe\u7684\u306b\u9ad8\u3044\u983b\u5ea6\u3067\u51fa\u73fe\u3059\u308b\u5358\u8a9e\u3092\u6307\u6a19\u306b\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h2>\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n<p>\u6a5f\u80fd\u3059\u308b\u4ed5\u7d44\u307f\u306f\u4f7f\u3044\u306a\u304c\u3089\u8003\u3048\u308b\u3068\u3057\u3066\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u5168\u304f\u30ea\u30f3\u30af\u5148\u306e\u8cc7\u6599\u901a\u308a\u3067\u306f\u672c\u5f53\u306b\u82b8\u304c\u306a\u3055\u3059\u304e\u308b\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u3060\u3051\u5909\u3048\u3066\u307f\u307e\u3057\u305f\u3002\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u306f\u3001\u68ee\u9d0e\u5916\u3068\u590f\u76ee\u6f31\u77f3\u306e\u4f5c\u54c1\u3092\u898b\u5206\u3051\u308b\u3068\u3044\u3046\u8ab2\u984c\u3067\u3001<a href=\"http:\/\/rmecab.jp\/wiki\/index.php?RMeCab\">MeCab\u306e\u30b5\u30a4\u30c8<\/a>\u3067\u914d\u5e03\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3001\u3092\u5b66\u7fd2\u7528\u306e\u6587\u7ae0\u3068\u3057\u3066\u3001\u3042\u3068\u306f\u9752\u7a7a\u6587\u5eab\u304b\u3089\u300c\u8349\u6795\u300d\u300c\u3053\u3053\u308d\u300d\uff08\u4ee5\u4e0a\u6f31\u77f3\uff09\u300c\u82b1\u5b50\u300d\u300c\u3042\u305d\u3073\u300d\uff08\u4ee5\u4e0a\u9d0e\u5916\uff09\u3092\u30c6\u30b9\u30c8\u7528\u6587\u7ae0\u3068\u3057\u3066\u3001\u7528\u3044\u307e\u3057\u305f\u3002\u306a\u304a\u3001\u9752\u7a7a\u6587\u5eab\u306e\u6587\u7ae0\u306f\u30eb\u30d3\u304c\u3046\u308b\u3055\u3044\u306e\u3067\u3001<a href=\"https:\/\/www.aokids.jp\/others\/delruby.html\">delruby.exe<\/a>\u3092\u7528\u3044\u3066\u51e6\u7406\u3057\u305f\u3082\u306e\u3067\u30c6\u30b9\u30c8\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30eb\u30d3\u306e\u51e6\u7406\u306e\u69d8\u5b50\uff08MS-DOS\u306e\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u304b\u3089\uff09<\/p>\n<blockquote><p>delruby asobi.txt &gt; ogai_asobi.txt<br \/>\ndelruby hanako.txt &gt; ogai_hanako.txt<br \/>\ndelruby kokoro.txt &gt; soseki_kokoro.txt<br \/>\ndelruby kusamakura.txt &gt; soseki_kusamakura.txt<\/p><\/blockquote>\n<p>\u3053\u308c\u3089\u306e\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u3068MeCab\u306e\u30b5\u30a4\u30c8\u304b\u3089\u5165\u624b\u3057\u305f\u30c7\u30fc\u30bf\u3092\u307e\u3068\u3081\u3066\u3001set\uff57\uff44\u3067\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4e0b\u306e\/data\/writers\/\u306e\u4e0b\u306b\u7f6e\u3044\u3066\u3001\u6b21\u3092\u5b9f\u884c\u3057\u307e\u3057\u305f\u3002<\/p>\n<blockquote><p>&nbsp;<\/p>\n<p>library(RMeCab)<\/p>\n<p># data is downloaded from<br \/>\n# shift JIS<br \/>\n# http:\/\/web.ias.tokushima-u.ac.jp\/linguistik\/RMeCab\/data.zip<br \/>\n# UTF8<br \/>\n# http:\/\/web.ias.tokushima-u.ac.jp\/linguistik\/RMeCab\/data.tar.gz<\/p>\n<p># indicate data folder<br \/>\nsetwd(&#8220;C:\/Users\/Oshima\/Documents\/2018\/R MeCab\/&#8221;)<\/p>\n<p># convert text files to vector<br \/>\nd &lt;- t(docMatrix2(&#8220;data\/writers&#8221;))<\/p>\n<p>myNaiveBayes &lt;- function(x, y) {<br \/>\nlev &lt;- levels(y) #1<br \/>\n# term frequency in each category<br \/>\nctf &lt;- sapply(lev, function(label) colSums(x[y == label,])) #2<br \/>\n# term probability in each category smoothed using Laplace smoothing<br \/>\nctp &lt;- t(t(ctf + 1) \/ (colSums(ctf) + nrow(ctf))) #3<br \/>\n# number of each class documents<br \/>\nnc &lt;- table(y, dnn = NULL) #4<br \/>\n# class prior<br \/>\ncp &lt;- nc \/ sum(nc) #5<br \/>\nstructure(list(lev = lev, cp = cp, ctp = ctp), class = &#8220;myNaiveBayes&#8221;) #6<br \/>\n}<\/p>\n<p>predict.myNaiveBayes &lt;- function(model, x) {<br \/>\nprob &lt;- apply(x, 1, function(x) colSums(log(model$ctp) * x)) #7<br \/>\nprob &lt;- prob + log(as.numeric(model$cp)) #8<br \/>\nlevel &lt;- apply(prob, 2, which.max) #9<br \/>\nmodel$lev[level] #10!!<br \/>\n}<\/p>\n<p>train.index &lt;- c(1:2, 5:9, 11)<br \/>\ny &lt;- factor(sub(&#8220;^([a-z]*?)_.*&#8221;, &#8220;\\\\1&#8221;, rownames(d), perl = TRUE))<br \/>\n# y; c(&#8220;ogai&#8221;, &#8220;soseki&#8221;)<\/p>\n<p>model &lt;- myNaiveBayes(d[train.index,], y[train.index])<br \/>\npredict(model, d[-train.index,])<\/p><\/blockquote>\n<p>\u30d5\u30a1\u30a4\u30eb\u306f\u540d\u524d\u9806\u306b\u30bd\u30fc\u30c8\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u30c6\u30b9\u30c8\u30b5\u30f3\u30d7\u30eb\u306f\u3001ogai, ogai, soseki, soseki\u306e\u9806\u306b\u51fa\u529b\u3055\u308c\u308c\u3070\u6b63\u89e3\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1535\" src=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0.png\" alt=\"\" width=\"913\" height=\"1290\" srcset=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0.png 913w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-106x150.png 106w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-212x300.png 212w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-768x1085.png 768w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-700x989.png 700w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-544x768.png 544w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/eaa2598cea307517b0b6ee72ab82d0a0-800x1130.png 800w\" sizes=\"auto, (max-width: 913px) 100vw, 913px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u304a\u308f\u308a\u306b<\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u6b63\u89e3\u304c\u5f97\u3089\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u5143\u306e<a href=\"https:\/\/abicky.net\/2011\/01\/30\/183233\/\">\u30ea\u30f3\u30af\u5148<\/a>\u306e\u65b9\u306e\u529f\u7e3e\u3067\u3057\u3087\u3046\u3002\u6b63\u78ba\u306a\u65b9\u6cd5\u3067\u4ed6\u306e\u624b\u6cd5\u3068\u6bd4\u8f03\u3057\u3066\u5b9f\u884c\u6642\u9593\u3092\u6e2c\u5b9a\u3057\u305f\u8a33\u3067\u306f\u306a\u3044\u306e\u3067\u5370\u8c61\u306a\u306e\u3059\u304c\u3001\u3053\u306e\u624b\u6cd5\u306f\u5b66\u7fd2\u304c\u304b\u306a\u308a\u901f\u3044\u3067\u3059\u3002\u3044\u305a\u308c\u306b\u3057\u3066\u3082\u3001\u3068\u308a\u3042\u3048\u305a\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f7f\u3044\u65b9\u306f\u7406\u89e3\u3067\u304d\u305f\u305e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6a5f\u68b0\u5b66\u7fd2\u7684\u306a\u4f55\u304b \u306f\u3058\u3081\u306b \u305d\u306e\u6614\u30012001\u5e74~2007\u5e74\u306b\u304b\u3051\u3066\u3001\u907a\u4f1d\u5b50\u767a\u73fe\u89e3\u6790\u3092\u3084\u3063\u3066\u3044\u305f\u9803\u3001SVM (support vector machine)\u3084Neural Network\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u809d\u81d3\u7531\u6765\u306e\u7d30\u80de\u306b&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1537,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-science"],"jetpack_featured_media_url":"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2018\/08\/965e5c7be269f28c5a4919e998b2e029.png","jetpack_shortlink":"https:\/\/wp.me\/p9b6zl-oJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts\/1533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1533"}],"version-history":[{"count":0,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts\/1533\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/media\/1537"}],"wp:attachment":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}