Rent Forecasting Model (Ray Serve)

Provides an end-to-end example for creating a notebook server and building a machine learning model to forecast rental prices, evaluate its accuracy, and deploy it for real-time predictions using Ray Serve in HPE Ezmeral Unified Analytics Software.

Prerequisites

  • Sign in to HPE Ezmeral Unified Analytics Software.
  • Verify that the installed Ray client and server versions match. To verify, complete the following steps in the terminal:
    1. To switch to Ray's environment, run:
      source /opt/conda/etc/profile.d/conda.sh && conda activate ray
    2. To verify that the Ray client and server versions match, run :
      ray --version

About this task

In this tutorial, you will complete the following steps:
  1. Generate a synthetic dataset of rental properties with attributes such as square footage, number of bedrooms, number of bathrooms, and furnishing status to train the prediction model.
  2. Format and input the generated data to the model for training.
  3. Use the Random Forest model to predict the monthly rental prices.
  4. Evaluate the predictive performance of the model using the Mean Absolute Error (MAE) on the testing data set.
  5. Visualize the performance of the model using matplotlib which shows the graph for Actual vs Predicted Rent Prices.
  6. After completing the model training process, save the model and deploy the model as a web service using Ray Serve. This allows you to manage request handling and scalability efficiently.
    1. First, initialize the Ray environment and start Ray Serve with the appropriate configuration settings to ensure smooth deployment and operation of service.
    2. Once Ray Serve is up and running, it manages the incoming HTTP requests and directs them to the deployed model for prediction.
  7. View the deployed application in the Ray Dashboard under the Serve tab.
  8. Wait for the deployed application to be in a Running state.
  9. Send HTTP requests to the deployed model to obtain prediction results. These requests contain the input data that you want the model to make predictions on, and the response contains the corresponding predictions generated by the model.
  10. After obtaining the prediction results, terminate deployment.

Procedure

  1. Create a notebook server using the jupyter-data-science image with at least 3 CPUs and 4 Gi of memory in Kubeflow. See Creating and Managing Notebook Servers.

  2. In your notebook environment, activate the Ray-specific Python kernel.
  3. To ensure optimal performance, use dedicated directories containing only the essential files needed for that job submission as a working directory.

    For example, if you do not see the Ray-Serve folder in the <username> directory, copy the folder from the shared/ezua-tutorials/current-release/Data-Science/Ray directory into the <username> directory. The shared directory is accessible to all users. Editing or running examples from the shared directory is not advised. The <username> directory is specific to you and cannot be accessed by other users.

  4. Open the ray-serve-executor.ipynb file in the <username>/Ray-Serve directory.
  5. Select the first cell of the ray-serve-executor.ipynb notebook and click Run the selected cells and advance (play icon). Continue until you run the following block of code which generates the rent_predictor_app_config.yaml configuration file.

  6. Run the following block of code to generate URI. Currently, serve deploy does not directly support the --working-dir option. You must specify the generated URI from the output of this block of code in the rent_predictor_app_config.yaml file.

  7. Open the rent_predictor_app_config.yaml file.
  8. Specify the generated URI in the rent_predictor_app_config.yaml file as follows:
    runtime_env:
        working_dir: "<generated-URI>" #example: gcs://_ray_pkg_fef565b457f470d9.zip
  9. Navigate back to the ray-serve-executor.ipynb notebook file and continue to run cells until you reach the following block of code.

  10. View the deployed application in Ray Dashboard under the Serve tab.
    1. Click the Applications & Frameworks icon on the left navigation bar.
    2. Navigate to the Ray tile under the Data Science tab and click Open.
    3. Navigate to the Serve tab.
    4. Locate and view your deployed application.
      NOTE
      The auto-generated application names default to app1, app2, and so on. You can rename them as necessary.
    5. Wait for the deployed application to be in a Running state.
  11. Navigate back to the ray-serve-executor.ipynb notebook file.
  12. Run the following block of code:

    You will obtain the prediction result as Predicted rent: 1861.12.
  13. After obtaining the prediction results, terminate deployment.

Results

This tutorial shows that by using Ray Serve and Ray cluster deployed in HPE Ezmeral Unified Analytics Software, you can efficiently deploy, manage, and scale your machine learning model as a web service to obtain prediction results.