-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure model data and algorithm handling
- Loading branch information
Showing
9 changed files
with
198 additions
and
154 deletions.
There are no files selected for viewing
79 changes: 49 additions & 30 deletions
79
examples/estimator/classifier/KNeighborsClassifier/java/basics.py
Large diffs are not rendered by default.
Oops, something went wrong.
88 changes: 46 additions & 42 deletions
88
examples/estimator/classifier/KNeighborsClassifier/js/basics.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 9 additions & 21 deletions
30
sklearn_porter/estimator/classifier/KNeighborsClassifier/templates/java/method.predict.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sklearn_porter/estimator/classifier/KNeighborsClassifier/templates/java/metric.minkowski.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 24 additions & 10 deletions
34
sklearn_porter/estimator/classifier/KNeighborsClassifier/templates/js/class.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
// Array.prototype.fill polyfill: | ||
[].fill||(Array.prototype.fill=function(a){{for(var b=Object(this),c=parseInt(b.length,10),d=arguments[1],e=parseInt(d,10)||0,f=0>e?Math.max(c+e,0):Math.min(e,c),g=arguments[2],h=void 0===g?c:parseInt(g)||0,i=0>h?Math.max(c+h,0):Math.min(h,c);i>f;f++)b[f]=a;return b}}); | ||
var {class_name} = function(nNeighbors, nTemplates, nClasses, power, X, y) {{ | ||
|
||
var Neighbor = function(clazz, dist) {{ | ||
this.clazz = clazz; | ||
this.dist = dist; | ||
}}; | ||
this.nNeighbors = nNeighbors; | ||
this.nTemplates = nTemplates; | ||
this.nClasses = nClasses; | ||
this.power = power; | ||
this.X = X; | ||
this.y = y; | ||
|
||
var {class_name} = function() {{ | ||
var Neighbor = function(clazz, dist) {{ | ||
this.clazz = clazz; | ||
this.dist = dist; | ||
}}; | ||
|
||
{method} | ||
|
||
}}; | ||
|
||
if (typeof process !== 'undefined' && typeof process.argv !== 'undefined') {{ | ||
if (process.argv.length - 2 == {n_features}) {{ | ||
var argv = process.argv.slice(2); | ||
var prediction = new {class_name}().{method_name}(argv); | ||
if (process.argv.length - 2 === {n_features}) {{ | ||
|
||
// Features: | ||
var features = process.argv.slice(2); | ||
|
||
// Parameters: | ||
{X} | ||
{y} | ||
|
||
// Estimator: | ||
var clf = new {class_name}({n_neighbors}, {n_templates}, {n_classes}, {power}, X, y); | ||
var prediction = clf.{method_name}(features); | ||
console.log(prediction); | ||
|
||
}} | ||
}} |
36 changes: 11 additions & 25 deletions
36
sklearn_porter/estimator/classifier/KNeighborsClassifier/templates/js/method.predict.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sklearn_porter/estimator/classifier/KNeighborsClassifier/templates/js/metric.minkowski.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters