Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import numpy
import pandas
import scipy
import xgboost
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

import apache_beam as beam
import datatable
import xgboost
from apache_beam.ml.inference.base import KeyedModelHandler
from apache_beam.ml.inference.base import PredictionResult
from apache_beam.ml.inference.base import RunInference
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerDatatable
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerNumpy
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerPandas
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerSciPy
Expand All @@ -59,7 +57,7 @@ def parse_known_args(argv):
'--input_type',
dest='input_type',
required=True,
choices=['numpy', 'pandas', 'scipy', 'datatable'],
choices=['numpy', 'pandas', 'scipy'],
help='Datatype of the input data.')
parser.add_argument(
'--output',
Expand Down Expand Up @@ -122,7 +120,6 @@ def run(
'numpy': (numpy.array, XGBoostModelHandlerNumpy),
'pandas': (pandas.DataFrame, XGBoostModelHandlerPandas),
'scipy': (scipy.sparse.csr_matrix, XGBoostModelHandlerSciPy),
'datatable': (datatable.Frame, XGBoostModelHandlerDatatable),
}

input_data_type, model_handler = data_types[known_args.input_type]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def process_outputs(filepath):
@unittest.skipIf(
os.getenv('FORCE_XGBOOST_IT') is None and xgboost is None,
'Missing dependencies. '
'Test depends on xgboost and datatable')
'Test depends on xgboost')
@pytest.mark.uses_xgboost
@pytest.mark.it_postcommit
class XGBoostInference(unittest.TestCase):
Expand Down Expand Up @@ -214,39 +214,6 @@ def test_iris_classification_scipy_single_batch(self):
true_label, expected_prediction = expected_output.split(',')
self.assertEqual(predictions_dict[true_label], expected_prediction)

def test_iris_classification_datatable_single_batch(self):
test_pipeline = TestPipeline(is_integration_test=True)
input_type = 'datatable'
output_file_dir = '/tmp'
output_file = '/'.join(
[output_file_dir, str(uuid.uuid4()), 'datatable_single_batch.txt'])
model_state_path = 'gs://apache-beam-ml/models/xgboost.iris_classifier.json'
extra_opts = {
'input_type': input_type,
'output': output_file,
'model_state': model_state_path,
'no_split': True
}

xgboost_iris_classification.run(
test_pipeline.get_full_options_as_args(**extra_opts),
save_main_session=False)
self.assertEqual(FileSystems().exists(output_file), True)

expected_outputs = EXPECTED_OUTPUT_SINGLE_BATCHES

predicted_outputs = process_outputs(output_file)
self.assertEqual(len(expected_outputs), len(predicted_outputs))

predictions_dict = {}
for predicted_output in predicted_outputs:
true_label, prediction = predicted_output.split(',')
predictions_dict[true_label] = prediction

for expected_output in expected_outputs:
true_label, expected_prediction = expected_output.split(',')
self.assertEqual(predictions_dict[true_label], expected_prediction)

def test_iris_classification_numpy_multi_batch(self):
test_pipeline = TestPipeline(is_integration_test=True)
input_type = 'numpy'
Expand Down Expand Up @@ -346,39 +313,6 @@ def test_iris_classification_scipy_multi_batch(self):
true_label, expected_prediction = expected_output.split(',')
self.assertEqual(predictions_dict[true_label], expected_prediction)

def test_iris_classification_datatable_multi_batch(self):
test_pipeline = TestPipeline(is_integration_test=True)
input_type = 'datatable'
output_file_dir = '/tmp'
output_file = '/'.join(
[output_file_dir, str(uuid.uuid4()), 'datatable_multi_batch.txt'])
model_state_path = 'gs://apache-beam-ml/models/xgboost.iris_classifier.json'
extra_opts = {
'input_type': input_type,
'output': output_file,
'model_state': model_state_path,
'split': True
}

xgboost_iris_classification.run(
test_pipeline.get_full_options_as_args(**extra_opts),
save_main_session=False)
self.assertEqual(FileSystems().exists(output_file), True)

expected_outputs = EXPECTED_OUTPUT_MULTIPLE_BATCHES

predicted_outputs = process_outputs(output_file)
self.assertEqual(len(expected_outputs), len(predicted_outputs))

predictions_dict = {}
for predicted_output in predicted_outputs:
true_label, prediction = predicted_output.split(',')
predictions_dict[true_label] = prediction

for expected_output in expected_outputs:
true_label, expected_prediction = expected_output.split(',')
self.assertEqual(predictions_dict[true_label], expected_prediction)


if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from apache_beam.ml.inference import RunInference
from apache_beam.ml.inference.base import KeyedModelHandler
from apache_beam.ml.inference.base import PredictionResult
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerDatatable
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerNumpy
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerPandas
from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerSciPy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
# limitations under the License.
#

datatable>=1.1.0,<2
xgboost>=2.0.0,<4
Loading