damccorm commented on code in PR #25905: URL: https://github.com/apache/beam/pull/25905#discussion_r1156246049
########## sdks/python/apache_beam/examples/inference/milk_quality_prediction_windowing.py: ########## @@ -0,0 +1,240 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""A streaming pipeline that uses RunInference API and windowing that classifies +the quality of milk as good, bad or medium based on pH, temperature, +taste, odor, fat, turbidity and color. Each minute new measurements come in +and a sliding window aggregates the number of good, bad and medium +samples. + +This example uses the milk quality prediction dataset from kaggle. +https://www.kaggle.com/datasets/cpluzshrijayan/milkquality + + +In order to set this example up, you will need two things. +1. Download the data in csv format from kaggle and host it. +2. Split the dataset in a training set and test set (preprocess_data function). +3. Train the classifier. +""" + +import argparse +import logging +import time +from typing import NamedTuple + +import pandas +from sklearn.model_selection import train_test_split + +import apache_beam as beam +import xgboost +from apache_beam import window +from apache_beam.ml.inference import RunInference +from apache_beam.ml.inference.base import PredictionResult +from apache_beam.ml.inference.xgboost_inference import XGBoostModelHandlerPandas +from apache_beam.options.pipeline_options import PipelineOptions +from apache_beam.options.pipeline_options import SetupOptions +from apache_beam.runners.runner import PipelineResult +from apache_beam.testing.test_stream import TestStream + + +def parse_known_args(argv): + """Parses args for the workflow.""" + parser = argparse.ArgumentParser() + parser.add_argument( + '--dataset', + dest='dataset', + required=True, + help='Path to the csv containing Kaggle Milk Quality dataset.') + parser.add_argument( + '--pipeline_input_data', + dest='pipeline_input_data', + required=True, + help='Path to store the csv containing input data for the pipeline.' + 'This will be generated as part of preprocessing the data.') + parser.add_argument( + '--training_set', + dest='training_set', + required=True, + help='Path to store the csv containing the training set.' + 'This will be generated as part of preprocessing the data.') + parser.add_argument( + '--labels', + dest='labels', + required=True, + help='Path to store the csv containing the labels used in training.' + 'This will be generated as part of preprocessing the data.') Review Comment: ```suggestion help='Path to store the csv containing input data for the pipeline.' 'This will be generated as part of preprocessing the data.') parser.add_argument( '--training_set', dest='training_set', required=True, help='Path to store the csv containing the training set.' 'This will be generated as part of preprocessing the data.') parser.add_argument( '--labels', dest='labels', required=True, help='Path to store the csv containing the labels used in training.' 'This will be generated as part of preprocessing the data.') ``` Needs this to make the linter happy -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
