diff --git a/src/python/nimbusml/tests/pipeline/test_uci_adult.py b/src/python/nimbusml/tests/pipeline/test_uci_adult.py index c5be9d58..00ae1728 100644 --- a/src/python/nimbusml/tests/pipeline/test_uci_adult.py +++ b/src/python/nimbusml/tests/pipeline/test_uci_adult.py @@ -6,14 +6,15 @@ import tempfile import unittest +import numpy as np from nimbusml import FileDataStream from nimbusml import Pipeline from nimbusml.datasets import get_dataset from nimbusml.ensemble import FastTreesBinaryClassifier from nimbusml.feature_extraction.categorical import OneHotVectorizer from nimbusml.linear_model import FastLinearBinaryClassifier -from nimbusml.utils import check_accuracy, get_X_y -from sklearn.utils.testing import assert_raises_regex, assert_equal, assert_true +from nimbusml.utils import get_X_y +from sklearn.utils.testing import assert_raises_regex, assert_equal, assert_true, assert_greater train_file = get_dataset("uciadult_train").as_filepath() test_file = get_dataset("uciadult_test").as_filepath() @@ -32,6 +33,15 @@ 'col=sex:TX:7 col=native-country-region:TX:8 header+' label_column = 'label' +def check_accuracy(test_file, label_column, predictions, threshold, sep=','): + (test, label) = get_X_y(test_file, label_column, sep=sep) + accuracy = np.mean(label[label_column].values == + predictions.ix[:, 'PredictedLabel'].values) + assert_greater( + accuracy, + threshold, + "accuracy should be greater than %s" % + threshold) class TestUciAdult(unittest.TestCase): diff --git a/src/python/nimbusml/tests/scikit/test_uci_adult_scikit.py b/src/python/nimbusml/tests/scikit/test_uci_adult_scikit.py index a08ce3b9..037987db 100644 --- a/src/python/nimbusml/tests/scikit/test_uci_adult_scikit.py +++ b/src/python/nimbusml/tests/scikit/test_uci_adult_scikit.py @@ -16,14 +16,14 @@ from nimbusml.linear_model import FastLinearBinaryClassifier from nimbusml.linear_model import LogisticRegressionClassifier from nimbusml.preprocessing.normalization import MeanVarianceScaler -from nimbusml.utils import check_accuracy_scikit, get_X_y +from nimbusml.utils import get_X_y from sklearn.base import clone from sklearn.datasets import load_iris from sklearn.decomposition import PCA from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline, FeatureUnion from sklearn.preprocessing import OneHotEncoder -from sklearn.utils.testing import assert_equal +from sklearn.utils.testing import assert_equal, assert_greater try: from pandas.testing import assert_frame_equal @@ -45,6 +45,19 @@ 'native-country-region'] selected_features = ['age', 'education-num'] +def check_accuracy_scikit( + test_file, + label_column, + predictions, + threshold, + sep=','): + (test, label) = get_X_y(test_file, label_column, sep=sep) + accuracy = np.mean(label[label_column].values == predictions.values) + assert_greater( + accuracy, + threshold, + "accuracy should be greater than %s" % + threshold) class TestUciAdultScikit(unittest.TestCase): diff --git a/src/python/nimbusml/utils/__init__.py b/src/python/nimbusml/utils/__init__.py index 3243711a..1c85d629 100644 --- a/src/python/nimbusml/utils/__init__.py +++ b/src/python/nimbusml/utils/__init__.py @@ -1,5 +1,4 @@ -from .utils import get_X_y, evaluate_binary_classifier, check_accuracy, \ - check_accuracy_scikit, load_img, ColumnSelector +from .utils import get_X_y, evaluate_binary_classifier, load_img, ColumnSelector try: from inspect import signature @@ -9,8 +8,6 @@ __all__ = [ 'get_X_y', 'evaluate_binary_classifier', - 'check_accuracy', - 'check_accuracy_scikit', 'load_img', 'ColumnSelector', 'signature' diff --git a/src/python/nimbusml/utils/utils.py b/src/python/nimbusml/utils/utils.py index b9b33075..5e2e9fe6 100644 --- a/src/python/nimbusml/utils/utils.py +++ b/src/python/nimbusml/utils/utils.py @@ -12,12 +12,9 @@ import pandas as pd from sklearn.base import BaseEstimator, TransformerMixin from sklearn.metrics import roc_auc_score -from sklearn.utils.testing import assert_greater - - -# select columns from DataFrame insize a pipeline +# select columns from DataFrame inside a pipeline class ColumnSelector(BaseEstimator, TransformerMixin): def __init__(self, columns, ravel=False): self.columns = columns @@ -106,30 +103,4 @@ def evaluate_binary_classifier(target, predicted, probabilities=None): auc_score = None if probabilities is not None: auc_score = roc_auc_score(target, probabilities) - return (accuracy, auc_score) - - -def check_accuracy(test_file, label_column, predictions, threshold, sep=','): - (test, label) = get_X_y(test_file, label_column, sep=sep) - accuracy = np.mean(label[label_column].values == - predictions.ix[:, 'PredictedLabel'].values) - assert_greater( - accuracy, - threshold, - "accuracy should be greater than %s" % - threshold) - - -def check_accuracy_scikit( - test_file, - label_column, - predictions, - threshold, - sep=','): - (test, label) = get_X_y(test_file, label_column, sep=sep) - accuracy = np.mean(label[label_column].values == predictions.values) - assert_greater( - accuracy, - threshold, - "accuracy should be greater than %s" % - threshold) + return (accuracy, auc_score) \ No newline at end of file