{"id":50776,"date":"2021-12-15T00:00:00","date_gmt":"2021-12-15T08:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/"},"modified":"2025-11-14T07:55:05","modified_gmt":"2025-11-14T15:55:05","slug":"k-nearest-neighbor-algorithm-in-java","status":"publish","type":"post","link":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/","title":{"rendered":"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002<\/p>\n<p>KNN\u306f\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u5b66\u7fd2\u70b9\u306e\u8ddd\u96e2\u3092\u6c42\u3081\u308b\u3053\u3068\u3067\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u6b63\u3057\u3044\u30af\u30e9\u30b9\u3092\u4e88\u6e2c\u3057\u307e\u3059\u3002\u3053\u306e\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u306f\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u6700\u3082\u8fd1\u3044\u70b9\u3092K\u500b\u9078\u629e\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u304cK\u500b\u306e\u30af\u30e9\u30b9\u306b\u5206\u985e\u3055\u308c\u308b\u78ba\u7387\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u6700\u3082\u9ad8\u3044\u78ba\u7387\u3092\u6301\u3064\u30af\u30e9\u30b9\u304c\u9078\u629e\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>KNN \u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306f\u3001\u5b66\u7fd2\u30c7\u30fc\u30bf\u304b\u3089\u8b58\u5225\u95a2\u6570\u3092\u5b66\u7fd2\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u5b66\u7fd2\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u8a18\u61b6\u3059\u308b\u305f\u3081\u3001<em>\u9045\u5ef6\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0<\/em> \u3068\u547c\u3070\u308c\u307e\u3059\u3002<\/p>\n<h2>\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8<\/h2>\n<p>\u672a\u77e5\u306e\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u4e88\u6e2c\u3092\u884c\u3046\u305f\u3081\u306b\u3001\u9867\u5ba2\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u4f7f\u7528\u3059\u308b\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u9867\u5ba2\u306e\u5e74\u9f62\u3001\u53ce\u5165\u3001\u8cfc\u5165\u3057\u305f\u5546\u54c1\u306a\u3069\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/11\/data-1.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/11\/data-1.png\" alt=\"\" width=\"310\" height=\"117\" class=\"aligncenter size-full wp-image-27916\" srcset=\"\/wp-content\/uploads\/2021\/11\/data-1.png 310w, \/wp-content\/uploads\/2021\/11\/data-1-300x113.png 300w\" sizes=\"(max-width: 310px) 100vw, 310px\" \/><\/a><\/p>\n<p>\u5e74\u9f6258\u6b73\u3001\u53ce\u516551000\u5186\u306e\u304a\u5ba2\u69d8\u306b\u5bfe\u3059\u308b\u30aa\u30b9\u30b9\u30e1\u5546\u54c1\u3092\u898b\u3064\u3051\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u8ddd\u96e2\u3092\u8a08\u7b97\u3057\u3001\u6b21\u306b <code>k<\/code> \u306e\u5024\u306b\u5fdc\u3058\u3066\u6700\u3082\u8fd1\u3044 <code>k<\/code> \u4eba\u306e\u8fd1\u508d\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f <code>k<\/code> \u306e\u5024\u306f 1 \u3067\u3059\u304c\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\u6642\u306b <code>k<\/code> \u306e\u5024\u3092\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>k<\/code> \u304c 1 \u306e\u5834\u5408\u306f 1 \u500b\u306e\u88fd\u54c1\u3001\u3064\u307e\u308a 1 \u4ef6\u306e\u6700\u8fd1\u508d\u304c\u8868\u793a\u3055\u308c\u30012 \u306e\u5834\u5408\u306f 2 \u500b\u306e\u88fd\u54c1\u3001\u3064\u307e\u308a 2 \u4ef6\u306e\u6700\u8fd1\u508d\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>K-\u6700\u8fd1\u508d\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e Java \u3067\u306e\u5b9f\u88c5<\/h2>\n<p>\u4e0a\u8a18\u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u7528\u3044\u3066\u3001Java\u3067KNN\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3059\u3002\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306f <code>customers.csv<\/code> \u3068\u3044\u3046\u540d\u524d\u306eCSV\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>csv\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u3001GridDB\u306b\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001GridDB\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u3001\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u4f7f\u3063\u3066\u5206\u6790\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30dd\u30fc\u30c8<\/h3>\n<p>\u307e\u305a\u3001\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u306e\u3042\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">import java.io.IOException;\nimport java.util.Collection;\nimport java.util.Properties;\nimport java.util.Scanner;\nimport java.io.File;\n\nimport com.toshiba.mwcloud.gs.Collection;\nimport com.toshiba.mwcloud.gs.GSException;\nimport com.toshiba.mwcloud.gs.GridStore;\nimport com.toshiba.mwcloud.gs.GridStoreFactory;\nimport com.toshiba.mwcloud.gs.Query;\nimport com.toshiba.mwcloud.gs.RowKey;\nimport com.toshiba.mwcloud.gs.RowSet;<\/code><\/pre>\n<\/div>\n<h2>\u30c7\u30fc\u30bf\u3092GridDB\u306b\u66f8\u304d\u8fbc\u3080<\/h2>\n<p>CSV\u30d5\u30a1\u30a4\u30eb\u304b\u3089GridDB\u30b3\u30f3\u30c6\u30ca\u306b\u30c7\u30fc\u30bf\u3092\u79fb\u52d5\u3055\u305b\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u307e\u305a\u3001\u30b3\u30f3\u30c6\u30ca\u30fb\u30b9\u30ad\u30fc\u30de\u3092\u9759\u7684\u30af\u30e9\u30b9\u3068\u3057\u3066\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">\npublic static class Customers{\n\n        @RowKey int customer;\n        int age;\n        Double income;\n        String purchased_product;\n}<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u8a18\u306e\u30af\u30e9\u30b9\u306f\u3001\u30b3\u30f3\u30c6\u30ca\u30844\u3064\u306e\u30ab\u30e9\u30e0\u3092\u6301\u3064SQL\u30c6\u30fc\u30d6\u30eb\u306b\u4f3c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001GridDB\u3078\u306e\u63a5\u7d9a\u3092\u78ba\u7acb\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002GridDB\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3068\u304d\u306e\u6307\u5b9a\u60c5\u5831\u306b\u57fa\u3065\u3044\u3066Properties\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">\n        Properties props = new Properties();\n        props.setProperty(\"notificationAddress\", \"239.0.0.1\");\n        props.setProperty(\"notificationPort\", \"31999\");\n        props.setProperty(\"clusterName\", \"defaultCluster\");\n        props.setProperty(\"user\", \"admin\");\n        props.setProperty(\"password\", \"admin\");\n        GridStore store = GridStoreFactory.getInstance().getGridStore(props);<\/code><\/pre>\n<\/div>\n<p>GridDB \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u3001\u4e0a\u8a18\u306e\u5185\u5bb9\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u3001<code>Customers<\/code>\u30b3\u30f3\u30c6\u30ca\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u3001\u3053\u308c\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">Collection&lt;String, Customers> coll = store.putCollection(\"col01\", Customers.class);<\/code><\/pre>\n<\/div>\n<p>\u30b3\u30f3\u30c6\u30ca <code>Customers<\/code> \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u4f5c\u6210\u3055\u308c\u3001<code>coll<\/code> \u3068\u3044\u3046\u540d\u524d\u304c\u4ed8\u3051\u3089\u308c\u307e\u3057\u305f\u3002\u3053\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f7f\u3063\u3066\u3001\u30b3\u30f3\u30c6\u30ca\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30c7\u30fc\u30bf\u3092GridDB\u306b\u683c\u7d0d\u3059\u308b<\/h2>\n<p>\u4ee5\u4e0b\u306eJava\u30b3\u30fc\u30c9\u3067\u3001<code>customers.csv<\/code>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001GridDB\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">\n                File file1 = new File(\"customers.csv\");\n                Scanner sc = new Scanner(file1);\n                String data = sc.next();\n \n                while (sc.hasNext()){\n                        String scData = sc.next();\n                        String dataList[] = scData.split(\",\");\n                        String customer = dataList[0];\n                        String age = dataList[1];\n                        String income = dataList[2];\n                        String purchased_product = dataList[3];\n                        \n                        Customers customers = new Customers();\n                        customers.customer = Integer.parseInt(customer);\n                        customers.age = Integer.parseInt(age);\n                        customers.income = Double.parseDouble(income);\n                        customers.purchased_product = purchased_product;\n                        coll.append(customers);\n                 }<\/code><\/pre>\n<\/div>\n<p>\u9867\u5ba2\u306b\u95a2\u3059\u308b\u30c7\u30fc\u30bf\u3067 <code>customers<\/code> \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001GridDB \u30b3\u30f3\u30c6\u30ca\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>GridDB \u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u3044\u3088\u3044\u3088GridDB\u30b3\u30f3\u30c6\u30ca\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">\n                Query&lt;customers> query = coll.query(\"select *\");\n                RowSet&lt;customers> rs = query.fetch(false);\n                RowSet res = query.fetch();<\/code><\/pre>\n<\/div>\n<p><code>select *<\/code>\u6587\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b3\u30f3\u30c6\u30ca\u304b\u3089\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u3092\u554f\u3044\u5408\u308f\u305b\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n<h3>\u5206\u985e\u5668\u306e\u69cb\u7bc9<\/h3>\n<p>\u3044\u3088\u3044\u3088 KNN \u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3068\u8aad\u307f\u8fbc\u307e\u308c\u305f\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u5206\u985e\u5668\u3092\u69cb\u7bc9\u3059\u308b\u6642\u304c\u6765\u307e\u3057\u305f\u3002\u305d\u306e\u305f\u3081\u306b\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">import java.io.IOException;\nimport java.util.Enumeration;\nimport java.text.DecimalFormat;\n\nimport weka.classifiers.Classifier;\nimport weka.core.Instances;\nimport weka.classifiers.lazy.IBk;\nimport weka.classifiers.Evaluation;\nimport weka.core.Instance;\nimport weka.core.converters.ArffLoader;<\/code><\/pre>\n<\/div>\n<p>\u305d\u308c\u3067\u306f\u3001\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3057\u3001\u305d\u306e\u7d71\u8a08\u60c5\u5831\u3092\u30d7\u30ea\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-java\">res.setClassIndex(res.numAttributes() - 1);\n        Classifier cls = new IBk(1);        \n        cls.buildClassifier(res);\n    \n        System.out.println(cls);\n       \n        Evaluation evaluation = new Evaluation(res);\n        evaluation.evaluateModel(cls, res);\n        \n        System.out.println(evaluation.toSummaryString());\n        System.out.println(evaluation.toClassDetailsString());\n        System.out.println(evaluation.toMatrixString());<\/code><\/pre>\n<\/div>\n<p>IBk \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3059\u308b\u969b\u306b <code>k<\/code> \u306e\u5024\u3092\u6307\u5b9a\u3057\u307e\u3057\u305f\u3002IBk \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306f\u6574\u6570\u306e\u5f15\u6570\u3092\u53d6\u308a\u307e\u3059\u30021 \u3068\u3044\u3046\u5024\u3092\u6e21\u3059\u3068\u30011 \u3064\u306e\u6700\u8fd1\u508d\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u30022 \u3092\u6e21\u3059\u3068\u30012 \u3064\u306e\u6700\u8fd1\u508d\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u5f15\u6570\u3092\u6e21\u3055\u305a\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u547c\u3073\u51fa\u3057\u305f\u5834\u5408\u306f\u30011\u8fd1\u508d\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u4eca\u56de\u306e\u5834\u5408\u30011\u3068\u3044\u3046\u5024\u3092\u6e21\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u9867\u5ba2\u306e\u6700\u8fd1\u508d\u30921\u4ef6\u4e88\u6e2c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30b3\u30fc\u30c9\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u5b9f\u884c<\/h2>\n<p>\u307e\u305a\u3001<code>gsadm<\/code> \u30e6\u30fc\u30b6\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002\u4f5c\u6210\u3057\u305f <code>.java<\/code> \u30d5\u30a1\u30a4\u30eb\u3092 GridDB \u306e <code>bin<\/code> \u30d5\u30a9\u30eb\u30c0\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002\u79fb\u52d5\u5148\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre><code>\/griddb_4.6.0-1_amd64\/usr\/griddb-4.6.0\/bin\n<\/code><\/pre>\n<p>\u6b21\u306b\u3001Linux\u7aef\u672b\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3001gridstore.jar\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">export CLASSPATH=$CLASSPATH:\/home\/osboxes\/Downloads\/griddb_4.6.0-1_amd64\/usr\/griddb-4.6.0\/bin\/gridstore.jar<\/code><\/pre>\n<\/div>\n<p>\u6b21\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066 <code>.java<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">javac KNNeighbor.java<\/code><\/pre>\n<\/div>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u751f\u6210\u3055\u308c\u305f .class \u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">java KNNeighbor<\/code><\/pre>\n<\/div>\n<p>KNN\u30e2\u30c7\u30eb\u306f\u3001\u9867\u5ba2\u306e\u6700\u8fd1\u508d\u30921\u3064\u8fd4\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002 KNN\u306f\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u5b66\u7fd2\u70b9\u306e\u8ddd\u96e2\u3092\u6c42\u3081\u308b\u3053\u3068\u3067\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u6b63\u3057 [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":49333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1005],"tags":[],"class_list":["post-50776","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-1005"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb.net\/ja\/\u672a\u5206\u985e\/k-nearest-neighbor-algorithm-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb.net\/ja\/\u672a\u5206\u985e\/k-nearest-neighbor-algorithm-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-15T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-14T15:55:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2021\/11\/nearest.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1160\" \/>\n\t<meta property=\"og:image:height\" content=\"653\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"griddb-admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"griddb-admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/\"},\"author\":{\"name\":\"griddb-admin\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\"},\"headline\":\"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\",\"datePublished\":\"2021-12-15T08:00:00+00:00\",\"dateModified\":\"2025-11-14T15:55:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/\"},\"wordCount\":41,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2021\/11\/nearest.png\",\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/\",\"url\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/\",\"name\":\"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2021\/11\/nearest.png\",\"datePublished\":\"2021-12-15T08:00:00+00:00\",\"dateModified\":\"2025-11-14T15:55:05+00:00\",\"description\":\"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002\",\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2021\/11\/nearest.png\",\"contentUrl\":\"\/wp-content\/uploads\/2021\/11\/nearest.png\",\"width\":1160,\"height\":653},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb.net\/en\/#website\",\"url\":\"https:\/\/griddb.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\",\"name\":\"griddb-admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"caption\":\"griddb-admin\"},\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/author\/griddb-admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT","description":"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002","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:\/\/griddb.net\/ja\/\u672a\u5206\u985e\/k-nearest-neighbor-algorithm-in-java\/","og_locale":"ja_JP","og_type":"article","og_title":"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT","og_description":"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002","og_url":"https:\/\/griddb.net\/ja\/\u672a\u5206\u985e\/k-nearest-neighbor-algorithm-in-java\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2021-12-15T08:00:00+00:00","article_modified_time":"2025-11-14T15:55:05+00:00","og_image":[{"width":1160,"height":653,"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/wp-content\/uploads\/2021\/11\/nearest.png","type":"image\/png"}],"author":"griddb-admin","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"\u57f7\u7b46\u8005":"griddb-admin","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"2\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#article","isPartOf":{"@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/"},"author":{"name":"griddb-admin","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233"},"headline":"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0","datePublished":"2021-12-15T08:00:00+00:00","dateModified":"2025-11-14T15:55:05+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/"},"wordCount":41,"commentCount":0,"publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2021\/11\/nearest.png","inLanguage":"ja","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/","url":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/","name":"Java\u306b\u3088\u308bK-Nearest Neighbor\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0 | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage"},"image":{"@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2021\/11\/nearest.png","datePublished":"2021-12-15T08:00:00+00:00","dateModified":"2025-11-14T15:55:05+00:00","description":"\u306f\u3058\u3081\u306b K-nearest neighbors (KNN) \u306f\u5206\u985e\u3084\u56de\u5e30\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u6559\u5e2b\u3042\u308a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002","inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/griddb.net\/ja\/%e6%9c%aa%e5%88%86%e9%a1%9e\/k-nearest-neighbor-algorithm-in-java\/#primaryimage","url":"\/wp-content\/uploads\/2021\/11\/nearest.png","contentUrl":"\/wp-content\/uploads\/2021\/11\/nearest.png","width":1160,"height":653},{"@type":"WebSite","@id":"https:\/\/griddb.net\/en\/#website","url":"https:\/\/griddb.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/griddb.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233","name":"griddb-admin","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","caption":"griddb-admin"},"url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/author\/griddb-admin\/"}]}},"_links":{"self":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/posts\/50776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/comments?post=50776"}],"version-history":[{"count":1,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/posts\/50776\/revisions"}],"predecessor-version":[{"id":51610,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/posts\/50776\/revisions\/51610"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/media\/49333"}],"wp:attachment":[{"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/media?parent=50776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/categories?post=50776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/ja\/wp-json\/wp\/v2\/tags?post=50776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}