Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/python/nimbusml/tests/pipeline/test_uci_adult.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):

Expand Down
17 changes: 15 additions & 2 deletions src/python/nimbusml/tests/scikit/test_uci_adult_scikit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):

Expand Down
5 changes: 1 addition & 4 deletions src/python/nimbusml/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,8 +8,6 @@
__all__ = [
'get_X_y',
'evaluate_binary_classifier',
'check_accuracy',
'check_accuracy_scikit',
'load_img',
'ColumnSelector',
'signature'
Expand Down
33 changes: 2 additions & 31 deletions src/python/nimbusml/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)