-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
[pyspark] support a list of feature column names #8117
Conversation
@trivialfis @WeichenXu123 Could you help to review this PR? Thx |
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.
Thank you for the PR. Could you please:
- add tests
- Add a demo or test that shows how to use it with other spark ml utilities.
Done @trivialfis @WeichenXu123 |
for c in features_col_name: | ||
if isinstance(dataset.schema[c].dataType, DoubleType): | ||
feature_cols.append(col(c).cast(FloatType()).alias(c)) | ||
elif isinstance(dataset.schema[c].dataType, (FloatType, IntegralType)): |
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.
What's IntegralType type ? Do you mean IntegerType ?
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.
@trivialfis, could you correct me if xgboost supports IntegralType (Byte/Integer/Long/Short) ?
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.
Yes, sort of. XGBoost will convert the data to float internally.
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.
BTW, XGBoost can convert it on the fly without creating a copy of data.
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.
Thx @trivialfis, Yeah, if the type is short/byte, it will reduce the size of the shuffle write.
python-package/xgboost/spark/core.py
Outdated
@@ -341,6 +363,22 @@ def _validate_and_convert_feature_col_as_array_col(dataset, features_col_name): | |||
return features_array_col | |||
|
|||
|
|||
def _validate_and_convert_feature_col( |
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.
Is the function being used ?
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.
Thx, removed.
python-package/xgboost/spark/core.py
Outdated
pandas_df_iter, | ||
None, | ||
dmatrix_kwargs, | ||
pandas_df_iter, features_cols_names, dmatrix_kwargs |
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.
What if features_cols_names conflicts with label / weight / base_margin column name ?
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.
Thx, I tried, it worked, no exception happened.
|
the gpu dask tests may corrupt the whole gpu env
@trivialfis could you help to review again. Thx |
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.
Thank you for the PR! Some questions in the comments.
python-package/xgboost/spark/core.py
Outdated
feature_col_names = self.getOrDefault(self.features_cols) | ||
features_col = [] | ||
if ( | ||
len(feature_col_names) |
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.
This condition looks weird?
len(feature_col_names) > 0 >= len(...)
is it correct?
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.
yes. the pylint required this
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.
all(c in dataset.columns for c in feature_col_names)
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.
Done, I use another set way to check.
python-package/xgboost/spark/core.py
Outdated
select_cols = [features_array_col, label_col] | ||
select_cols = [label_col] | ||
features_cols_names = None | ||
if len(self.getOrDefault(self.features_cols)): |
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.
if len(self.getOrDefault(self.features_cols)): | |
if self.getOrDefault(self.features_cols): |
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.
Done, Thx
note to myself: need to update the linter script. |
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.
LGTM, leave one question though.
@trivialfis @wbo4958 |
@trivialfis @WeichenXu123 Thx for reviewing. |
This PR introduces a new Param storing a list of feature column names, so with it, users do not need to vectorize or create an array feature column beforehand, instead, they need to specify feature_col with a list of column names.
Eg,
why introduce this new parameter?
The internal of XGBoost is wrapping the feature columns into a vector or an array column on the JVM side, but it will unwrap the vector/array column into each feature column on the python side. So if we just pass each feature column, which can improve the performance.
But for now, there are some limitations that users must enable
use_gpu
when using this way and it may break some spark ml pipelines eg,OneVsRest