How to use the sklearn2pmml.preprocessing.CutTransformer function in sklearn2pmml

To help you get started, we’ve selected a few sklearn2pmml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openscoring / papis.io / RandomForestAudit.py View on Github external
mapper = DataFrameMapper([
	("Education", CategoricalDomain()),
	("Employment", CategoricalDomain()),
	("Gender", CategoricalDomain()),
	("Marital", CategoricalDomain()),
	("Occupation", CategoricalDomain()),
	("Age", [ContinuousDomain(), CutTransformer(bins = [17, 28, 37, 47, 83], labels = ["q1", "q2", "q3", "q4"])]),
	("Hours", ContinuousDomain()),
	("Income", ContinuousDomain()),
	(["Hours", "Income"], Alias(ExpressionTransformer("X[1] / (X[0] * 52)"), "Hourly_Income"))
])
classifier = H2ORandomForestEstimator(ntrees = 17)

predict_proba_transformer = Pipeline([
	("expression", ExpressionTransformer("X[1]")),
	("cut", Alias(CutTransformer(bins = [0.0, 0.75, 0.90, 1.0], labels = ["no", "maybe", "yes"]), "Decision", prefit = True))
])

pipeline = PMMLPipeline([
	("local_mapper", mapper),
	("uploader", H2OFrameCreator()),
	("remote_classifier", classifier)
], predict_proba_transformer = predict_proba_transformer)
pipeline.fit(audit_X, H2OFrame(audit_y.to_frame(), column_types = ["categorical"]))

pipeline.verify(audit_X.sample(100))

sklearn2pmml(pipeline, "pmml/RandomForestAudit.pmml")

if "--deploy" in sys.argv:
	from openscoring import Openscoring
github openscoring / papis.io / RandomForestAudit.py View on Github external
audit_df = pandas.read_csv("csv/Audit.csv")
#print(audit_df.head(5))

audit_X = audit_df[audit_df.columns.difference(["Adjusted"])]
audit_y = audit_df["Adjusted"]

h2o.init()

mapper = DataFrameMapper([
	("Education", CategoricalDomain()),
	("Employment", CategoricalDomain()),
	("Gender", CategoricalDomain()),
	("Marital", CategoricalDomain()),
	("Occupation", CategoricalDomain()),
	("Age", [ContinuousDomain(), CutTransformer(bins = [17, 28, 37, 47, 83], labels = ["q1", "q2", "q3", "q4"])]),
	("Hours", ContinuousDomain()),
	("Income", ContinuousDomain()),
	(["Hours", "Income"], Alias(ExpressionTransformer("X[1] / (X[0] * 52)"), "Hourly_Income"))
])
classifier = H2ORandomForestEstimator(ntrees = 17)

predict_proba_transformer = Pipeline([
	("expression", ExpressionTransformer("X[1]")),
	("cut", Alias(CutTransformer(bins = [0.0, 0.75, 0.90, 1.0], labels = ["no", "maybe", "yes"]), "Decision", prefit = True))
])

pipeline = PMMLPipeline([
	("local_mapper", mapper),
	("uploader", H2OFrameCreator()),
	("remote_classifier", classifier)
], predict_proba_transformer = predict_proba_transformer)
github openscoring / papis.io / XGBoostAudit.py View on Github external
from xgboost import XGBClassifier

import pandas
import sys

audit_df = pandas.read_csv("csv/Audit.csv")
#print(audit_df.head(5))

audit_X = audit_df[audit_df.columns.difference(["Adjusted"])]
audit_y = audit_df["Adjusted"]

scalar_mapper = DataFrameMapper([
	("Education", [CategoricalDomain(), LabelBinarizer(), SelectKBest(chi2, k = 3)]),
	("Employment", [CategoricalDomain(), LabelBinarizer(), SelectKBest(chi2, k = 3)]),
	("Occupation", [CategoricalDomain(), LabelBinarizer(), SelectKBest(chi2, k = 3)]),
	("Age", [ContinuousDomain(), CutTransformer(bins = [17, 28, 37, 47, 83], labels = ["q1", "q2", "q3", "q4"]), LabelBinarizer()]),
	("Hours", ContinuousDomain()),
	("Income", ContinuousDomain()),
	(["Hours", "Income"], Alias(ExpressionTransformer("X[1] / (X[0] * 52)"), "Hourly_Income"))
])
interaction_mapper = DataFrameMapper([
	("Gender", [CategoricalDomain(), LabelBinarizer()]),
	("Marital", [CategoricalDomain(), LabelBinarizer()])
])
classifier = XGBClassifier()

pipeline = PMMLPipeline([
	("mapper", FeatureUnion([
		("scalar_mapper", scalar_mapper),
		("interaction", Pipeline([
			("interaction_mapper", interaction_mapper),
			("polynomial", PolynomialFeatures())

sklearn2pmml

Python library for converting Scikit-Learn pipelines to PMML

AGPL-3.0
Latest version published 25 days ago

Package Health Score

70 / 100
Full package analysis

Similar packages