Package: ml2json
ml2jsonExport scikit-learn model files to JSON for sharing or deploying predictive models with peace of mind.This is the continuation of the work hosted atOlivierBeq/sklearn-json.Why ml2json?Other methods for exporting scikit-learn models require Pickle or Joblib (based on Pickle).Serializing model files with Pickle provides a simple attack vector for malicious users - they give an attacker the ability to execute arbitrary code wherever the file is deserialized. For an example see:https://www.smartfile.com/blog/python-pickle-security-problems-and-solutions/.Internal designs of Pickle and Joblib files make the binary files not mandatorily supported across Python versions.ml2json is a safe and transparent solution for exporting scikit-learn model files to text files both machine and human readable.SafeExport model files to 100% JSON which cannot execute code on deserialization.TransparentModel files are serialized in JSON (i.e., not binary), so you have the ability to see exactly what's inside.Getting Startedml2json makes exporting model files to JSON simple.Installpip install ml2jsonTo install other all dependencies (e.g. XGBoost, HDBSCAN), use:pip install ml2json[full]Example Usageimportml2jsonfromsklearn.ensembleimportRandomForestClassifiermodel=RandomForestClassifier(n_estimators=10,max_depth=5,random_state=0).fit(X,y)ml2json.to_json(model,file_name)deserialized_model=ml2json.from_json(file_name)deserialized_model.predict(X)FeaturesThe list of supported models is rapidly growing.
In addition of the support for scikit-learn models, ml2json supports the following libraries:scikit-learn-extraXGBoostLightGBMCatBoostImbalanced-learnkmodesHDBSCANUMAPPyNNDescentPrinceMlChemADml2json requires scikit-learn >= 1.2.2, <=1.4.0.Supported scikit-learn ModelsLibraryCategoryClassSupported?Scikit-LearnClusteringcluster.AffinityPropagation:heavy_check_mark:Scikit-LearnClusteringcluster.AgglomerativeClustering:heavy_check_mark:Scikit-LearnClusteringcluster.Birch:heavy_check_mark:Scikit-LearnClusteringcluster.DBSCAN:heavy_check_mark:Scikit-LearnClusteringcluster.FeatureAgglomeration:heavy_check_mark:Scikit-LearnClusteringcluster.KMeans:heavy_check_mark:Scikit-LearnClusteringcluster.BisectingKMeans:heavy_check_mark:Scikit-LearnClusteringcluster.MiniBatchKMeans:heavy_check_mark:Scikit-LearnClusteringcluster.MeanShift:heavy_check_mark:Scikit-LearnClusteringcluster.OPTICS:heavy_check_mark:Scikit-LearnClusteringcluster.SpectralClustering:heavy_check_mark:Scikit-LearnClusteringcluster.SpectralBiclustering:heavy_check_mark:Scikit-LearnClusteringcluster.SpectralCoclustering:heavy_check_mark:Scikit-LearnCross decompositioncross_decomposition.CCA:heavy_check_mark:Scikit-LearnCross decompositioncross_decomposition.PLSCanonical:heavy_check_mark:Scikit-LearnCross decompositioncross_decomposition.PLSRegression:heavy_check_mark:Scikit-LearnCross decompositioncross_decomposition.PLSSVD:heavy_check_mark:Scikit-LearnDecompositiondecomposition.DictionaryLearning:heavy_check_mark:Scikit-LearnDecompositiondecomposition.FactorAnalysis:heavy_check_mark:Scikit-LearnDecompositiondecomposition.FastICA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.IncrementalPCA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.KernelPCA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.LatentDirichletAllocation:heavy_check_mark:Scikit-LearnDecompositiondecomposition.MiniBatchDictionaryLearning:heavy_check_mark:Scikit-LearnDecompositiondecomposition.MiniBatchSparsePCA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.NMF:heavy_check_mark:Scikit-LearnDecompositiondecomposition.MiniBatchNMF:heavy_check_mark:Scikit-LearnDecompositiondecomposition.PCA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.SparsePCA:heavy_check_mark:Scikit-LearnDecompositiondecomposition.SparseCoder:heavy_check_mark:Scikit-LearnDecompositiondecomposition.TruncatedSVD:heavy_check_mark:Scikit-LearnDiscriminant Analysisdiscriminant_analysis.LinearDiscriminantAnalysis:heavy_check_mark:Scikit-LearnDiscriminant Analysisdiscriminant_analysis.QuadraticDiscriminantAnalysis:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.AdaBoostClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.AdaBoostRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.BaggingClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.BaggingRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.ExtraTreesClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.ExtraTreesRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.GradientBoostingClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.GradientBoostingRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.IsolationForest:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.RandomForestClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.RandomForestRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.RandomTreesEmbedding:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.StackingClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.StackingRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.VotingClassifier:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.VotingRegressor:heavy_check_mark:Scikit-LearnEnsemble Methodsensemble.HistGradientBoostingRegressor:x:Scikit-LearnEnsemble Methodsensemble.HistGradientBoostingClassifier:x:Scikit-LearnFeature Extractionfeature_extraction.DictVectorizer:heavy_check_mark:Scikit-LearnFeature Extractionfeature_extraction.FeatureHasher:x:Scikit-LearnFeature Extractionfeature_extraction.image.PatchExtractor:x:Scikit-LearnFeature Extractionfeature_extraction.text.CountVectorizer:x:Scikit-LearnFeature Extractionfeature_extraction.text.HashingVectorizer:x:Scikit-LearnFeature Extractionfeature_extraction.text.TfidfTransformer:x:Scikit-LearnFeature Extractionfeature_extraction.text.TfidfVectorizer:x:Scikit-LearnFeature Selectionfeature_selection.GenericUnivariateSelect:x:Scikit-LearnFeature Selectionfeature_selection.SelectPercentile:x:Scikit-LearnFeature Selectionfeature_selection.SelectKBest:x:Scikit-LearnFeature Selectionfeature_selection.SelectFpr:x:Scikit-LearnFeature Selectionfeature_selection.SelectFdr:x:Scikit-LearnFeature Selectionfeature_selection.SelectFromModel:x:Scikit-LearnFeature Selectionfeature_selection.SelectFwe:x:Scikit-LearnFeature Selectionfeature_selection.SequentialFeatureSelector:x:Scikit-LearnFeature Selectionfeature_selection.RFE:x:Scikit-LearnFeature Selectionfeature_selection.RFECV:x:Scikit-LearnFeature Selectionfeature_selection.VarianceThreshold:x:Scikit-LearnGaussian Processesgaussian_process.GaussianProcessClassifier:x:Scikit-LearnGaussian Processesgaussian_process.GaussianProcessRegressor:x:Scikit-LearnImputeimpute.SimpleImputer:x:Scikit-LearnImputeimpute.IterativeImputer:x:Scikit-LearnImputeimpute.MissingIndicator:x:Scikit-LearnImputeimpute.KNNImputer:x:Scikit-LearnIsotonic regressionisotonic.IsotonicRegression:x:Scikit-LearnKernel Approximationkernel_approximation.AdditiveChi2Sampler:x:Scikit-LearnKernel Approximationkernel_approximation.Nystroem:x:Scikit-LearnKernel Approximationkernel_approximation.PolynomialCountSketch:x:Scikit-LearnKernel Approximationkernel_approximation.RBFSampler:x:Scikit-LearnKernel Approximationkernel_approximation.SkewedChi2Sampler:x:Scikit-LearnKernel Ridge Regressionkernel_ridge.KernelRidge:x:Scikit-LearnLinear Modelslinear_model.LogisticRegression:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.LogisticRegressionCV:x:Scikit-LearnLinear Modelslinear_model.PassiveAggressiveClassifier:x:Scikit-LearnLinear Modelslinear_model.Perceptron:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.RidgeClassifier:x:Scikit-LearnLinear Modelslinear_model.RidgeClassifierCV:x:Scikit-LearnLinear Modelslinear_model.SGDClassifier:x:Scikit-LearnLinear Modelslinear_model.SGDOneClassSVM:x:Scikit-LearnLinear Modelslinear_model.LinearRegression:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.Ridge:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.RidgeCV:x:Scikit-LearnLinear Modelslinear_model.SGDRegressor:x:Scikit-LearnLinear Modelslinear_model.ElasticNet:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.ElasticNetCV:x:Scikit-LearnLinear Modelslinear_model.Lars:x:Scikit-LearnLinear Modelslinear_model.LarsCV:x:Scikit-LearnLinear Modelslinear_model.Lasso:heavy_check_mark:Scikit-LearnLinear Modelslinear_model.LassoCV:x:Scikit-LearnLinear Modelslinear_model.LassoLars:x:Scikit-LearnLinear Modelslinear_model.LassoLarsCV:x:Scikit-LearnLinear Modelslinear_model.LassoLarsIC:x:Scikit-LearnLinear Modelslinear_model.OrthogonalMatchingPursuit:x:Scikit-LearnLinear Modelslinear_model.OrthogonalMatchingPursuitCV:x:Scikit-LearnLinear Modelslinear_model.ARDRegression:x:Scikit-LearnLinear Modelslinear_model.BayesianRidge:x:Scikit-LearnLinear Modelslinear_model.MultiTaskElasticNet:x:Scikit-LearnLinear Modelslinear_model.MultiTaskElasticNetCV:x:Scikit-LearnLinear Modelslinear_model.MultiTaskLasso:x:Scikit-LearnLinear Modelslinear_model.MultiTaskLassoCV:x:Scikit-LearnLinear Modelslinear_model.HuberRegressor:x:Scikit-LearnLinear Modelslinear_model.QuantileRegressor:x:Scikit-LearnLinear Modelslinear_model.RANSACRegressor:x:Scikit-LearnLinear Modelslinear_model.TheilSenRegressor:x:Scikit-LearnLinear Modelslinear_model.PoissonRegressor:x:Scikit-LearnLinear Modelslinear_model.TweedieRegressor:x:Scikit-LearnLinear Modelslinear_model.GammaRegressor:x:Scikit-LearnLinear Modelslinear_model.PassiveAggressiveRegressor:x:Scikit-LearnManifold Learningmanifold.Isomap:heavy_check_mark:Scikit-LearnManifold Learningmanifold.LocallyLinearEmbedding:heavy_check_mark:Scikit-LearnManifold Learningmanifold.MDS:heavy_check_mark:Scikit-LearnManifold Learningmanifold.SpectralEmbedding:heavy_check_mark:Scikit-LearnManifold Learningmanifold.TSNE:heavy_check_mark:Scikit-LearnGaussian Mixture Modelsmixture.BayesianGaussianMixture:x:Scikit-LearnGaussian Mixture Modelsmixture.GaussianMixture:x:Scikit-LearnModel Selectionmodel_selection.GroupKFold:x:Scikit-LearnModel Selectionmodel_selection.GroupShuffleSplit:x:Scikit-LearnModel Selectionmodel_selection.KFold:x:Scikit-LearnModel Selectionmodel_selection.LeaveOneGroupOut:x:Scikit-LearnModel Selectionmodel_selection.LeavePGroupsOut:x:Scikit-LearnModel Selectionmodel_selection.LeaveOneOut:x:Scikit-LearnModel Selectionmodel_selection.LeavePOut:x:Scikit-LearnModel Selectionmodel_selection.PredefinedSplit:x:Scikit-LearnModel Selectionmodel_selection.RepeatedKFold:x:Scikit-LearnModel Selectionmodel_selection.RepeatedStratifiedKFold:x:Scikit-LearnModel Selectionmodel_selection.ShuffleSplit:x:Scikit-LearnModel Selectionmodel_selection.StratifiedKFold:x:Scikit-LearnModel Selectionmodel_selection.StratifiedShuffleSplit:x:Scikit-LearnModel Selectionmodel_selection.StratifiedGroupKFold:x:Scikit-LearnModel Selectionmodel_selection.TimeSeriesSplit:x:Scikit-LearnModel Selectionmodel_selection.GridSearchCV:x:Scikit-LearnModel Selectionmodel_selection.HalvingGridSearchCV:x:Scikit-LearnModel Selectionmodel_selection.ParameterGrid:x:Scikit-LearnModel Selectionmodel_selection.ParameterSampler:x:Scikit-LearnModel Selectionmodel_selection.RandomizedSearchCV:x:Scikit-LearnModel Selectionmodel_selection.HalvingRandomSearchCV:x:Scikit-LearnMulticlass classificationmulticlass.OneVsRestClassifier:x:Scikit-LearnMulticlass classificationmulticlass.OneVsOneClassifier:x:Scikit-LearnMulticlass classificationmulticlass.OutputCodeClassifier:x:Scikit-LearnMultioutput regression and classificationmultioutput.ClassifierChain:x:Scikit-LearnMultioutput regression and classificationmultioutput.MultiOutputRegressor:x:Scikit-LearnMultioutput regression and classificationmultioutput.MultiOutputClassifier:x:Scikit-LearnMultioutput regression and classificationmultioutput.RegressorChain:x:Scikit-LearnNaive Bayesnaive_bayes.BernoulliNB:heavy_check_mark:Scikit-LearnNaive Bayesnaive_bayes.CategoricalNB:x:Scikit-LearnNaive Bayesnaive_bayes.ComplementNB:heavy_check_mark:Scikit-LearnNaive Bayesnaive_bayes.GaussianNB:heavy_check_mark:Scikit-LearnNaive Bayesnaive_bayes.MultinomialNB:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.BallTree:x:Scikit-LearnNearest Neighborsneighbors.KDTree:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.KernelDensity:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.KNeighborsClassifier:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.KNeighborsRegressor:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.KNeighborsTransformer:x:Scikit-LearnNearest Neighborsneighbors.LocalOutlierFactor:x:Scikit-LearnNearest Neighborsneighbors.RadiusNeighborsClassifier:x:Scikit-LearnNearest Neighborsneighbors.RadiusNeighborsRegressor:x:Scikit-LearnNearest Neighborsneighbors.RadiusNeighborsTransformer:x:Scikit-LearnNearest Neighborsneighbors.NearestCentroid:x:Scikit-LearnNearest Neighborsneighbors.NearestNeighbors:heavy_check_mark:Scikit-LearnNearest Neighborsneighbors.NeighborhoodComponentsAnalysis:x:Scikit-LearnNeural network modelsneural_network.BernoulliRBM:x:Scikit-LearnNeural network modelsneural_network.MLPClassifier:heavy_check_mark:Scikit-LearnNeural network modelsneural_network.MLPRegressor:heavy_check_mark:Scikit-LearnPipelinepipeline.FeatureUnion:x:Scikit-LearnPipelinepipeline.Pipeline:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.Binarizer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.FunctionTransformer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.KBinsDiscretizer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.KernelCenterer:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.LabelBinarizer:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.LabelEncoder:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.MultiLabelBinarizer:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.MaxAbsScaler:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.MinMaxScaler:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.Normalizer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.OneHotEncoder:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.OrdinalEncoder:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.PolynomialFeatures:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.PowerTransformer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.QuantileTransformer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.RobustScaler:heavy_check_mark:Scikit-LearnPreprocessing and Normalizationpreprocessing.SplineTransformer:x:Scikit-LearnPreprocessing and Normalizationpreprocessing.StandardScaler:heavy_check_mark:Scikit-LearnRandom projectionrandom_projection.GaussianRandomProjection:x:Scikit-LearnRandom projectionrandom_projection.SparseRandomProjection:x:Scikit-LearnSemi-Supervised Learningsemi_supervised.LabelPropagation:x:Scikit-LearnSemi-Supervised Learningsemi_supervised.LabelSpreading:x:Scikit-LearnSemi-Supervised Learningsemi_supervised.SelfTrainingClassifier:x:Scikit-LearnSupport Vector Machinessvm.LinearSVC:x:Scikit-LearnSupport Vector Machinessvm.LinearSVR:x:Scikit-LearnSupport Vector Machinessvm.NuSVC:x:Scikit-LearnSupport Vector Machinessvm.NuSVR:x:Scikit-LearnSupport Vector Machinessvm.OneClassSVM:x:Scikit-LearnSupport Vector Machinessvm.SVC:heavy_check_mark:Scikit-LearnSupport Vector Machinessvm.SVR:heavy_check_mark:Scikit-LearnDecision Treestree.DecisionTreeClassifier:heavy_check_mark:Scikit-LearnDecision Treestree.DecisionTreeRegressor:heavy_check_mark:Scikit-LearnDecision Treestree.ExtraTreeClassifier:heavy_check_mark:Scikit-LearnDecision Treestree.ExtraTreeRegressor:heavy_check_mark:Imbalanced-LearnUnder-samplingClusterCentroids:x:Imbalanced-LearnUnder-samplingCondensedNearestNeighbour:x:Imbalanced-LearnUnder-samplingEditedNearestNeighbours:x:Imbalanced-LearnUnder-samplingRepeatedEditedNearestNeighbours:x:Imbalanced-LearnUnder-samplingAllKNN:x:Imbalanced-LearnUnder-samplingInstanceHardnessThreshold:x:Imbalanced-LearnUnder-samplingNearMiss:x:Imbalanced-LearnUnder-samplingNeighbourhoodCleaningRule:x:Imbalanced-LearnUnder-samplingOneSidedSelection:x:Imbalanced-LearnUnder-samplingRandomUnderSampler:x:Imbalanced-LearnUnder-samplingTomekLinks:x:Imbalanced-LearnOver-samplingRandomOverSampler:x:Imbalanced-LearnOver-samplingSMOTE:x:Imbalanced-LearnOver-samplingSMOTENC:x:Imbalanced-LearnOver-samplingSMOTEN:x:Imbalanced-LearnOver-samplingADASYN:x:Imbalanced-LearnOver-samplingBorderlineSMOTE:x:Imbalanced-LearnOver-samplingKMeansSMOTE:x:Imbalanced-LearnOver-samplingSVMSMOTE:x:Imbalanced-LearnCombined over & under samplingSMOTEENN:x:Imbalanced-LearnCombined over & under samplingSMOTETomek:x:Imbalanced-LearnEnsemble MethodsEasyEnsembleClassifier:x:Imbalanced-LearnEnsemble MethodsRUSBoostClassifier:x:Imbalanced-LearnEnsemble MethodsBalancedBaggingClassifier:x:Imbalanced-LearnEnsemble MethodsBalancedRandomForestClassifier:x:XGBoostEnsemble MethodsXGBRegressor:heavy_check_mark:XGBoostEnsemble MethodsXGBClassifier:heavy_check_mark:XGBoostEnsemble MethodsXGBRanker:heavy_check_mark:XGBoostEnsemble MethodsXGBRFRegressor:heavy_check_mark:XGBoostEnsemble MethodsXGBRFClassifier:heavy_check_mark:LightGBMEnsemble MethodsLGBMClassifier:heavy_check_mark:LightGBMEnsemble MethodsLGBMRegressor:heavy_check_mark:LightGBMEnsemble MethodsLGBMRanker:heavy_check_mark:CatBoostEnsemble MethodsCatBoostClassifier:heavy_check_mark:CatBoostEnsemble MethodsCatBoostRanker:heavy_check_mark:CatBoostEnsemble MethodsCatBoostRegressor:heavy_check_mark:kmodesClusteringKModes:heavy_check_mark:kmodesClusteringKPrototypes:heavy_check_mark:Scikit-Learn-extraClusteringcluster.KMedoids:x:Scikit-Learn-extraClusteringcluster.CommonNNClustering:x:Scikit-Learn-extraKernel approximationkernel_approximation.Fastfood:x:Scikit-Learn-extraEigenProkernel_methods.EigenProRegressor:x:Scikit-Learn-extraRobustkernel_methods.EigenProClassifier:x:Scikit-Learn-extraRobustrobust.RobustWeightedClassifier:x:Scikit-Learn-extraRobustrobust.RobustWeightedRegressor:x:Scikit-Learn-extraRobustrobust.RobustWeightedKMeans:x:HDBSCANClusteringHDBSCAN:heavy_check_mark:UMAPManifold LearningUMAP:heavy_check_mark:PyNNDescentNearest NeighborsNNDescent:heavy_check_mark:PrinceDecompositionPCA:x:PrinceDecompositionCA:x:PrinceDecompositionMCA:x:PrinceDecompositionMFA:x:PrinceDecompositionFAMD:x:PrinceDecompositionGPA:x:MLChemADApplicability DomainBoundingBoxApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainConvexHullApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainPCABoundingBoxApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainTopKatApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainLeverageApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainHotellingT2ApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainKernelDensityApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainIsolationForestApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainCentroidDistanceApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainKNNApplicabilityDomain:heavy_check_mark:MLChemADApplicability DomainStandardizationApproachApplicabilityDomain:heavy_check_mark: