nok/sklearn-porter has 1,304 GitHub stars and 168 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-16 03:55 UTC. Last push 2026-11-14.
計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 履歴を収集中
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
概要
Transpile trained scikit-learn estimators and transformers to C, C#, Go, Java, JavaScript, PHP and Ruby.
機械学習README.md
オリジナルsklearn-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.