def test_prod_float(self): X = numpy.asarray([1.0, float("NaN"), 2.0, 4.0]) aggregator = Aggregator(function="prod") X = X.reshape((-1, 4)) self.assertEquals(8.0, aggregator.transform(X)) X = X.reshape((2, 2)) self.assertEquals([1.0, 8.0], aggregator.transform(X).tolist())
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)
def test_min_int(self): X = numpy.asarray([1, 0, 2, 3]) aggregator = Aggregator(function="min") X = X.reshape((-1, 4)) self.assertEquals(0, aggregator.transform(X)) X = X.reshape((2, 2)) self.assertEquals([0, 2], aggregator.transform(X).tolist()) X = X.reshape((4, -1)) self.assertEquals([1, 0, 2, 3], aggregator.transform(X).tolist())
def test_min(self): X = numpy.asarray([1, 0.5, 2, 3.0, 0, 1.0]) min = Aggregator(function="min") X = X.reshape((1, 6)) self.assertEqual(0, min.transform(X)) X = X.reshape((3, 2)) self.assertEqual([0.5, 2, 0], min.transform(X).tolist()) X = X.reshape((2, 3)) self.assertEqual([0.5, 0], min.transform(X).tolist()) X = X.reshape((6, 1)) self.assertEqual([1, 0.5, 2, 3.0, 0, 1.0], min.transform(X).tolist())
def test_min_float(self): X = numpy.asarray([1.0, 0.5, 2.0, 3.0, float("NaN"), 1.5]) aggregator = Aggregator(function = "min") X = X.reshape((-1, 6)) self.assertEqual(0.5, aggregator.transform(X)) X = X.reshape((3, 2)) self.assertEqual([0.5, 2.0, 1.5], aggregator.transform(X).tolist()) X = X.reshape((2, 3)) self.assertEqual([0.5, 1.5], aggregator.transform(X).tolist()) X = X.reshape((6, -1)) self.assertTrue(nan_eq([1.0, 0.5, 2.0, 3.0, float("NaN"), 1.5], aggregator.transform(X).tolist()))
def test_mean_float(self): X = numpy.asarray([1.0, float("NaN"), 2.0]) aggregator = Aggregator(function="mean") X = X.reshape((-1, 3)) self.assertEquals(1.5, aggregator.transform(X))
def test_init(self): with self.assertRaises(ValueError): Aggregator(None)