forked from georgia-tech-db/evadb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting the change for XGBoost integration into EVADb. (georgia-tech…
…-db#1232) Co-authored-by: Jineet Desai <[email protected]> Co-authored-by: Andy Xu <[email protected]>
- Loading branch information
Showing
11 changed files
with
215 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _xgboost: | ||
|
||
Model Training with XGBoost | ||
============================ | ||
|
||
1. Installation | ||
--------------- | ||
|
||
To use the `Flaml XGBoost AutoML framework <https://microsoft.github.io/FLAML/docs/Examples/AutoML-for-XGBoost/>`_, we need to install the extra Flaml dependency in your EvaDB virtual environment. | ||
|
||
.. code-block:: bash | ||
pip install "flaml[automl]" | ||
2. Example Query | ||
---------------- | ||
|
||
.. code-block:: sql | ||
CREATE FUNCTION IF NOT EXISTS PredictRent FROM | ||
( SELECT number_of_rooms, number_of_bathrooms, days_on_market, rental_price FROM HomeRentals ) | ||
TYPE XGBoost | ||
PREDICT 'rental_price'; | ||
In the above query, you are creating a new customized function by training a model from the ``HomeRentals`` table using the ``Flaml XGBoost`` 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 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
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,48 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed 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. | ||
import pickle | ||
|
||
import pandas as pd | ||
|
||
from evadb.functions.abstract.abstract_function import AbstractFunction | ||
from evadb.utils.generic_utils import try_to_import_xgboost | ||
|
||
|
||
class GenericXGBoostModel(AbstractFunction): | ||
@property | ||
def name(self) -> str: | ||
return "GenericXGBoostModel" | ||
|
||
def setup(self, model_path: str, predict_col: str, **kwargs): | ||
try_to_import_xgboost() | ||
|
||
self.model = pickle.load(open(model_path, "rb")) | ||
self.predict_col = predict_col | ||
|
||
def forward(self, frames: pd.DataFrame) -> pd.DataFrame: | ||
# We do not pass the prediction column to the predict method of XGBoost | ||
# AutoML. | ||
frames.drop([self.predict_col], axis=1, inplace=True) | ||
predictions = self.model.predict(frames) | ||
predict_df = pd.DataFrame(predictions) | ||
# We need to rename the column of the output dataframe. For this we | ||
# shall rename it to the column name same as that of the predict column | ||
# passed to EVA query. | ||
predict_df.rename(columns={0: self.predict_col}, inplace=True) | ||
return predict_df | ||
|
||
def to_device(self, device: str): | ||
# TODO figure out how to control the GPU for ludwig models | ||
return self |
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