-
Notifications
You must be signed in to change notification settings - Fork 264
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
Starting the change for XGBoost integration into EVADb. #1232
Merged
+205
−11
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4aab6d
Starting the change for XGBoost integration into EVADb.
8d38c73
Fixing minor things
81264f8
Setup dependency
xzdandy 42f3b40
Adding the documentation for XGBoost
58ffb86
Adding entry in toc.yml
8e1bd05
Addressing Andy's comments on the change.
37c94f8
Adding parameter for regression metric and time limit.
85033c3
Passing prediction column from handler to the model .py files.
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
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
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.
We need add documentation on all the parameters XGBoost support. time_limit and metric are the two parameters we support now.