{"id":5888,"date":"2025-03-28T16:13:50","date_gmt":"2025-03-28T07:13:50","guid":{"rendered":"https:\/\/yorozu.cloudfree.jp\/wordpress\/?p=5888"},"modified":"2025-03-28T16:16:39","modified_gmt":"2025-03-28T07:16:39","slug":"5888","status":"publish","type":"post","link":"https:\/\/yorozu.cloudfree.jp\/wordpress\/?p=5888","title":{"rendered":"\u7df4\u7fd2\u554f\u984c\uff0851\u301c55\uff09"},"content":{"rendered":"\n<p>\u5b9f\u884c\u4f8b\u306f\u300cstupa.sarnath\u300d\u306e\u300cGoogle Colabotry\u300d\u74b0\u5883\u306b\u4fdd\u5b58\u3057\u3066\u3042\u308b<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&quot;&quot;&quot;\n\n\u6f14\u7fd21\uff08for\u306e\u30cd\u30b9\u30c8\uff09\n1\u304b\u308931\u307e\u3067\u306e\u6574\u6570\u3092\u8981\u7d20\u3068\u3059\u308b\u30ea\u30b9\u30c81\u3068\uff0c1\u304b\u308912\u307e\u3067\u306e\u6574\u6570\u3092\u8981\u7d20\u3068\u3059\u308b\u30ea\u30b9\u30c82\u3092\u4f5c\u6210\u3057\u307e\u3059\uff0e\u30ea\u30b9\u30c81\u3068\u30ea\u30b9\u30c82\u304b\u3089\u5024\u30921\u3064\u305a\u3064\u53d6\u3063\u3066\u304d\u305f\u6642\uff0c1\u306e\u4f4d\u304c\u4e00\u81f4\u3059\u308b\u5024\u304c\u4f55\u7d44\u3042\u308b\u304b\u3092\u6c42\u3081\u3066\u304f\u3060\u3055\u3044\uff0e\u4f8b\u3048\u3070\uff0c1\u306811\u306f\uff0c1\u306e\u4f4d\u304c\u4e21\u65b91\u306a\u306e\u3067\uff0c\u30ab\u30a6\u30f3\u30c8\u306b\u5165\u308a\u307e\u3059\uff0e1\u30681\uff0c31\u30681\u306a\u3069\u3082\u540c\u69d8\u3067\u3059\uff0e\n\n\u671f\u5f85\u3059\u308b\u51fa\u529b\uff1a38\n\n\u6f14\u7fd22\uff08\u8f9e\u66f8\u306e\u5024\u30bd\u30fc\u30c8\uff09\n\u8f9e\u66f8\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\uff0e\n\ndic = {&#39;two&#39;:324, &#39;four&#39;:830, &#39;three&#39;:493, &#39;one&#39;:172, &#39;five&#39;:1024}\n\u3053\u306e\u6642\uff0c\u5024\u3067\u6607\u9806\u30bd\u30fc\u30c8\u3057\u305f\u3068\u8003\u3048\u305f\u5834\u5408\u306e\u30ad\u30fc\u306e\u4e26\u3073\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\uff0e\n\n\u671f\u5f85\u3059\u308b\u51fa\u529b\uff1a[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;, &#39;four&#39;, &#39;five&#39;]\n\n\u6f14\u7fd23\uff08num2freq\uff09\n\u30ea\u30b9\u30c8\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\uff0e\n\nnums = [1,2,4,3,2,1,5,1]\n\u3053\u306e\u30ea\u30b9\u30c8\u306b\u5bfe\u3057\u3066\uff0c\u8981\u7d20\u306e\u51fa\u73fe\u6570\u3092\u683c\u7d0d\u3057\u305f\u8f9e\u66f8num2freq\u3092\u4f5c\u6210\u3057\uff0c\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\uff0e\u3053\u308c\u306fnum2freq[\u8981\u7d20] = \u51fa\u73fe\u6570\u3068\u306a\u308b\u3088\u3046\u306a\u8f9e\u66f8\u3067\uff0c\u4f8b\u3048\u3070num2freq[1] = 3\u3067\u3059\uff0e\n\n\u671f\u5f85\u3059\u308b\u51fa\u529b\uff1a{1: 3, 2: 2, 4: 1, 3: 1, 5: 1}\n\n\u6f14\u7fd24\uff08word2freq\uff09\n\u4eca\uff0c\u6587\u5b57\u5217\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4e0e\u3048\u3089\u308c\u3066\u3044\u307e\u3059\uff0e\n\ndoc = &#39;i bought an apple .\\ni ate it .\\nit is delicious .&#39;\n\\n\u306f\u6539\u884c\u8a18\u53f7\u306a\u306e\u3067\uff0c3\u3064\u306e\u6587\u304c3\u884c\u306b\u6e21\u3063\u3066\u66f8\u304b\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\uff0e\n\u3053\u306e\u6587\u7ae0\u4e2d\u306e\u5358\u8a9e\u3092\u7528\u3044\u3066\uff0c\u30ad\u30fc\u3068\u3057\u3066\u5358\u8a9e\uff0c\u5024\u3068\u3057\u3066\u51fa\u73fe\u6570\u3092\u6301\u3064\u3088\u3046\u306a\u8f9e\u66f8word2freq\u3092\u4f5c\u6210\u3057\uff0c\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\uff0e\u305f\u3060\u3057\uff0c\u6539\u884c\u8a18\u53f7\u306f\u5358\u8a9e\u306b\u542b\u3081\u306a\u3044\u3067\u304f\u3060\u3055\u3044\uff0e\n\u30d2\u30f3\u30c8\uff1a\u6539\u884c\u8a18\u53f7\u3067split\u3057\u3066\u304b\u3089\u7a7a\u767d\u3067split\u3059\u308c\u3070\uff0c\u5358\u8a9e\u306b\u5206\u5272\u3067\u304d\u307e\u3059\uff0e\n\n\u671f\u5f85\u3059\u308b\u51fa\u529b\uff1a{&#39;i&#39;: 2, &#39;bought&#39;: 1, &#39;an&#39;: 1, &#39;apple&#39;: 1, &#39;.&#39;: 3, &#39;ate&#39;: 1, &#39;it&#39;: 2, &#39;is&#39;: 1, &#39;delicious&#39;: 1}\n\n\u6f14\u7fd25\uff08Jaccard\u4fc2\u6570\uff09\n2\u3064\u306e\u96c6\u5408A,B\u306e\u985e\u4f3c\u5ea6\u3092\u8a08\u7b97\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066\uff0cJaccard\u4fc2\u6570\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\uff0e\u4f8b\u3048\u3070\uff0c\u6587\u7ae0\u306e\u985e\u4f3c\u5ea6\u306e\u6307\u6a19\u3068\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\uff0e\n\nJaccard(A,B)=|A\u2229B||A\u222aB|=A\u3068B\u306e\u7a4d\u96c6\u5408\u306e\u8981\u7d20\u6570A\u3068B\u306e\u548c\u96c6\u5408\u306e\u8981\u7d20\u6570\n2\u3064\u306e\u30ea\u30b9\u30c8\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4e0e\u3048\u3089\u308c\u3066\u3044\u308b\u6642\uff0c\u30ea\u30b9\u30c8\u3092\u96c6\u5408\u3068\u898b\u306a\u3057\u305f\u6642\u306eJaccard\u4fc2\u6570\u306e\u5024\u3092\u6c42\u3081\u3066\u304f\u3060\u3055\u3044\uff0e\n\nlist1 = [12,23,34,45,56,67,78,89]\nlist2 = [21,32,43,45,65,67,78,98]\n\u671f\u5f85\u3059\u308b\u51fa\u529b\uff1a0.23076923076923078\n\n&quot;&quot;&quot;\n#\n#\n#\u6f14\u7fd21\uff08for\u306e\u30cd\u30b9\u30c8\uff09\n#\nprint(&quot;\u6f14\u7fd21\uff08for\u306e\u30cd\u30b9\u30c8\uff09&quot;)\n#\nl1 = list(range(1,32))\nl2 = list(range(1,13))\n#print(l1)\n#print(l2)\ncnt = 0\nfor item1 in l1:\n  for item2 in l2:\n    if item1 % 10 == item2 % 10:\n#      print(item1,item2)\n      cnt += 1\nprint(cnt)\n#\n#\u6f14\u7fd22\uff08\u8f9e\u66f8\u306e\u5024\u30bd\u30fc\u30c8\uff09\n#\nprint(&quot;\u6f14\u7fd22\uff08\u8f9e\u66f8\u306e\u5024\u30bd\u30fc\u30c8\uff09&quot;)\n#\ndic = {&#39;two&#39;:324, &#39;four&#39;:830, &#39;three&#39;:493, &#39;one&#39;:172, &#39;five&#39;:1024}\nitem = list(dic.items())\n#print(item)\nx = sorted(item, key=lambda x:x[1])\n#print(x)\nq = [i[0] for i in x]\nprint(q)\n#\n#\u6f14\u7fd23\uff08num2freq\uff09\n#\nprint(&quot;\u6f14\u7fd23\uff08num2freq\uff09&quot;)\n#\nnums = [1,2,4,3,2,1,5,1]\nnum2freq = {}\nfor i in nums:\n  num2freq[i] = num2freq.get(i, 0) + 1\n#  print(num2freq[i])\nprint(num2freq)\n#\n#\u6f14\u7fd24\uff08word2freq\uff09\n#\nprint(&quot;\u6f14\u7fd24\uff08word2freq\uff09&quot;)\n#\ndoc = &#39;i bought an apple .\\ni ate it .\\nit is delicious .&#39;\nword2freq = {}\nx1 = doc.split(&#39;\\n&#39;)\n#print(x1)\nfor x in x1:\n  words = x.split()\n#  print(words)\n  for word in words:\n    word2freq[word] = word2freq.get(word, 0) + 1\nprint(word2freq)\n#\n#\u6f14\u7fd25\uff08Jaccard\u4fc2\u6570\uff09\n#\nprint(&quot;\u6f14\u7fd25\uff08Jaccard\u4fc2\u6570\uff09&quot;)\n#\nlist1 = [12,23,34,45,56,67,78,89]\nlist2 = [21,32,43,45,65,67,78,98]\na = set(list1)\nb = set(list2)\ninter_set = a.intersection(b)\nunion_set = a.union(b)\nprint(len(inter_set) \/ len(union_set))\n<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30fbPython\u5b66\u7fd2\uff08\uff15\uff15\u672c\u30ce\u30c3\u30af\uff09\u306b\u3064\u3044\u3066<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[17],"class_list":["post-5888","post","type-post","status-publish","format-standard","hentry","category-99_","tag-python"],"_links":{"self":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5888"}],"version-history":[{"count":4,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5888\/revisions"}],"predecessor-version":[{"id":5893,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5888\/revisions\/5893"}],"wp:attachment":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}