Exemplo n.º 1
0
 def test_transform(self):
     X = numpy.asarray([-2, -1, 0, 1, 2])
     transformer = PowerFunctionTransformer(power=1)
     self.assertEqual(X.tolist(), transformer.transform(X).tolist())
     transformer = PowerFunctionTransformer(power=2)
     self.assertEqual([4, 1, 0, 1, 4], transformer.transform(X).tolist())
     transformer = PowerFunctionTransformer(power=3)
     self.assertEqual([-8, -1, 0, 1, 8], transformer.transform(X).tolist())
Exemplo n.º 2
0
 def test_power(self):
     X = numpy.asarray([-2, -1, 0, 1, 2])
     pow = PowerFunctionTransformer(power=1)
     self.assertEquals(X.tolist(), pow.transform(X).tolist())
     pow = PowerFunctionTransformer(power=2)
     self.assertEquals([4, 1, 0, 1, 4], pow.transform(X).tolist())
     pow = PowerFunctionTransformer(power=3)
     self.assertEquals([-8, -1, 0, 1, 8], pow.transform(X).tolist())
Exemplo n.º 3
0
def build_iris(classifier, name, with_proba = True, fit_params = {}, predict_params = {}, predict_proba_params = {}, **pmml_options):
	pipeline = Pipeline([
		("pipeline", Pipeline([
			("mapper", DataFrameMapper([
				(iris_X.columns.values, ContinuousDomain()),
				(["Sepal.Length", "Petal.Length"], Aggregator(function = "mean")),
				(["Sepal.Width", "Petal.Width"], Aggregator(function = "mean"))
			])),
			("transform", FeatureUnion([
				("normal_scale", FunctionTransformer(None, validate = True)),
				("log_scale", FunctionTransformer(numpy.log10, validate = True)),
				("power_scale", PowerFunctionTransformer(power = 2))
			]))
		])),
		("pca", IncrementalPCA(n_components = 3, whiten = True)),
		("classifier", classifier)
	])
	pipeline.fit(iris_X, iris_y, **fit_params)
	pipeline = make_pmml_pipeline(pipeline, iris_X.columns.values, iris_y.name)
	pipeline.configure(**pmml_options)
	if isinstance(classifier, XGBClassifier):
		pipeline.verify(iris_X.sample(frac = 0.10, random_state = 13), predict_params = predict_params, predict_proba_params = predict_proba_params, precision = 1e-5, zeroThreshold = 1e-5)
	else:
		pipeline.verify(iris_X.sample(frac = 0.10, random_state = 13), predict_params = predict_params, predict_proba_params = predict_proba_params)
	store_pkl(pipeline, name)
	species = DataFrame(pipeline.predict(iris_X, **predict_params), columns = ["Species"])
	if with_proba == True:
		species_proba = DataFrame(pipeline.predict_proba(iris_X, **predict_proba_params), columns = ["probability(setosa)", "probability(versicolor)", "probability(virginica)"])
		species = pandas.concat((species, species_proba), axis = 1)
	store_csv(species, name)