ã¯ããã«
OLL によるオンライン学習を試してみた - 凹みTips ã«ã¦ oll ï¼Online-Learning Library) ã触ã£ã¦ã¿ãè¨äºãæ¸ãã¾ãããããããå ã« oll ã node.js ã®ã¢ããªã³åããã¦ã¿ã¾ããã
ãã¦ã³ãã¼ã
使ã£ã¦ã¿ã
github ã® README ã«ãæ¸ãã¾ããã以ä¸ã®ããã«ä½¿ãã¾ãã
2012/06/20 0:25 - add ã®å¼æ°ãä¿®æ£
var oll = require('./build/Release/oll'); var PA1 = new oll.PA1(); // å¦ç¿ã¨ãã¹ã PA1.add(true, '0:1.0 1:2.0 2:-1.0'); PA1.add(false, '0:-0.5 1:1.0 2:-0.5'); console.log(PA1.test('0:1.0 1:1.0')); // 0.1714285910129547 // å¦ç¿çµæããã¡ã¤ã«ã¸ä¿å PA1.save('test.dat'); // å¦ç¿çµæããã¡ã¤ã«ãã復å var PA1_2 = new oll.PA1(); PA1_2.load('test.dat'); console.log(PA1_2.test('0:1.0 1:1.0')); // 0.1714285910129547
ãããªæãã§å¦ç¿ã¨ãã¹ããå¦ç¿çµæããã¡ã¤ã«ã¸ä¿åãã¾ããã®å¾©å
ãå¯è½ã§ãã
å¦ç¿ã®ããæ¹ã¯ä»¥ä¸ã®å½¢å¼ã§ãå¯è½ã§ãã
PA1.add('+1 0:1.0 1:2.0 2:-1.0'); PA1.add('-1 0:-0.5 1:1.0 2:-0.5');
å¦ç¿ææ³ã¯ä»¥ä¸ã®ãã®ã使ãã¾ãã
P : Perceptron AP : Averaged Perceptron PA : Passive Agressive PA1 : Passive Agressive I PA2 : Passive Agressive II PAK : Kernelized Passive Agressive CW : Confidence Weighted
ã½ã¼ã¹ã³ã¼ãã® PA1 ã®ã¨ãããæ¸ãæããã° OK ã§ãã
ã¾ãã³ã³ã¹ãã©ã¯ã¿ã§åæå¤ã®è¨å®ãå¯è½ã§ãã
var Perceptron = new oll.P({C: 2.0, bias: 1.0});
C 㯠oll_train ã® -C ãã©ã¡ã¼ã¿ã«ç¸å½ãããã©ã«ã㧠1.0ãbias 㯠-b ãã©ã¡ã¼ã¿ã«ç¸å½ãããã©ã«ã㧠0.0 ã§ãã
ããã¡ãã£ã¨ãã£ããæ©æ¢°å¦ç¿ããã¦ã¿ã
oll ã®ãã¼ã¸ã«æ¸ãã¦ããå
容ããã¹ããã¦ã¿ã¾ãã
åèï¼Perceptron を勉強する前にオンライン機械学習ライブラリを試してみる (nakatani @ cybozu labs)
ããã«æ¸ãã¦ãããã¨ã¨åããããªãã¨ããã¦ã¿ã¾ãã
ããã㨠getline çãªæåã¯ä»¥ä¸ã®ãã¼ã¸ãåèã«ãã¾ããã
node.jsで1行ずつテキストを読み込む方法 - ホワイトぼーど
ã³ã¼ã
// ã©ã¤ãã©ãªã®èªã¿è¾¼ã¿ var fs = require('fs'); var oll = require('./build/Release/oll'); var Perceptron = new oll.P({C: 2.0, bias: 1.0}); // å¦ç¿ var trainData = fs.readFileSync('data/news20.train').toString().split('\n'); for (var i in trainData) { Perceptron.add(trainData[i]); } // ãã¹ã var testData = fs.readFileSync('data/news20.test').toString().split('\n'); var success = 0, failure = 0; for (var i in testData) { var b = testData[i].charAt(0); var result = Perceptron.test(testData[i].substr(3)); if ( (b == '+' && result > 0) || (b == '-' && result < 0) ) ++success; else ++failure; } // çµæ console.log("success\t: " + success); console.log("failure\t: " + failure); console.log( (success) / (success + failure) * 100 + "%");
çµæ
success : 4879 failure : 118 97.63858314988994%
æ¬å®¶ã¨ä¼¼ããããªæ°å¤ãåºã¾ãããCW ã¨ãã§ãã£ãã 99% è¶ ãã¦ã¾ãããéã«åºããã¦ãã£ã¦ãã®ãä¸å®ã«ãªã£ã¦ãããã
ãããã«
node.js ã®ã¢ããªã³åãã㨠v8 åä½ã§ããããã node.js ã®ããããªè³ç£ã使ãã¦è¯ãã§ãããTwitter ããä½ãå¼ã£å¼µã£ã¦ãã¦å¦ç¿ãããã¨ããç°¡åã«ã§ãããã§ããåã®ã¨ã³ããªã§æ¸ãã node-mecab ã¨ãã¨çµã¿åããããããªããä½ãé¢ç½ããã¨åºæ¥ãªãããªããã