nok/sklearn-porter
nok/sklearn-porter has 1,303 GitHub stars and 168 forks. GitHot measured 0 stars in 24 hours, -1 in 7 days, and -1 in 15 days. Last checked 2026-11-22 16:34 UTC. Last push 2026-11-19.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
학습된 scikit-learn 추정기와 변환기를 C, C#, Go, Java, JavaScript, PHP 및 Ruby로 트랜스파일합니다.
머신러닝README.md
Originalsklearn-porter
Transpile trained scikit-learn estimators and transformers
to C, C#, Go, Java, JavaScript, PHP and Ruby.
Installation • Quick Start • Examples • Support • Documentation • Contributing • Citation
Use the generated code to make predictions where Python isn't available or is too heavy, e.g. on embedded systems, in web browsers or in existing applications. The ported estimators make the same predictions as the original scikit-learn estimators, the ported transformers (e.g. for the preprocessing) transform the features like the original transformers.
Installation
uv add sklearn-porter
pip install sklearn-porter
Python 3.11 or newer and scikit-learn 1.8 or newer are required.
Quick Start
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn_porter import make, save, test
# Train a classifier:
X, y = load_iris(return_X_y=True)
clf = DecisionTreeClassifier(max_depth=2, random_state=0).fit(X, y)
# Save it to JavaScript files (the code and the model data):
src_path, json_path = save(clf, language='js', template='exported', directory='/tmp')
# Make predictions with the ported classifier (with Node.js):
y_pred, y_proba = make(clf, X[:3], language='js')
print(y_pred) # [0 0 0]
# Check that all predictions match those of scikit-learn:
print(test(clf, X, language='js')) # 1.0
Run the saved classifier with the model data and the features of a sample:
$ node /tmp/DecisionTreeClassifier.js /tmp/DecisionTreeClassifier.json 6.3 3.3 6.0 2.5
Predicted class: 2
Probability of class #0 : 0
Probability of class #1 : 0.021739130434782608
Probability of class #2 : 0.9782608695652174
make() and test() need the compiler or interpreter of the language (see languages).
Examples
- ✨ Getting Started: port a classifier, make predictions and measure the accuracy.
- Transformers: port transformers (e.g. a
StandardScaler) and use the ported transformers. - Pipelines: port a
Pipelineof transformers and a final estimator to one source file. - CLI: port a saved classifier with the command
porter, save the source code to files and run it.
Support
Estimators
Classifiers (21)
- ensemble.AdaBoostClassifier
- ensemble.ExtraTreesClassifier
- ensemble.GradientBoostingClassifier
- ensemble.HistGradientBoostingClassifier
- ensemble.RandomForestClassifier
- linear_model.LogisticRegression
- linear_model.LogisticRegressionCV
- linear_model.Perceptron
- linear_model.RidgeClassifier
- linear_model.RidgeClassifierCV
- linear_model.SGDClassifier ²
- naive_bayes.BernoulliNB ¹
- naive_bayes.ComplementNB ¹
- naive_bayes.GaussianNB ¹
- naive_bayes.MultinomialNB ¹
- neighbors.KNeighborsClassifier ¹
- neural_network.MLPClassifier ¹
- svm.LinearSVC ¹
- svm.NuSVC ¹ ²
- svm.SVC ¹ ²
- tree.DecisionTreeClassifier
Regressors (21)
- ensemble.ExtraTreesRegressor
- ensemble.GradientBoostingRegressor
- ensemble.HistGradientBoostingRegressor
- ensemble.RandomForestRegressor
- linear_model.ARDRegression
- linear_model.BayesianRidge
- linear_model.ElasticNet
- linear_model.ElasticNetCV
- linear_model.HuberRegressor
- linear_model.Lasso
- linear_model.LassoCV
- linear_model.LinearRegression
- linear_model.Ridge
- linear_model.RidgeCV
- linear_model.SGDRegressor
- neighbors.KNeighborsRegressor ¹
- neural_network.MLPRegressor ¹
- svm.LinearSVR
- svm.NuSVR ¹
- svm.SVR ¹
- tree.DecisionTreeRegressor
Outlier detectors (2)
Transformers
Composition (2)
Feature extraction (4)
Feature selection (11)
- feature_selection.GenericUnivariateSelect
- feature_selection.RFE
- feature_selection.RFECV
- feature_selection.SelectFdr
- feature_selection.SelectFpr
- feature_selection.SelectFromModel
- feature_selection.SelectFwe
- feature_selection.SelectKBest
- feature_selection.SelectPercentile
- feature_selection.SequentialFeatureSelector
- feature_selection.VarianceThreshold
Preprocessing (15)
- impute.SimpleImputer
- preprocessing.Binarizer
- preprocessing.FunctionTransformer
- preprocessing.KBinsDiscretizer
- preprocessing.MaxAbsScaler
- preprocessing.MinMaxScaler
- preprocessing.Normalizer
- preprocessing.OneHotEncoder
- preprocessing.OrdinalEncoder
- preprocessing.PolynomialFeatures
- preprocessing.PowerTransformer
- preprocessing.QuantileTransformer
- preprocessing.RobustScaler
- preprocessing.StandardScaler
- preprocessing.TargetEncoder
¹ without the template combined, ² without predict_proba (even if scikit-learn provides it, e.g. SVC(probability=True)). All other estimators support all languages and templates, the classifiers also predict_proba (if scikit-learn provides it). porter show lists all supported combinations.
Languages
| Language | Key | make() and test() need |
Tested with |
|---|---|---|---|
| C | c |
gcc |
GCC 14 |
| C# | cs |
dotnet (.NET SDK 8+) |
.NET SDK 10 |
| Go | go |
go |
Go 1.27 |
| Java | java |
javac and java |
OpenJDK 21, Gson 2.15 |
| JavaScript | js |
node |
Node.js 24 |
| PHP | php |
php |
PHP 8.4 |
| Ruby | ruby |
ruby |
Ruby 3.3 |
The key selects the language, e.g. port(clf, language='cs').
Templates
The template defines how the model data is stored in the generated code:
attached: The model data is embedded in the source code, e.g. as arrays.exported: The model data is saved in a separate JSON file, which the source code reads at runtime.combined: The model data is compiled into the logic of the source code, e.g. as nested if-else statements.
The template is selected like the language, e.g. port(clf, template='exported').
Documentation
Read these pages before you use a ported estimator in production:
- Estimator notes: How each estimator and transformer is ported and which parameters can lead to different predictions.
- Limitations: The known limitations, e.g. of pipelines, large Java methods, C#, sparse data and Windows.
- Changelog: All changes of each version.
Contributing
Contributions are welcome! See CONTRIBUTING.md for the development setup, the tests and the release process.
Citation
If you use sklearn-porter in your work, please cite it. GitHub shows the citation of the citation file (with the version) under "Cite this repository", or use this BibTeX entry:
@software{sklearn_porter,
author = {Darius Morawiec},
title = {sklearn-porter},
note = {Transpile trained scikit-learn estimators and transformers to C, C#, Go, Java, JavaScript, PHP and Ruby},
url = {https://github.com/nok/sklearn-porter}
}
License
sklearn-porter is open source software released under the BSD 3-Clause license.
관련 프로젝트 살펴보기
불러오는 중…