-
Notifications
You must be signed in to change notification settings - Fork 729
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
Support multivarient in autots #2936
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e91786
upgrade xgboost to 1.2
dding3 d682618
Merge branch 'master' of https://github.com/intel-analytics/analytics…
dding3 88446a4
Merge branch 'master' of https://github.com/intel-analytics/analytics…
dding3 6d7e42a
Merge branch 'master' of https://github.com/intel-analytics/analytics…
dding3 78e63eb
support multiple varient
dding3 5ab0e5b
add example
dding3 5c377e2
code clean
dding3 ce4f141
fix comments
dding3 117525e
fix ut
dding3 ebaa651
fix ut
dding3 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
93 changes: 93 additions & 0 deletions
93
pyzoo/zoo/zouwu/use-case/network_traffic/network_traffic_autots_multivariant_example.py
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,93 @@ | ||
def get_drop_dates_and_len(df, allow_missing_num=3): | ||
""" | ||
Find missing values and get records to drop | ||
""" | ||
missing_num = df.total.isnull().astype(int).groupby(df.total.notnull().astype(int).cumsum()).sum() | ||
drop_missing_num = missing_num[missing_num > allow_missing_num] | ||
drop_datetimes = df.iloc[drop_missing_num.index].index | ||
drop_len = drop_missing_num.values | ||
return drop_datetimes, drop_len | ||
|
||
def rm_missing_weeks(start_dts, missing_lens, df): | ||
""" | ||
Drop weeks that contains more than 3 consecutive missing values. | ||
If consecutive missing values across weeks, we remove all the weeks. | ||
""" | ||
for start_time, l in zip(start_dts, missing_lens): | ||
start = start_time - pd.Timedelta(days=start_time.dayofweek) | ||
start = start.replace(hour=0, minute=0, second=0) | ||
start_week_end = start + pd.Timedelta(days=6) | ||
start_week_end = start_week_end.replace(hour=22, minute=0, second=0) | ||
|
||
end_time = start_time + l*pd.Timedelta(hours=2) | ||
if start_week_end < end_time: | ||
end = end_time + pd.Timedelta(days=6-end_time.dayofweek) | ||
end = end.replace(hour=22, minute=0, second=0) | ||
else: | ||
end = start_week_end | ||
df = df.drop(df[start:end].index) | ||
return df | ||
|
||
import os | ||
import numpy as np | ||
import pandas as pd | ||
|
||
raw_df = pd.read_csv("data/data.csv") | ||
|
||
df = pd.DataFrame(pd.to_datetime(raw_df.StartTime)) | ||
df['AvgRate'] = raw_df.AvgRate.apply(lambda x: float(x[:-4]) if x.endswith("Mbps") else float(x[:-4]) * 1000) | ||
df["total"] = raw_df["total"] | ||
df.set_index("StartTime", inplace=True) | ||
full_idx = pd.date_range(start=df.index.min(), end=df.index.max(), freq='2H') | ||
df = df.reindex(full_idx) | ||
drop_dts, drop_len = get_drop_dates_and_len(df) | ||
df = rm_missing_weeks(drop_dts, drop_len, df) | ||
df.ffill(inplace=True) | ||
df.index.name = "datetime" | ||
df = df.reset_index() | ||
|
||
from zoo import init_spark_on_local | ||
from zoo.ray import RayContext | ||
sc = init_spark_on_local(cores=4, spark_log_level="INFO") | ||
ray_ctx = RayContext(sc=sc, object_store_memory="1g") | ||
ray_ctx.init() | ||
|
||
from zoo.zouwu.autots.forecast import AutoTSTrainer | ||
from zoo.automl.config.recipe import * | ||
|
||
trainer = AutoTSTrainer(dt_col="datetime", | ||
target_col=["AvgRate", "total"], | ||
horizon=1, | ||
extra_features_col=None) | ||
|
||
look_back = (36, 84) | ||
from zoo.automl.common.util import train_val_test_split | ||
train_df, val_df, test_df = train_val_test_split(df, | ||
val_ratio=0.1, | ||
test_ratio=0.1, | ||
look_back=look_back[0]) | ||
|
||
ts_pipeline = trainer.fit(train_df, val_df, | ||
recipe=MTNetGridRandomRecipe( | ||
num_rand_samples=1, | ||
time_step=[12], | ||
long_num=[6], | ||
ar_size=[6], | ||
cnn_height=[4], | ||
cnn_hid_size=[32], | ||
training_iteration=1, | ||
epochs=20, | ||
batch_size=[1024]), | ||
metric="mse") | ||
|
||
ts_pipeline.internal.config | ||
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. You may want to print out the result or this might be a useless line. |
||
pred_df = ts_pipeline.predict(test_df) | ||
|
||
mse, smape = ts_pipeline.evaluate(test_df, metrics=["mse", "smape"]) | ||
print("Evaluate: the mean square error is", mse) | ||
print("Evaluate: the smape value is", smape) | ||
|
||
ray_ctx.stop() | ||
sc.stop() | ||
|
||
|
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 can use
init_orca_context()
instead.