├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── learn.js ├── lib └── exec.py ├── modules ├── cluster.js ├── ensemble.js ├── linear_model.js ├── neighbors.js └── preprocessing.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | npm-debug.log 3 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Luke Ramsey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Scikit-Node NPM Module

2 | 3 | ## Contents 4 | 5 | [What is Scikit-Node?](#about) 6 | [Setup Process](#setup) 7 | [API](#use) 8 | [skLearn](#sk) 9 | [Helper Methods](#halp) 10 | 11 | ## What is Scikit-Node 12 | 13 | Scikit-Node is an npm wrapper for Python's scikit-learn library. Using this module, you can use scikit-learn a node.js server. To learn more about scikit-learn, please go to http://scikit-learn.org/stable/. The methods on the Scikit-node Module spawn a python process that executes scikit-learn estimators and methods. The results from these algorithms are then streamed up to node. 14 | 15 | This module is currently in beta, so feedback and contributions would be appreciated! I am available by email at lramsey177@gmail.com or through a github issues request. 16 | 17 | ## Set Up Process 18 | 19 | In order to run Scikit-Node, there are several dependencies that need to be present. The first step would be to make sure node.js, npm, and a python verison of >= 27. or >= 3.2 has been installed. To install these items, I would recommend checking out http://nodejs.org/download/ and https://www.python.org/download/. 20 | 21 | In addition, there are several python modules that need to be installed for the module to function properly. These modules are scikit-learn, numpy, and jsonpickle. For install instructions for scikit-learn and numpy, please go to http://scikit-learn.org/stable/install.html. The version of scikit-node I have used in producing this module is 0.15. For jsonpickle, please go to http://jsonpickle.github.io/#download-install. Some additional python modules used in this project are importlib, argparse and ast. These modules are all included in the Python Standard Library, so there should be no need to download them. 22 | 23 | Once these dependencies are installed, add the Scikit-Node module to your project by typing 'npm install scikit-node' into the terminal. 24 | 25 | ## API 26 | 27 | To use the Scikit-Node npm module, begin by requiring the module. 28 | 29 | sk = require('scikit-node') 30 | 31 | ## skLearn 32 | 33 | All methods of the Scikit-Node module arise from the skLearn method. 34 | 35 | sk.skLearn(module, estimator, methods, callback) 36 | 37 | This function requires four arguments. The module argument is a string that mentions which scikit-learn module is needed. For example, if one wanted to use the RandomForestClassifier estimator, this estimator needs to be accessed on the ensemble module in scikit learn. 38 | 39 | module = 'ensemble' 40 | 41 | The second estimator contains an array, where index 0 of the array is a string referring to an estimator object. All succeeding elements in the estimator array are the hyperparameters which are used to fine tune the estimator. Estimators are objects scikit-learn uses to carry out its machine learning. Estimators contain methods which are customized to the algorithm indicated by the estimator. The hyperparameters change how the algoirthm is run. Check the Scikit-learn documentation to see the proper order you need when passing hyperparamers to estimators. 42 | 43 | estimator = ['RandomForestClassifier', 100] 44 | 45 | The methods argument contains an array of arrays. Each inner array contains a method on the chosen estimator at index 0. All succeeding indexes in each inner arrray contains arguments for that method. 46 | 47 | methods = ['fit', X, Y] 48 | 49 | The callback argument is a function that runs once the python process has streamed its results to node. This callback function gives you direct access to the results of the scikit-learn methods. The results of every scikit-learn method except fit will be added to a results array, which is ordered based on the order methods were placed in the methods parameter. 50 | 51 | ## Helper Methods 52 | 53 | On top of the skLearn method, there are also several helper methods which make using the module easier. Using the helper methods, one would not need to put parameters in for the module and estimator, but instead would just need to choose the correct method for a desired estimator. The helper method calls the skLearn method, passing in the desired module and estimator for you. Some of the helper methods may not work if you have a scikit-learn version of 0.14 or earlier, as version 0.15 has some new methods that earlier versions lacked. 54 | 55 | All these helper methods expect the same kind of arguments. One example of such a helper method is the randomForestClassifier method. 56 | 57 | sk.randomForestClassifier(methods, callback, hyperparams) 58 | 59 | The methods argument here is the same as the one above in the skLearn method. The callback parameter allows you to use the results of your scikit-learn methods in node. The hyperparams argument contains an array that holds all the hyperparams that will be passed to a scikit-learn estimator. 60 | 61 | Helper methods from these below scikit-learn modules have been added to scikit-node. 62 | 63 | cluster 64 | ensemble 65 | linear_model 66 | preprocessing 67 | 68 | To investigate the helper methods that have been added to each module, there is an algorithm checker method for each module. They are of the format 'moduleAlgorithms', where the word module is replaced by the actual name of the desired module. 69 | 70 | clusterAlgorthms() 71 | 72 | This algorithm checker method will return an object where the keys are each helper method from that module in scikit-node, and the values are the functions themselves for that module. 73 | 74 | If you want a certain module or helper method added to Scikit-Node, please feel free to submit a github issues request or send me an email at lramsey177@gmail.com. Contributors are welcome to submit pull requests as well to add new helper methods to Scikit-Node. 75 | 76 | [Contents](#contents) 77 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var sk = require('./learn'); 2 | var cluster = require('./modules/cluster'); 3 | var ensemble = require('./modules/ensemble'); 4 | var linear_model = require('./modules/linear_model'); 5 | var neighbors = require('./modules/neighbors'); 6 | var preprocessing = require('./modules/preprocessing'); 7 | 8 | var _extend = function(obj1){ 9 | var objs = Array.prototype.slice.call(arguments,1); 10 | objs.forEach(function(obj){ 11 | for(var key in obj){ 12 | obj1[key] = obj[key]; 13 | } 14 | }); 15 | }; 16 | 17 | _extend(sk, cluster, ensemble, linear_model, neighbors, preprocessing); 18 | 19 | sk.allModules = function(){ 20 | return { 'cluster':sk.clusterAlgorithms, 'ensemble':sk.ensembleAlgorithms, 'linear_model':sk.linear_modelAlgorithms, 'preprocessing':sk.preprocessing }; 21 | }; 22 | 23 | module.exports = sk; 24 | -------------------------------------------------------------------------------- /learn.js: -------------------------------------------------------------------------------- 1 | var child = require('child_process'); 2 | 3 | var sk = {}; 4 | 5 | sk.SKLearn = function(module, estimator, methods, cb){ 6 | cb = cb || function(){}; 7 | arg = JSON.stringify([module, estimator, methods]); 8 | python = child.spawn( 9 | 'python', [__dirname + '/lib/exec.py', arg]); 10 | output = ''; 11 | python.stdout.on('data', function(data){ 12 | output += data; 13 | }); 14 | python.stdout.on('error', function(err){ 15 | throw new Error(err); 16 | }); 17 | python.stdout.on('close', function(){ 18 | results = JSON.parse(output); 19 | cb(results); 20 | }); 21 | }; 22 | 23 | module.exports = sk; 24 | -------------------------------------------------------------------------------- /lib/exec.py: -------------------------------------------------------------------------------- 1 | import jsonpickle as j 2 | import numpy as np 3 | import importlib 4 | import argparse 5 | import ast 6 | 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument('args') 9 | args = parser.parse_args() 10 | arguments = ast.literal_eval(args.args) 11 | module = importlib.import_module('sklearn.' + arguments[0]) 12 | estimatorName = arguments[1].pop(0) 13 | estimatorFunc = eval('module.' + estimatorName) 14 | estimator = estimatorFunc(*arguments[1]) 15 | 16 | methods = arguments[2] 17 | 18 | results = {} 19 | for i in range(0, len(methods)): 20 | methodName = methods[i].pop(0) 21 | 22 | params = [] 23 | for k in range(0, len(methods[i])): 24 | param = np.array(methods[i][k], dtype='float64') 25 | params.append(param) 26 | 27 | if(methodName == 'fit'): 28 | estimator.fit(*params) 29 | else: 30 | method = eval('estimator.' + methodName) 31 | data = method(*params) 32 | results[methodName] = data 33 | 34 | 35 | for data in results: 36 | results[data] = results[data].tolist() 37 | 38 | print j.encode(results) 39 | -------------------------------------------------------------------------------- /modules/cluster.js: -------------------------------------------------------------------------------- 1 | var sk = require('../learn'); 2 | var cluster = {}; 3 | var amodule = 'cluster'; 4 | var estimator; 5 | 6 | cluster.clusterAlgorithms = function(){ 7 | var estimators = {}; 8 | var key; 9 | for(key in cluster){ 10 | estimators[key] = cluster[key]; 11 | } 12 | delete estimators.clusterAlgorithms; 13 | return estimators; 14 | }; 15 | 16 | var AffinityPropagation = cluster.AffinityPropagation = function(methods, cb, hyperparams){ 17 | hyperparams = hyperparams || []; 18 | estimator = ['AffinityPropagation'].concat(hyperparams); 19 | return sk.SKLearn(amodule, estimator, methods, cb); 20 | }; 21 | 22 | var AgglomerativeClustering = cluster.AgglomerativeClustering = function(methods, cb, hyperparams){ 23 | hyperparams = hyperparams || []; 24 | estimator = ['AgglomerativeClustering'].concat(hyperparams); 25 | return sk.SKLearn(amodule, estimator, methods, cb); 26 | }; 27 | 28 | var DBSCAN = cluster.DBSCAN = function(methods, cb, hyperparams){ 29 | hyperparams = hyperparams || []; 30 | estimator = ['DBSCAN'].concat(hyperparams); 31 | return sk.SKLearn(amodule, estimator, methods, cb); 32 | }; 33 | 34 | var FeatureAgglomeration = cluster.FeatureAgglomeration = function(methods, cb, hyperparams){ 35 | hyperparams = hyperparams || []; 36 | estimator = ['FeatureAgglomeration'].concat(hyperparams); 37 | return sk.SKLearn(amodule, estimator, methods, cb); 38 | }; 39 | 40 | var KMeans = cluster.KMeans = function(methods, cb, hyperparams){ 41 | hyperparams = hyperparams || []; 42 | estimator = ['KMeans'].concat(hyperparams); 43 | return sk.SKLearn(amodule, estimator, methods, cb); 44 | }; 45 | 46 | var MiniBatchKMeans = cluster.MiniBatchKMeans = function(methods, cb, hyperparams){ 47 | hyperparams = hyperparams || []; 48 | estimator = ['MiniBatchKMeans'].concat(hyperparams); 49 | return sk.SKLearn(amodule, estimator, methods, cb); 50 | }; 51 | 52 | var MeanShift = cluster.MeanShift = function(methods, cb, hyperparams){ 53 | hyperparams = hyperparams || []; 54 | estimator = ['MeanShift'].concat(hyperparams); 55 | return sk.SKLearn(amodule, estimator, methods, cb); 56 | }; 57 | 58 | var SpectralClustering = cluster.SpectralClustering = function(methods, cb, hyperparams){ 59 | hyperparams = hyperparams || []; 60 | estimator = ['SpectralClustering'].concat(hyperparams); 61 | return sk.SKLearn(amodule, estimator, methods, cb); 62 | }; 63 | 64 | var Ward = cluster.Ward = function(methods, cb, hyperparams){ 65 | hyperparams = hyperparams || []; 66 | estimator = ['Ward'].concat(hyperparams); 67 | return sk.SKLearn(amodule, estimator, methods, cb); 68 | }; 69 | 70 | module.exports = cluster; 71 | -------------------------------------------------------------------------------- /modules/ensemble.js: -------------------------------------------------------------------------------- 1 | var sk = require('../learn'); 2 | var ensemble = {}; 3 | var amodule = 'ensemble'; 4 | var estimator; 5 | 6 | ensemble.ensembleAlgorithms = function(){ 7 | var estimators = {}; 8 | var key; 9 | for(key in ensemble){ 10 | estimators[key] = ensemble[key]; 11 | } 12 | delete estimators.ensembleAlgorithms; 13 | return estimators; 14 | }; 15 | 16 | var AdaBoostClassifier = ensemble.AdaBoostClassifier = function(methods, cb, hyperparams){ 17 | hyperparams = hyperparams || []; 18 | estimator = ['AdaBoostClassifier'].concat(hyperparams); 19 | return sk.SKLearn(amodule, estimator, methods, cb); 20 | }; 21 | 22 | var AdaBoostRegressor = ensemble.AdaBoostRegressor = function(methods, cb, hyperparams){ 23 | hyperparams = hyperparams || []; 24 | estimator = ['AdaBoostRegressor'].concat(hyperparams); 25 | return sk.SKLearn(amodule, estimator, methods, cb); 26 | }; 27 | 28 | var BaggingClassifier = ensemble.BaggingClassifier = function(methods, cb, hyperparams){ 29 | hyperparams = hyperparams || []; 30 | estimator = ['BaggingClassifier'].concat(hyperparams); 31 | return sk.SKLearn(amodule, estimator, methods, cb); 32 | }; 33 | 34 | var BaggingRegressor = ensemble.BaggingRegressor = function(methods, cb, hyperparams){ 35 | hyperparams = hyperparams || []; 36 | estimator = ['BaggingRegressor'].concat(hyperparams); 37 | return sk.SKLearn(amodule, estimator, methods, cb); 38 | }; 39 | 40 | var ExtraTreeRegressor = ensemble.ExtraTreeRegressor = function(methods, cb, hyperparams){ 41 | hyperparams = hyperparams || []; 42 | estimator = ['ExtraTreeRegressor'].concat(hyperparams); 43 | return sk.SKLearn(amodule, estimator, methods, cb); 44 | }; 45 | 46 | var GradientBoostingClassifier = ensemble.GradientBoostingClassifier = function(methods, cb, hyperparams){ 47 | hyperparams = hyperparams || []; 48 | estimator = ['GradientBoostingClassifier'].concat(hyperparams); 49 | return sk.SKLearn(amodule, estimator, methods, cb); 50 | }; 51 | 52 | var GradientBoostingRegressor = ensemble.GradientBoostingRegressor = function(methods, cb, hyperparams){ 53 | hyperparams = hyperparams || []; 54 | estimator = ['GradientBoostingRegressor'].concat(hyperparams); 55 | return sk.SKLearn(amodule, estimator, methods, cb); 56 | }; 57 | 58 | var RandomForestClassifier = ensemble.RandomForestClassifier = function(methods, cb, hyperparams){ 59 | hyperparams = hyperparams || []; 60 | estimator = ['RandomForestClassifier'].concat(hyperparams); 61 | return sk.SKLearn(amodule, estimator, methods, cb); 62 | }; 63 | 64 | var RandomTreesEmbedding = ensemble.RandomTreesEmbedding = function(methods, cb, hyperparams){ 65 | hyperparams = hyperparams || []; 66 | estimator = ['RandomTreesEmbedding'].concat(hyperparams); 67 | return sk.SKLearn(amodule, estimator, methods, cb); 68 | }; 69 | 70 | var RandomForestRegressor = ensemble.RandomForestRegressor = function(methods, cb, hyperparams){ 71 | hyperparams = hyperparams || []; 72 | estimator = ['RandomForestRegressor'].concat(hyperparams); 73 | return sk.SKLearn(amodule, estimator, methods, cb); 74 | }; 75 | 76 | module.exports = ensemble; 77 | -------------------------------------------------------------------------------- /modules/linear_model.js: -------------------------------------------------------------------------------- 1 | var sk = require('../learn'); 2 | var linear_model = {}; 3 | var amodule = 'linear_model'; 4 | var estimator; 5 | 6 | linear_model.linear_modelAlgorithms = function(){ 7 | var estimators = {}; 8 | var key; 9 | for(key in linear_model){ 10 | estimators[key] = linear_model[key]; 11 | } 12 | delete estimators.linear_modelAlgorithms; 13 | return estimators; 14 | }; 15 | 16 | var ARDRegression = linear_model.ARDRegression = function(methods, cb, hyperparams){ 17 | hyperparams = hyperparams || []; 18 | estimator = ['ARDRegression'].concat(hyperparams); 19 | return sk.SKLearn(amodule, estimator, methods, cb); 20 | }; 21 | 22 | var BayesianRidge = linear_model.BayesianRidge = function(methods, cb, hyperparams){ 23 | hyperparams = hyperparams || []; 24 | estimator = ['BayesianRidge'].concat(hyperparams); 25 | return sk.SKLearn(amodule, estimator, methods, cb); 26 | }; 27 | 28 | var ElasticNet = linear_model.ElasticNet = function(methods, cb, hyperparams){ 29 | hyperparams = hyperparams || []; 30 | estimator = ['ElasticNet'].concat(hyperparams); 31 | return sk.SKLearn(amodule, estimator, methods, cb); 32 | }; 33 | 34 | var ElasticNetCV = linear_model.ElasticNetCV = function(methods, cb, hyperparams){ 35 | hyperparams = hyperparams || []; 36 | estimator = ['ElasticNetCV'].concat(hyperparams); 37 | return sk.SKLearn(amodule, estimator, methods, cb); 38 | }; 39 | 40 | var Lars = linear_model.Lars = function(methods, cb, hyperparams){ 41 | hyperparams = hyperparams || []; 42 | estimator = ['Lars'].concat(hyperparams); 43 | return sk.SKLearn(amodule, estimator, methods, cb); 44 | }; 45 | 46 | var LarsCV = linear_model.LarsCV = function(methods, cb, hyperparams){ 47 | hyperparams = hyperparams || []; 48 | estimator = ['LarsCV'].concat(hyperparams); 49 | return sk.SKLearn(amodule, estimator, methods, cb); 50 | }; 51 | 52 | var Lasso = linear_model.Lasso = function(methods, cb, hyperparams){ 53 | hyperparams = hyperparams || []; 54 | estimator = ['Lasso'].concat(hyperparams); 55 | return sk.SKLearn(amodule, estimator, methods, cb); 56 | }; 57 | 58 | var LassoCV = linear_model.LassoCV = function(methods, cb, hyperparams){ 59 | hyperparams = hyperparams || []; 60 | estimator = ['LassoCV'].concat(hyperparams); 61 | return sk.SKLearn(amodule, estimator, methods, cb); 62 | }; 63 | 64 | var LassoLars = linear_model.LassoLars = function(methods, cb, hyperparams){ 65 | hyperparams = hyperparams || []; 66 | estimator = ['LassoLars'].concat(hyperparams); 67 | return sk.SKLearn(amodule, estimator, methods, cb); 68 | }; 69 | 70 | var LassoLarsCV = linear_model.LassoLarsCV = function(methods, cb, hyperparams){ 71 | hyperparams = hyperparams || []; 72 | estimator = ['LassoLarsCV'].concat(hyperparams); 73 | return sk.SKLearn(amodule, estimator, methods, cb); 74 | }; 75 | 76 | var LassoLarsIC = linear_model.LassoLarsIC = function(methods, cb, hyperparams){ 77 | hyperparams = hyperparams || []; 78 | estimator = ['LassoLarsIC'].concat(hyperparams); 79 | return sk.SKLearn(amodule, estimator, methods, cb); 80 | }; 81 | 82 | var LinearRegression = linear_model.LinearRegression = function(methods, cb, hyperparams){ 83 | hyperparams = hyperparams || []; 84 | estimator = ['LinearRegression'].concat(hyperparams); 85 | return sk.SKLearn(amodule, estimator, methods, cb); 86 | }; 87 | 88 | var LogisticRegression = linear_model.LogisticRegression = function(methods, cb, hyperparams){ 89 | hyperparams = hyperparams || []; 90 | estimator = ['LogisticRegression'].concat(hyperparams); 91 | return sk.SKLearn(amodule, estimator, methods, cb); 92 | }; 93 | 94 | var MultiTaskLasso = linear_model.MultiTaskLasso = function(methods, cb, hyperparams){ 95 | hyperparams = hyperparams || []; 96 | estimator = ['MultiTaskLasso'].concat(hyperparams); 97 | return sk.SKLearn(amodule, estimator, methods, cb); 98 | }; 99 | 100 | var MultiTaskElasticNet = linear_model.MultiTaskElasticNet = function(methods, cb, hyperparams){ 101 | hyperparams = hyperparams || []; 102 | estimator = ['MultiTaskElasticNet'].concat(hyperparams); 103 | return sk.SKLearn(amodule, estimator, methods, cb); 104 | }; 105 | 106 | var MultiTaskLassoCV = linear_model.MultiTaskLassoCV = function(methods, cb, hyperparams){ 107 | hyperparams = hyperparams || []; 108 | estimator = ['MultiTaskLassoCV'].concat(hyperparams); 109 | return sk.SKLearn(amodule, estimator, methods, cb); 110 | }; 111 | 112 | var MultiTaskElasticNetCV = linear_model.MultiTaskElasticNetCV = function(methods, cb, hyperparams){ 113 | hyperparams = hyperparams || []; 114 | estimator = ['MultiTaskElasticNetCV'].concat(hyperparams); 115 | return sk.SKLearn(amodule, estimator, methods, cb); 116 | }; 117 | 118 | var OrthogonalMatchingPursuit = linear_model.OrthogonalMatchingPursuit = function(methods, cb, hyperparams){ 119 | hyperparams = hyperparams || []; 120 | estimator = ['OrthogonalMatchingPursuit'].concat(hyperparams); 121 | return sk.SKLearn(amodule, estimator, methods, cb); 122 | }; 123 | 124 | var OrthogonalMatchingPursuitCV = linear_model.OrthogonalMatchingPursuitCV = function(methods, cb, hyperparams){ 125 | hyperparams = hyperparams || []; 126 | estimator = ['OrthogonalMatchingPursuitCV'].concat(hyperparams); 127 | return sk.SKLearn(amodule, estimator, methods, cb); 128 | }; 129 | 130 | var PassiveAggressiveClassifier = linear_model.PassiveAggressiveClassifier = function(methods, cb, hyperparams){ 131 | hyperparams = hyperparams || []; 132 | estimator = ['PassiveAggressiveClassifier'].concat(hyperparams); 133 | return sk.SKLearn(amodule, estimator, methods, cb); 134 | }; 135 | 136 | var PassiveAggressiveRegressor = linear_model.PassiveAggressiveRegressor = function(methods, cb, hyperparams){ 137 | hyperparams = hyperparams || []; 138 | estimator = ['PassiveAggressiveRegressor'].concat(hyperparams); 139 | return sk.SKLearn(amodule, estimator, methods, cb); 140 | }; 141 | 142 | var Perceptron = linear_model.Perceptron = function(methods, cb, hyperparams){ 143 | hyperparams = hyperparams || []; 144 | estimator = ['Perceptron'].concat(hyperparams); 145 | return sk.SKLearn(amodule, estimator, methods, cb); 146 | }; 147 | 148 | var RandomizedLasso = linear_model.RandomizedLasso = function(methods, cb, hyperparams){ 149 | hyperparams = hyperparams || []; 150 | estimator = ['RandomizedLasso'].concat(hyperparams); 151 | return sk.SKLearn(amodule, estimator, methods, cb); 152 | }; 153 | 154 | var RandomizedLogisticRegression = linear_model.RandomizedLogisticRegression = function(methods, cb, hyperparams){ 155 | hyperparams = hyperparams || []; 156 | estimator = ['RandomizedLogisticRegression'].concat(hyperparams); 157 | return sk.SKLearn(amodule, estimator, methods, cb); 158 | }; 159 | 160 | var Ridge = linear_model.Ridge = function(methods, cb, hyperparams){ 161 | hyperparams = hyperparams || []; 162 | estimator = ['Ridge'].concat(hyperparams); 163 | return sk.SKLearn(amodule, estimator, methods, cb); 164 | }; 165 | 166 | var RidgeClassifier = linear_model.RidgeClassifier = function(methods, cb, hyperparams){ 167 | hyperparams = hyperparams || []; 168 | estimator = ['RidgeClassifier'].concat(hyperparams); 169 | return sk.SKLearn(amodule, estimator, methods, cb); 170 | }; 171 | 172 | var RidgeClassifierCV = linear_model.RidgeClassifierCV = function(methods, cb, hyperparams){ 173 | hyperparams = hyperparams || []; 174 | estimator = ['RidgeClassifierCV'].concat(hyperparams); 175 | return sk.SKLearn(amodule, estimator, methods, cb); 176 | }; 177 | 178 | var RidgeCV = linear_model.RidgeCV = function(methods, cb, hyperparams){ 179 | hyperparams = hyperparams || []; 180 | estimator = ['RidgeCV'].concat(hyperparams); 181 | return sk.SKLearn(amodule, estimator, methods, cb); 182 | }; 183 | 184 | var SGDClassifier = linear_model.SGDClassifier = function(methods, cb, hyperparams){ 185 | hyperparams = hyperparams || []; 186 | estimator = ['SGDClassifier'].concat(hyperparams); 187 | return sk.SKLearn(amodule, estimator, methods, cb); 188 | }; 189 | 190 | var SGDRegressor = linear_model.SGDRegressor = function(methods, cb, hyperparams){ 191 | hyperparams = hyperparams || []; 192 | estimator = ['SGDRegressor'].concat(hyperparams); 193 | return sk.SKLearn(amodule, estimator, methods, cb); 194 | }; 195 | 196 | module.exports = linear_model; 197 | -------------------------------------------------------------------------------- /modules/neighbors.js: -------------------------------------------------------------------------------- 1 | var sk = require('../learn'); 2 | var neighbors = {}; 3 | var amodule = 'neighbors'; 4 | var estimator; 5 | 6 | neighbors.neighborsAlgorithms = function(){ 7 | var estimators = {}; 8 | var key; 9 | for(key in neighbors){ 10 | estimators[key] = neighbors[key]; 11 | } 12 | delete estimators.neighborsAlgorithms; 13 | return estimators; 14 | }; 15 | 16 | var NearestNeighbors = neighbors.NearestNeighbors = function(methods, cb, hyperparams){ 17 | hyperparams = hyperparams || []; 18 | estimator = ['NearestNeighbors'].concat(hyperparams); 19 | return sk.SKLearn(amodule, estimator, methods, cb); 20 | }; 21 | 22 | var KNeighborsClassifier = neighbors.KNeighborsClassifier = function(methods, cb, hyperparams){ 23 | hyperparams = hyperparams || []; 24 | estimator = ['KNeighborsClassifier'].concat(hyperparams); 25 | return sk.SKLearn(amodule, estimator, methods, cb); 26 | }; 27 | 28 | var RadiusNeighborsClassifier = neighbors.RadiusNeighborsClassifier = function(methods, cb, hyperparams){ 29 | hyperparams = hyperparams || []; 30 | estimator = ['RadiusNeighborsClassifier'].concat(hyperparams); 31 | return sk.SKLearn(amodule, estimator, methods, cb); 32 | }; 33 | 34 | var KNeighborsRegressor = neighbors.KNeighborsRegressor = function(methods, cb, hyperparams){ 35 | hyperparams = hyperparams || []; 36 | estimator = ['KNeighborsRegressor'].concat(hyperparams); 37 | return sk.SKLearn(amodule, estimator, methods, cb); 38 | }; 39 | 40 | var RadiusNeighborsRegressor = neighbors.RadiusNeighborsRegressor = function(methods, cb, hyperparams){ 41 | hyperparams = hyperparams || []; 42 | estimator = ['RadiusNeighborsRegressor'].concat(hyperparams); 43 | return sk.SKLearn(amodule, estimator, methods, cb); 44 | }; 45 | 46 | var NearestCentroid = neighbors.NearestCentroid = function(methods, cb, hyperparams){ 47 | hyperparams = hyperparams || []; 48 | estimator = ['NearestCentroid'].concat(hyperparams); 49 | return sk.SKLearn(amodule, estimator, methods, cb); 50 | }; 51 | 52 | var BallTree = neighbors.BallTree = function(methods, cb, hyperparams){ 53 | hyperparams = hyperparams || []; 54 | estimator = ['BallTree'].concat(hyperparams); 55 | return sk.SKLearn(amodule, estimator, methods, cb); 56 | }; 57 | 58 | var KDTree = neighbors.KDTree = function(methods, cb, hyperparams){ 59 | hyperparams = hyperparams || []; 60 | estimator = ['KDTree'].concat(hyperparams); 61 | return sk.SKLearn(amodule, estimator, methods, cb); 62 | }; 63 | 64 | var DistanceMetric = neighbors.DistanceMetric = function(methods, cb, hyperparams){ 65 | hyperparams = hyperparams || []; 66 | estimator = ['DistanceMetric'].concat(hyperparams); 67 | return sk.SKLearn(amodule, estimator, methods, cb); 68 | }; 69 | 70 | var KernelDensity = neighbors.KernelDensity = function(methods, cb, hyperparams){ 71 | hyperparams = hyperparams || []; 72 | estimator = ['KernelDensity'].concat(hyperparams); 73 | return sk.SKLearn(amodule, estimator, methods, cb); 74 | }; 75 | 76 | var kneighbors_graph = neighbors.kneighbors_graph = function(methods, cb, hyperparams){ 77 | hyperparams = hyperparams || []; 78 | estimator = ['kneighbors_graph'].concat(hyperparams); 79 | return sk.SKLearn(amodule, estimator, methods, cb); 80 | }; 81 | 82 | var radius_neighbors_graph = neighbors.radius_neighbors_graph = function(methods, cb, hyperparams){ 83 | hyperparams = hyperparams || []; 84 | estimator = ['radius_neighbors_graph'].concat(hyperparams); 85 | return sk.SKLearn(amodule, estimator, methods, cb); 86 | }; -------------------------------------------------------------------------------- /modules/preprocessing.js: -------------------------------------------------------------------------------- 1 | var sk = require('../learn'); 2 | var preprocessing = {}; 3 | var amodule = 'preprocessing'; 4 | var estimator; 5 | 6 | preprocessing.preprocessingAlgorithms = function(){ 7 | var estimators = {}; 8 | var key; 9 | for(key in preprocessing){ 10 | estimators[key] = preprocessing[key]; 11 | } 12 | delete estimators.preprocessingAlgorithms; 13 | return estimators; 14 | }; 15 | 16 | var Binarizer = preprocessing.Binarizer = function(methods, cb, hyperparams){ 17 | hyperparams = hyperparams || []; 18 | estimator = ['Binarizer'].concat(hyperparams); 19 | return sk.SKLearn(amodule, estimator, methods, cb); 20 | }; 21 | 22 | var Imputer = preprocessing.Imputer = function(methods, cb, hyperparams){ 23 | hyperparams = hyperparams || []; 24 | estimator = ['Imputer'].concat(hyperparams); 25 | return sk.SKLearn(amodule, estimator, methods, cb); 26 | }; 27 | 28 | var KernelCenterer = preprocessing.KernelCenterer = function(methods, cb, hyperparams){ 29 | hyperparams = hyperparams || []; 30 | estimator = ['KernelCenterer'].concat(hyperparams); 31 | return sk.SKLearn(amodule, estimator, methods, cb); 32 | }; 33 | 34 | var LabelBinarizer = preprocessing.LabelBinarizer = function(methods, cb, hyperparams){ 35 | hyperparams = hyperparams || []; 36 | estimator = ['LabelBinarizer'].concat(hyperparams); 37 | return sk.SKLearn(amodule, estimator, methods, cb); 38 | }; 39 | 40 | var LabelEncoder = preprocessing.LabelEncoder = function(methods, cb, hyperparams){ 41 | hyperparams = hyperparams || []; 42 | estimator = ['LabelEncoder'].concat(hyperparams); 43 | return sk.SKLearn(amodule, estimator, methods, cb); 44 | }; 45 | 46 | var MultiLabelBinarizer = preprocessing.MultiLabelBinarizer = function(methods, cb, hyperparams){ 47 | hyperparams = hyperparams || []; 48 | estimator = ['MultiLabelBinarizer'].concat(hyperparams); 49 | return sk.SKLearn(amodule, estimator, methods, cb); 50 | }; 51 | 52 | var MinMaxScaler = preprocessing.MinMaxScaler = function(methods, cb, hyperparams){ 53 | hyperparams = hyperparams || []; 54 | estimator = ['MinMaxScaler'].concat(hyperparams); 55 | return sk.SKLearn(amodule, estimator, methods, cb); 56 | }; 57 | 58 | var Normalizer = preprocessing.Normalizer = function(methods, cb, hyperparams){ 59 | hyperparams = hyperparams || []; 60 | estimator = ['Normalizer'].concat(hyperparams); 61 | return sk.SKLearn(amodule, estimator, methods, cb); 62 | }; 63 | 64 | var OneHotEncoder = preprocessing.OneHotEncoder = function(methods, cb, hyperparams){ 65 | hyperparams = hyperparams || []; 66 | estimator = ['OneHotEncoder'].concat(hyperparams); 67 | return sk.SKLearn(amodule, estimator, methods, cb); 68 | }; 69 | 70 | var StandardScaler = preprocessing.StandardScaler = function(methods, cb, hyperparams){ 71 | hyperparams = hyperparams || []; 72 | estimator = ['StandardScaler'].concat(hyperparams); 73 | return sk.SKLearn(amodule, estimator, methods, cb); 74 | }; 75 | 76 | var PolynomialFeatures = preprocessing.PolynomialFeatures = function(methods, cb, hyperparams){ 77 | hyperparams = hyperparams || []; 78 | estimator = ['PolynomialFeatures'].concat(hyperparams); 79 | return sk.SKLearn(amodule, estimator, methods, cb); 80 | }; 81 | 82 | module.exports = preprocessing; 83 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scikit-node", 3 | "version": "0.2.2", 4 | "description": "node wrapper for python's scikit-learn", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type":"git", 11 | "url": "https://github.com/lramsey/scikit-node.git" 12 | }, 13 | "keywords": [ 14 | "scikit-learn", 15 | "machine learning" 16 | ], 17 | "author": "Luke Ramsey", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/lramsey/scikit-node/issues", 21 | "email": "lramsey177@gmail.com" 22 | } 23 | } 24 | --------------------------------------------------------------------------------