{"action":"created","issue":{"url":"https://api.github.com/repos/tmcw/simple-statistics/issues/87","labels_url":"https://api.github.com/repos/tmcw/simple-statistics/issues/87/labels{/name}","comments_url":"https://api.github.com/repos/tmcw/simple-statistics/issues/87/comments","events_url":"https://api.github.com/repos/tmcw/simple-statistics/issues/87/events","html_url":"https://github.com/tmcw/simple-statistics/issues/87","id":59351549,"number":87,"title":"Multivariate Linear Regression","user":{"login":"tusharmath","id":194482,"avatar_url":"https://avatars.githubusercontent.com/u/194482?v=3","gravatar_id":"","url":"https://api.github.com/users/tusharmath","html_url":"https://github.com/tusharmath","followers_url":"https://api.github.com/users/tusharmath/followers","following_url":"https://api.github.com/users/tusharmath/following{/other_user}","gists_url":"https://api.github.com/users/tusharmath/gists{/gist_id}","starred_url":"https://api.github.com/users/tusharmath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tusharmath/subscriptions","organizations_url":"https://api.github.com/users/tusharmath/orgs","repos_url":"https://api.github.com/users/tusharmath/repos","events_url":"https://api.github.com/users/tusharmath/events{/privacy}","received_events_url":"https://api.github.com/users/tusharmath/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-02-28T18:14:18Z","updated_at":"2015-04-23T21:07:48Z","closed_at":null,"body":"Is there a plan to support multivariate linear regression? Some code - \r\n\r\n\r\n```javascript\r\nvar LinearRegression, MeanError, _;\r\n\r\n_ = require('lodash');\r\n\r\nMeanError = Error\r\n\r\nLinearRegression = (function() {\r\n  function LinearRegression() {}\r\n\r\n  LinearRegression.prototype._hypothesis = function(P, Xi) {\r\n    var tmp;\r\n    if (Xi[0] !== 1) {\r\n      throw new MeanError('x1 should be 1');\r\n    }\r\n    tmp = function(cost, Xij, j) {\r\n      return cost + Xij * P[j];\r\n    };\r\n    return _.reduce(Xi, tmp, 0);\r\n  };\r\n\r\n  LinearRegression.prototype._diffWithHypothesis = function(X, Y, P) {\r\n    return _.map(Y, (function(_this) {\r\n      return function(Yi, i) {\r\n        return Yi - _this._hypothesis(P, X[i]);\r\n      };\r\n    })(this));\r\n  };\r\n\r\n  LinearRegression.prototype._gradientDescent = function(P, X, Y, al) {\r\n    var hypDiff, m;\r\n    m = X.length;\r\n    if (m !== Y.length) {\r\n      throw new MeanError('labels length not matching training data');\r\n    }\r\n    hypDiff = this._diffWithHypothesis(X, Y, P);\r\n    return _.map(P, function(Pj, j) {\r\n      var func1;\r\n      func1 = function(val, Xi, i) {\r\n        return val + hypDiff[i] * Xi[j];\r\n      };\r\n      return Pj + al / m * _.reduce(X, func1, 0);\r\n    });\r\n  };\r\n\r\n  LinearRegression.prototype.train = function(X, Y, epoch, al) {\r\n    var P, n, predict, _i, _results;\r\n    if (epoch == null) {\r\n      epoch = 1000;\r\n    }\r\n    if (al == null) {\r\n      al = 0.1;\r\n    }\r\n    X = _.map(X, function(Xi) {\r\n      Xi.unshift(1);\r\n      return Xi;\r\n    });\r\n    n = X[0].length;\r\n    P = (function() {\r\n      _results = [];\r\n      for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }\r\n      return _results;\r\n    }).apply(this).map(function() {\r\n      return 0;\r\n    });\r\n    _.times(epoch, (function(_this) {\r\n      return function() {\r\n        return P = _this._gradientDescent(P, X, Y, al);\r\n      };\r\n    })(this));\r\n    predict = (function(_this) {\r\n      return function(testXi) {\r\n        testXi.unshift(1);\r\n        return _this._hypothesis(P, testXi);\r\n      };\r\n    })(this);\r\n    return {\r\n      predict: predict\r\n    };\r\n  };\r\n\r\n  return LinearRegression;\r\n\r\n})();\r\n\r\nmodule.exports = LinearRegression;\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/tmcw/simple-statistics/issues/comments/95719317","html_url":"https://github.com/tmcw/simple-statistics/issues/87#issuecomment-95719317","issue_url":"https://api.github.com/repos/tmcw/simple-statistics/issues/87","id":95719317,"user":{"login":"tmcw","id":32314,"avatar_url":"https://avatars.githubusercontent.com/u/32314?v=3","gravatar_id":"","url":"https://api.github.com/users/tmcw","html_url":"https://github.com/tmcw","followers_url":"https://api.github.com/users/tmcw/followers","following_url":"https://api.github.com/users/tmcw/following{/other_user}","gists_url":"https://api.github.com/users/tmcw/gists{/gist_id}","starred_url":"https://api.github.com/users/tmcw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmcw/subscriptions","organizations_url":"https://api.github.com/users/tmcw/orgs","repos_url":"https://api.github.com/users/tmcw/repos","events_url":"https://api.github.com/users/tmcw/events{/privacy}","received_events_url":"https://api.github.com/users/tmcw/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T21:07:48Z","updated_at":"2015-04-23T21:07:48Z","body":"seeing https://github.com/dambalah/shaman too"}}