-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ORCA] Add xshards example #5542
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ ray stop -f | |
cd "`dirname $0`" | ||
cd ../../tutorial/xshards | ||
|
||
echo "Running Xshards tests" | ||
echo "Running Xshards tests 1" | ||
|
||
#timer | ||
start=$(date "+%s") | ||
|
@@ -43,4 +43,25 @@ python tabular_playground_series.py | |
now=$(date "+%s") | ||
time1=$((now - start)) | ||
|
||
echo "Running Xshards tests time used: $time1 seconds" | ||
echo "Running Xshards tests 1 time used: $time1 seconds" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put timing at the end |
||
|
||
echo "Running Xshards tests 2" | ||
|
||
#timer | ||
start=$(date "+%s") | ||
|
||
if [ -f ${BIGDL_ROOT}/python/orca/tutorial/xshards/titanic.csv ] | ||
then | ||
echo "titanic.csv already exists" | ||
else | ||
wget -nv $FTP_URI/analytics-zoo-data/xshards/titanic.csv -P ${BIGDL_ROOT}/python/orca/tutorial/xshards/ | ||
fi | ||
|
||
python titanic.py | ||
|
||
rm -rf result | ||
|
||
now=$(date "+%s") | ||
time2=$((now - start)) | ||
|
||
echo "Running Xshards tests 1 time used: $time2 seconds" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# Copyright 2016 The BigDL Authors. | ||
# | ||
# 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. | ||
# | ||
# This example is adapted from | ||
# https://www.kaggle.com/code/chuanguy/titanic-data-processing-with-python-0-813/notebook | ||
|
||
from bigdl.orca import init_orca_context, stop_orca_context | ||
import bigdl.orca.data.pandas | ||
|
||
init_orca_context(cluster_mode="local", cores=4, memory="3g") | ||
|
||
file_path = "titanic.csv" | ||
data_shard = bigdl.orca.data.pandas.read_csv(file_path) | ||
|
||
# drop | ||
def drop_func(df): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop_passenger |
||
df = df.drop(['PassengerId'], axis=1) | ||
return df | ||
data_shard = data_shard.transform_shard(drop_func) | ||
|
||
|
||
# fillna, apply, replace, map | ||
def process_cabin(df): | ||
df['Cabin'] = df['Cabin'].fillna('X') | ||
df['Cabin'] = df['Cabin'].apply(lambda x: str(x)[0]) | ||
df['Cabin'] = df['Cabin'].replace(['A', 'D', 'E', 'T'], 'M') | ||
df['Cabin'] = df['Cabin'].replace(['B', 'C'], 'H') | ||
df['Cabin'] = df['Cabin'].replace(['F', 'G'], 'L') | ||
df['Cabin'] = df['Cabin'].map({'X': 0, 'L': 1, 'M': 2, 'H': 3}) | ||
df['Cabin'] = df['Cabin'].astype(int) | ||
return df | ||
data_shard = data_shard.transform_shard(process_cabin) | ||
|
||
|
||
# astype, loc | ||
def change_val(data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. encode |
||
data['Sex'] = data['Sex'].map({'female': 1, 'male': 0}) | ||
data['Pclass'] = data['Pclass'].map({1: 3, 2: 2, 3: 1}).astype(int) | ||
data.loc[data['Sex'] == 0, 'SexByPclass'] = data.loc[data['Sex'] == 0, 'Pclass'] | ||
data.loc[data['Sex'] == 1, 'SexByPclass'] = data.loc[data['Sex'] == 1, 'Pclass'] + 3 | ||
return data | ||
data_shard = data_shard.transform_shard(change_val) | ||
|
||
# save | ||
data_shard.save_pickle('./result') | ||
|
||
stop_orca_context() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra blank line |
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.
change the name to the example name