@kobra-dev/js-regression
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -24,2 +24,7 @@ export declare class LogisticRegression { | ||
cost(X: any, Y: any, theta: any): number; | ||
save(): { | ||
theta: any[]; | ||
dim: any; | ||
}; | ||
loadAndPredict(json: any, X: any): number | any[]; | ||
} | ||
@@ -26,0 +31,0 @@ export declare class MultiClassLogistic { |
@@ -160,2 +160,15 @@ 'use strict'; | ||
_proto.save = function save() { | ||
return { | ||
theta: this.theta, | ||
dim: this.dim | ||
}; | ||
}; | ||
_proto.loadAndPredict = function loadAndPredict(json, X) { | ||
this.theta = json.theta; | ||
this.dim = json.dim; | ||
return this.transform(X); | ||
}; | ||
return LogisticRegression; | ||
@@ -162,0 +175,0 @@ }(); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){function t(t){this.theta=[],(t=t||{}).alpha||(t.alpha=.001),t.iterations||(t.iterations=100),t.lambda||(t.lambda=0),this.alpha=t.alpha,this.lambda=t.lambda,this.iterations=t.iterations}var s=t.prototype;return s.fit=function(t){this.dim=t[0].length;for(var s=t.length,a=[],h=[],i=0;i<s;++i){var r=t[i],e=[],o=r[r.length-1];e.push(1);for(var n=0;n<r.length-1;++n)e.push(r[n]);a.push(e),h.push(o)}this.theta=[];for(var l=0;l<this.dim;++l)this.theta.push(0);for(var f=0;f<this.iterations;++f){var u=this.grad(a,h,this.theta);for(l=0;l<this.dim;++l)this.theta[l]=this.theta[l]-this.alpha*u[l]}return this.threshold=this.computeThreshold(a,h),{theta:this.theta,threshold:this.threshold,cost:this.cost(a,h,this.theta),config:{alpha:this.alpha,lambda:this.lambda,iterations:this.iterations}}},s.computeThreshold=function(t,s){for(var a=1,h=t.length,i=0;i<h;++i){var r=this.transform(t[i]);1==s[i]&&a>r&&(a=r)}return a},s.grad=function(t,s,a){for(var h=t.length,i=[],r=0;r<this.dim;++r){for(var e=0,o=0;o<h;++o){var n=t[o];e+=((this.h(n,a)-s[o])*n[r]+this.lambda*a[r])/h}i.push(e)}return i},s.h=function(t,s){for(var a=0,h=0;h<this.dim;++h)a+=s[h]*t[h];return 1/(1+Math.exp(-a))},s.transform=function(t){if(t[0].length){for(var s=[],a=0;a<t.length;++a){var h=this.transform(t[a]);s.push(h)}return s}var i=[];i.push(1);for(var r=0;r<t.length;++r)i.push(t[r]);return this.h(i,this.theta)},s.cost=function(t,s,a){for(var h=t.length,i=0,r=0;r<h;++r){var e=s[r],o=t[r];i+=-(e*Math.log(this.h(o,a))+(1-e)*Math.log(1-this.h(o,a)))/h}for(var n=0;n<this.dim;++n)i+=this.lambda*a[n]*a[n]/(2*h);return i},t}(),s=function(){function s(t){(t=t||{}).alpha||(t.alpha=.001),t.iterations||(t.iterations=100),t.lambda||(t.lambda=0),this.alpha=t.alpha,this.lambda=t.lambda,this.iterations=t.iterations}var a=s.prototype;return a.fit=function(s,a){this.dim=s[0].length;var h=s.length;if(!a){a=[];for(var i=0;i<h;++i){for(var r=!1,e=s[i][this.dim-1],o=0;o<a.length;++o)if(e==a[o]){r=!0;break}r||a.push(e)}}this.classes=a,this.logistics={};for(var n={},l=0;l<this.classes.length;++l){var f=this.classes[l];this.logistics[f]=new t({alpha:this.alpha,lambda:this.lambda,iterations:this.iterations});var u=[];for(i=0;i<h;++i){var p=[];for(o=0;o<this.dim-1;++o)p.push(s[i][o]);p.push(s[i][this.dim-1]==f?1:0),u.push(p)}n[f]=this.logistics[f].fit(u)}return n},a.transform=function(t){if(t[0].length){for(var s=[],a=0;a<t.length;++a){var h=this.transform(t[a]);s.push(h)}return s}for(var i=0,r="",e=0;e<this.classes.length;++e){var o=this.classes[e],n=this.logistics[o].transform(t);i<n&&(i=n,r=o)}return r},s}();exports.LogisticRegression=t,exports.MultiClassLogistic=s; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){function t(t){this.theta=[],(t=t||{}).alpha||(t.alpha=.001),t.iterations||(t.iterations=100),t.lambda||(t.lambda=0),this.alpha=t.alpha,this.lambda=t.lambda,this.iterations=t.iterations}var i=t.prototype;return i.fit=function(t){this.dim=t[0].length;for(var i=t.length,s=[],h=[],a=0;a<i;++a){var r=t[a],e=[],n=r[r.length-1];e.push(1);for(var o=0;o<r.length-1;++o)e.push(r[o]);s.push(e),h.push(n)}this.theta=[];for(var l=0;l<this.dim;++l)this.theta.push(0);for(var f=0;f<this.iterations;++f){var u=this.grad(s,h,this.theta);for(l=0;l<this.dim;++l)this.theta[l]=this.theta[l]-this.alpha*u[l]}return this.threshold=this.computeThreshold(s,h),{theta:this.theta,threshold:this.threshold,cost:this.cost(s,h,this.theta),config:{alpha:this.alpha,lambda:this.lambda,iterations:this.iterations}}},i.computeThreshold=function(t,i){for(var s=1,h=t.length,a=0;a<h;++a){var r=this.transform(t[a]);1==i[a]&&s>r&&(s=r)}return s},i.grad=function(t,i,s){for(var h=t.length,a=[],r=0;r<this.dim;++r){for(var e=0,n=0;n<h;++n){var o=t[n];e+=((this.h(o,s)-i[n])*o[r]+this.lambda*s[r])/h}a.push(e)}return a},i.h=function(t,i){for(var s=0,h=0;h<this.dim;++h)s+=i[h]*t[h];return 1/(1+Math.exp(-s))},i.transform=function(t){if(t[0].length){for(var i=[],s=0;s<t.length;++s){var h=this.transform(t[s]);i.push(h)}return i}var a=[];a.push(1);for(var r=0;r<t.length;++r)a.push(t[r]);return this.h(a,this.theta)},i.cost=function(t,i,s){for(var h=t.length,a=0,r=0;r<h;++r){var e=i[r],n=t[r];a+=-(e*Math.log(this.h(n,s))+(1-e)*Math.log(1-this.h(n,s)))/h}for(var o=0;o<this.dim;++o)a+=this.lambda*s[o]*s[o]/(2*h);return a},i.save=function(){return{theta:this.theta,dim:this.dim}},i.loadAndPredict=function(t,i){return this.theta=t.theta,this.dim=t.dim,this.transform(i)},t}(),i=function(){function i(t){(t=t||{}).alpha||(t.alpha=.001),t.iterations||(t.iterations=100),t.lambda||(t.lambda=0),this.alpha=t.alpha,this.lambda=t.lambda,this.iterations=t.iterations}var s=i.prototype;return s.fit=function(i,s){this.dim=i[0].length;var h=i.length;if(!s){s=[];for(var a=0;a<h;++a){for(var r=!1,e=i[a][this.dim-1],n=0;n<s.length;++n)if(e==s[n]){r=!0;break}r||s.push(e)}}this.classes=s,this.logistics={};for(var o={},l=0;l<this.classes.length;++l){var f=this.classes[l];this.logistics[f]=new t({alpha:this.alpha,lambda:this.lambda,iterations:this.iterations});var u=[];for(a=0;a<h;++a){var d=[];for(n=0;n<this.dim-1;++n)d.push(i[a][n]);d.push(i[a][this.dim-1]==f?1:0),u.push(d)}o[f]=this.logistics[f].fit(u)}return o},s.transform=function(t){if(t[0].length){for(var i=[],s=0;s<t.length;++s){var h=this.transform(t[s]);i.push(h)}return i}for(var a=0,r="",e=0;e<this.classes.length;++e){var n=this.classes[e],o=this.logistics[n].transform(t);a<o&&(a=o,r=n)}return r},i}();exports.LogisticRegression=t,exports.MultiClassLogistic=i; | ||
//# sourceMappingURL=js-regression.cjs.production.min.js.map |
@@ -156,2 +156,15 @@ var LogisticRegression = /*#__PURE__*/function () { | ||
_proto.save = function save() { | ||
return { | ||
theta: this.theta, | ||
dim: this.dim | ||
}; | ||
}; | ||
_proto.loadAndPredict = function loadAndPredict(json, X) { | ||
this.theta = json.theta; | ||
this.dim = json.dim; | ||
return this.transform(X); | ||
}; | ||
return LogisticRegression; | ||
@@ -158,0 +171,0 @@ }(); |
130
package.json
{ | ||
"version": "1.0.11", | ||
"description": "Package implements linear regression and logistic regression", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kobra-dev/js-regression.git" | ||
}, | ||
"keywords": [ | ||
"linear regression", | ||
"logistic regression", | ||
"polynomial regression", | ||
"multiple linear regression", | ||
"classification", | ||
"binary classification", | ||
"multi-class classification", | ||
"prediction", | ||
"linear models", | ||
"least squares", | ||
"gradient descent", | ||
"regression" | ||
], | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why" | ||
}, | ||
"peerDependencies": {}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
"version": "1.0.12", | ||
"description": "Package implements linear regression and logistic regression", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kobra-dev/js-regression.git" | ||
}, | ||
"keywords": [ | ||
"linear regression", | ||
"logistic regression", | ||
"polynomial regression", | ||
"multiple linear regression", | ||
"classification", | ||
"binary classification", | ||
"multi-class classification", | ||
"prediction", | ||
"linear models", | ||
"least squares", | ||
"gradient descent", | ||
"regression" | ||
], | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why" | ||
}, | ||
"peerDependencies": {}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"tabWidth": 4 | ||
}, | ||
"name": "@kobra-dev/js-regression", | ||
"author": "Kobra, Xianshun Chen", | ||
"contributors": [ | ||
"Xianshun Chen <xs0040@gmail.com>", | ||
"The Kobra Authors <team@kobra.dev>" | ||
], | ||
"module": "dist/js-regression.esm.js", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.12.0", | ||
"husky": "^6.0.0", | ||
"js-datasets-iris": "^1.0.4", | ||
"size-limit": "^4.12.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.0", | ||
"typescript": "^4.3.4" | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"tabWidth": 4 | ||
}, | ||
"name": "@kobra-dev/js-regression", | ||
"author": "Kobra, Xianshun Chen", | ||
"contributors": [ | ||
"Xianshun Chen <xs0040@gmail.com>", | ||
"The Kobra Authors <team@kobra.dev>" | ||
], | ||
"module": "dist/js-regression.esm.js", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.12.0", | ||
"husky": "^6.0.0", | ||
"js-datasets-iris": "^1.0.4", | ||
"size-limit": "^4.12.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.0", | ||
"typescript": "^4.3.4" | ||
} | ||
} |
@@ -64,4 +64,4 @@ export class LogisticRegression { | ||
lambda: this.lambda, | ||
iterations: this.iterations | ||
} | ||
iterations: this.iterations, | ||
}, | ||
}; | ||
@@ -146,2 +146,16 @@ } | ||
} | ||
save() { | ||
return { | ||
theta: this.theta, | ||
dim: this.dim, | ||
}; | ||
} | ||
loadAndPredict(json: any, X: any) { | ||
this.theta = json.theta; | ||
this.dim = json.dim; | ||
return this.transform(X); | ||
} | ||
} | ||
@@ -203,3 +217,3 @@ | ||
lambda: this.lambda, | ||
iterations: this.iterations | ||
iterations: this.iterations, | ||
}); | ||
@@ -206,0 +220,0 @@ var data_c = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72619
720
1