Upgrade to Pro — share decks privately, control downloads, hide ads and more …

とりあえず機械学習したかった

yubessy
February 26, 2018

 とりあえず機械学習したかった

社内勉強会用資料です

yubessy

February 26, 2018
Tweet

More Decks by yubessy

Other Decks in Programming

Transcript

  1. Agenda 1. スプレッドシー トを作る 2. 「 ツー ル」→「 スクリプトエディタ」 を開く

    3. http://www.numericjs.com/ をコピペする 4. 線形回帰を実装する 5. シー ト操作ボタンを実装する 6. ボタンを押す
  2. はい LinearRegression.prototype.train = function (x, y, numIter, alph if (numIter

    === undefined) numIter = 100; if (alpha === undefined) alpha = 0.01; if (lambda === undefined) lambda = 0; x = U.biased(x); var m = x.length; var n = x[0].length; var theta = U.zeros(n); for (var i = 0; i < numIter; i++) { var d = N.dot(N.transpose(x), N.sub(N.dot(x, theta), y)); if (lambda) { var r = N.mul(lambda, theta); r[0] = 0; N.addeq(d, r); } N.subeq(theta, N.mul(alpha / m, d)); }
  3. はい function run() { N = numeric; var ui =

    SpreadsheetApp.getUi(); var ss = SpreadsheetApp.getActiveSpreadsheet(); var dataSheet = ss.getActiveSheet(); var firstRow = 2; var firstColumn = 1; var numRow = dataSheet.getLastRow() - firstRow + 1; var numColumn = dataSheet.getLastColumn() - firstRow + 1; var dataRange = dataSheet.getRange(firstRow, firstColumn, numR var dataset = U.loadDataset(dataRange.getValues()); var model = new LinearRegression(); model.train(dataset.training.x, dataset.training.y, 100, var predictionY = model.predict(dataset.prediction.x); var trainingY_ = model.predict(dataset.training.x); var resultSheet = ss.insertSheet(dataSheet.getName() + "_resul resultSheet.getRange(1, 1).setValue(dataSheet.getRange(1, var values = U.mergeValues(predictionY, dataset.prediction.idx