-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Documentation For Model Training #1201
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cca34f1
Skip 17-home-rental-prediction.ipynb due to postgres setup
xzdandy 27a20f4
Fix the format issues on existing pages.
xzdandy 8bd0adf
Checkpoint
xzdandy bd853f6
Update predicion usecases
xzdandy b1d3def
Update the ludwig documentation
xzdandy 1061828
Add sklearn documentation
xzdandy da0ca5a
Add missing files
xzdandy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.. _ludwig: | ||
|
||
Model Training with Ludwig | ||
========================== | ||
|
||
1. Installation | ||
--------------- | ||
|
||
To use the `Ludwig framework <https://ludwig.ai/latest/>`_, we need to install the extra ludwig dependency in your EvaDB virtual environment. | ||
|
||
.. code-block:: bash | ||
|
||
pip install evadb[ludwig] | ||
|
||
2. Example Query | ||
---------------- | ||
|
||
.. code-block:: sql | ||
|
||
CREATE OR REPLACE FUNCTION PredictHouseRent FROM | ||
( SELECT sqft, location, rental_price FROM HomeRentals ) | ||
TYPE Ludwig | ||
PREDICT 'rental_price' | ||
TIME_LIMIT 120; | ||
|
||
In the above query, you are creating a new customized function by automatically training a model from the ``HomeRentals`` table. | ||
The ``rental_price`` column will be the target column for predication, while ``sqft`` and ``location`` are the inputs. | ||
|
||
You can also simply give all other columns in ``HomeRentals`` as inputs and let the underlying AutoML framework to figure it out. Below is an example query: | ||
|
||
.. code-block:: sql | ||
|
||
CREATE FUNCTION IF NOT EXISTS PredictHouseRent FROM | ||
( SELECT * FROM HomeRentals ) | ||
TYPE Ludwig | ||
PREDICT 'rental_price' | ||
TIME_LIMIT 120; | ||
|
||
.. note:: | ||
|
||
Check out our :ref:`homerental-predict` for working example. | ||
|
||
3. Model Training Parameters | ||
---------------------------- | ||
|
||
.. list-table:: Available Parameters | ||
:widths: 25 75 | ||
|
||
* - PREDICT (**required**) | ||
- The name of the column we wish to predict. | ||
* - TIME_LIMIT | ||
- Time limit to train the model in seconds. Default: 120. | ||
* - TUNE_FOR_MEMORY | ||
- Whether to refine hyperopt search space for available host / GPU memory. Default: False. | ||
|
||
Below is an example query specifying the above parameters: | ||
|
||
.. code-block:: sql | ||
|
||
CREATE FUNCTION IF NOT EXISTS PredictHouseRent FROM | ||
( SELECT * FROM HomeRentals ) | ||
TYPE Ludwig | ||
PREDICT 'rental_price' | ||
TIME_LIMIT 3600 | ||
TUNE_FOR_MEMORY True; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _sklearn: | ||
|
||
Model Training with Sklearn | ||
============================ | ||
|
||
1. Installation | ||
--------------- | ||
|
||
To use the `Sklearn framework <https://scikit-learn.org/stable/>`_, we need to install the extra sklearn dependency in your EvaDB virtual environment. | ||
|
||
.. code-block:: bash | ||
|
||
pip install evadb[sklearn] | ||
|
||
2. Example Query | ||
---------------- | ||
|
||
.. code-block:: sql | ||
|
||
CREATE OR REPLACE FUNCTION PredictHouseRent FROM | ||
( SELECT number_of_rooms, number_of_bathrooms, days_on_market, rental_price FROM HomeRentals ) | ||
TYPE Sklearn | ||
PREDICT 'rental_price'; | ||
|
||
In the above query, you are creating a new customized function by training a model from the ``HomeRentals`` table using the ``Sklearn`` framework. | ||
The ``rental_price`` column will be the target column for predication, while the rest columns from the ``SELET`` query are the inputs. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
.. _homerental-predict: | ||
|
||
Home Rental Prediction | ||
======================= | ||
|
||
.. raw:: html | ||
|
||
<embed> | ||
<table align="left"> | ||
<td> | ||
<a target="_blank" href="https://colab.research.google.com/github/georgia-tech-db/eva/blob/staging/tutorials/17-home-rental-prediction.ipynb"><img src="https://www.tensorflow.org/images/colab_logo_32px.png" /> Run on Google Colab</a> | ||
</td> | ||
<td> | ||
<a target="_blank" href="https://github.com/georgia-tech-db/eva/blob/staging/tutorials/17-home-rental-prediction.ipynb"><img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" /> View source on GitHub</a> | ||
</td> | ||
<td> | ||
<a target="_blank" href="https://github.com/georgia-tech-db/eva/raw/staging/tutorials/17-home-rental-prediction.ipynb"><img src="https://www.tensorflow.org/images/download_logo_32px.png" /> Download notebook</a> | ||
</td> | ||
</table><br><br> | ||
</embed> | ||
|
||
Introduction | ||
------------ | ||
|
||
In this tutorial, we present how to use :ref:`Prediction AI Engines<ludwig>` in EvaDB to predict home rental prices. EvaDB makes it easy to do predictions using its built-in AutoML engines with your existing databases. | ||
|
||
.. include:: ../shared/evadb.rst | ||
|
||
.. include:: ../shared/postgresql.rst | ||
|
||
We will assume that the input data is loaded into a ``PostgreSQL`` database. | ||
To load the home rental data into your database, see the complete `home rental prediction notebook on Colab <https://colab.research.google.com/github/georgia-tech-db/eva/blob/staging/tutorials/17-home-rental-prediction.ipynb>`_. | ||
|
||
Preview the Home Sales Data | ||
------------------------------------------- | ||
|
||
We use the `home rental data <https://www.dropbox.com/scl/fi/gy2682i66a8l2tqsowm5x/home_rentals.csv?rlkey=e080k02rv5205h4ullfjdr8lw&raw=1>`_ in this usecase. The data contains eight columns: ``number_of_rooms``, ``number_of_bathrooms``, ``sqft``, ``location``, ``days_on_market``, ``initial_price``, ``neighborhood``, and ``rental_price``. | ||
|
||
.. code-block:: sql | ||
|
||
SELECT * FROM postgres_data.home_rentals LIMIT 3; | ||
|
||
This query previews the data in the home_rentals table: | ||
|
||
.. code-block:: | ||
|
||
+------------------------------+----------------------------------+-------------------+-----------------------+-----------------------------+----------------------------+---------------------------+---------------------------+ | ||
| home_rentals.number_of_rooms | home_rentals.number_of_bathrooms | home_rentals.sqft | home_rentals.location | home_rentals.days_on_market | home_rentals.initial_price | home_rentals.neighborhood | home_rentals.rental_price | | ||
|------------------------------|----------------------------------|-------------------|-----------------------|-----------------------------|----------------------------|---------------------------|---------------------------| | ||
| 1 | 1 | 674 | good | 1 | 2167 | downtown | 2167 | | ||
| 1 | 1 | 554 | poor | 19 | 1883 | westbrae | 1883 | | ||
| 0 | 1 | 529 | great | 3 | 2431 | south_side | 2431 | | ||
+------------------------------+----------------------------------+-------------------+-----------------------+-----------------------------+----------------------------+---------------------------+---------------------------+ | ||
|
||
Train a Home Rental Prediction Model | ||
------------------------------------- | ||
|
||
Let's next train a prediction model from the home_rental table using EvaDB's ``CREATE FUNCTION`` query. | ||
We will use the built-in :ref:`Ludwig<ludwig>` engine for this task. | ||
|
||
.. code-block:: sql | ||
|
||
CREATE OR REPLACE FUNCTION PredictHouseRent FROM | ||
( SELECT * FROM postgres_data.home_rental ) | ||
TYPE Ludwig | ||
PREDICT 'rental_price' | ||
TIME_LIMIT 3600; | ||
|
||
In the above query, we use all the columns (except ``rental_price``) from ``home_rental`` table to predict the ``rental_price`` column. | ||
We set the training time out to be 3600 seconds. | ||
|
||
.. note:: | ||
|
||
Go over :ref:`ludwig` page on exploring all configurable paramters for the model training frameworks. | ||
|
||
.. code-block:: | ||
|
||
+----------------------------------------------+ | ||
| Function PredictHouseRent successfully added | | ||
+----------------------------------------------+ | ||
|
||
Predict the Home Rental Price using the Trained Model | ||
----------------------------------------------------- | ||
|
||
Next we use the trained ``PredictHouseRent`` to predict the home rental price. | ||
|
||
.. code-block:: sql | ||
|
||
SELECT PredictHouseRent(*) FROM postgres_data.home_rentals LIMIT 3; | ||
|
||
We use ``*`` to simply pass all columns into the ``PredictHouseRent`` function. | ||
|
||
.. code-block:: | ||
|
||
+-------------------------------------------+ | ||
| predicthouserent.rental_price_predictions | | ||
+-------------------------------------------+ | ||
| 2087.763672 | | ||
| 1793.570190 | | ||
| 2346.319824 | | ||
+-------------------------------------------+ | ||
|
||
We have the option to utilize a ``LATERAL JOIN`` to compare the actual rental prices in the ``home_rentals`` dataset with the predicted rental prices generated by the trained model, ``PredictHouseRent``. | ||
|
||
.. code-block:: sql | ||
|
||
SELECT rental_price, predicted_rental_price | ||
FROM postgres_data.home_rentals | ||
JOIN LATERAL PredictHouseRent(*) AS Predicted(predicted_rental_price) | ||
LIMIT 3; | ||
|
||
Here is the query's output: | ||
|
||
.. code-block:: | ||
|
||
+---------------------------+----------------------------------+ | ||
| home_rentals.rental_price | Predicted.predicted_rental_price | | ||
+---------------------------+----------------------------------+ | ||
| 2167 | 2087.763672 | | ||
| 1883 | 1793.570190 | | ||
| 2431 | 2346.319824 | | ||
+------------------ --------+----------------------------------+ | ||
|
||
.. include:: ../shared/footer.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot understand this parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we add a note explaining this? Any issues of using it if there is no GPU?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also not sure. Ludwig documentation also don't have a good explanation. Shall we hide this parameter from the documentation?