Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"source": [
"import azureml.core\n",
"\n",
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion contrib/fairness/fairlearn-azureml-mitigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dependencies:
- fairlearn>=0.6.2
- joblib
- liac-arff
- raiwidgets~=0.7.0
- raiwidgets~=0.11.0
2 changes: 1 addition & 1 deletion contrib/fairness/upload-fairness-dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dependencies:
- fairlearn>=0.6.2
- joblib
- liac-arff
- raiwidgets~=0.7.0
- raiwidgets~=0.11.0
4 changes: 2 additions & 2 deletions how-to-use-azureml/automated-machine-learning/automl_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ dependencies:

- pip:
# Required packages for AzureML execution, history, and data preparation.
- azureml-widgets~=1.34.0
- azureml-widgets~=1.35.0
- pytorch-transformers==1.0.0
- spacy==2.1.8
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.34.0/validated_win32_requirements.txt [--no-deps]
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.35.0/validated_win32_requirements.txt [--no-deps]
- arch==4.14
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ dependencies:

- pip:
# Required packages for AzureML execution, history, and data preparation.
- azureml-widgets~=1.34.0
- azureml-widgets~=1.35.0
- pytorch-transformers==1.0.0
- spacy==2.1.8
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.34.0/validated_linux_requirements.txt [--no-deps]
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.35.0/validated_linux_requirements.txt [--no-deps]
- arch==4.14
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ dependencies:

- pip:
# Required packages for AzureML execution, history, and data preparation.
- azureml-widgets~=1.34.0
- azureml-widgets~=1.35.0
- pytorch-transformers==1.0.0
- spacy==2.1.8
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.34.0/validated_darwin_requirements.txt [--no-deps]
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.35.0/validated_darwin_requirements.txt [--no-deps]
- arch==4.14
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

try:
import conda
except:
except Exception:
print('Failed to import conda.')
print('This setup is usually run from the base conda environment.')
print('You can activate the base environment using the command "conda activate base"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down Expand Up @@ -703,7 +703,7 @@
"from azureml.core.webservice import AciWebservice\n",
"from azureml.core.model import Model\n",
"\n",
"inference_config = InferenceConfig(entry_script=script_file_name)\n",
"inference_config = InferenceConfig(environment = best_run.get_environment(), entry_script=script_file_name)\n",
"\n",
"aciconfig = AciWebservice.deploy_configuration(cpu_cores = 2, \n",
" memory_gb = 2, \n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
model = Model(ws, args.model_name)
last_train_time = model.created_time
print("Model was last trained on {0}.".format(last_train_time))
except Exception as e:
except Exception:
print("Could not get last model train time.")
last_train_time = datetime.min.replace(tzinfo=pytz.UTC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,10 @@
"""

import argparse
import pandas as pd
import numpy as np
from azureml.core import Dataset, Run
from azureml.automl.core.shared.constants import TimeSeriesInternal
from sklearn.externals import joblib
from pandas.tseries.frequencies import to_offset


def align_outputs(y_predicted, X_trans, X_test, y_test, target_column_name,
predicted_column_name='predicted',
horizon_colname='horizon_origin'):
"""
Demonstrates how to get the output aligned to the inputs
using pandas indexes. Helps understand what happened if
the output's shape differs from the input shape, or if
the data got re-sorted by time and grain during forecasting.

Typical causes of misalignment are:
* we predicted some periods that were missing in actuals -> drop from eval
* model was asked to predict past max_horizon -> increase max horizon
* data at start of X_test was needed for lags -> provide previous periods
"""

if (horizon_colname in X_trans):
df_fcst = pd.DataFrame({predicted_column_name: y_predicted,
horizon_colname: X_trans[horizon_colname]})
else:
df_fcst = pd.DataFrame({predicted_column_name: y_predicted})

# y and X outputs are aligned by forecast() function contract
df_fcst.index = X_trans.index

# align original X_test to y_test
X_test_full = X_test.copy()
X_test_full[target_column_name] = y_test

# X_test_full's index does not include origin, so reset for merge
df_fcst.reset_index(inplace=True)
X_test_full = X_test_full.reset_index().drop(columns='index')
together = df_fcst.merge(X_test_full, how='right')

# drop rows where prediction or actuals are nan
# happens because of missing actuals
# or at edges of time due to lags/rolling windows
clean = together[together[[target_column_name,
predicted_column_name]].notnull().all(axis=1)]
return(clean)


parser = argparse.ArgumentParser()
parser.add_argument(
'--target_column_name', type=str, dest='target_column_name',
Expand All @@ -77,13 +32,25 @@ def align_outputs(y_predicted, X_trans, X_test, y_test, target_column_name,

# generate forecast
fitted_model = joblib.load('model.pkl')
y_predictions, X_trans = fitted_model.forecast(X_test)

# align output
df_all = align_outputs(y_predictions, X_trans, X_test, y_test, target_column_name)
# We have default quantiles values set as below(95th percentile)
quantiles = [0.025, 0.5, 0.975]
predicted_column_name = 'predicted'
PI = 'prediction_interval'
fitted_model.quantiles = quantiles
pred_quantiles = fitted_model.forecast_quantiles(X_test)
pred_quantiles[PI] = pred_quantiles[[min(quantiles), max(quantiles)]].apply(lambda x: '[{}, {}]'.format(x[0],
x[1]), axis=1)
X_test[target_column_name] = y_test
X_test[PI] = pred_quantiles[PI]
X_test[predicted_column_name] = pred_quantiles[0.5]
# drop rows where prediction or actuals are nan
# happens because of missing actuals
# or at edges of time due to lags/rolling windows
clean = X_test[X_test[[target_column_name,
predicted_column_name]].notnull().all(axis=1)]

file_name = 'outputs/predictions.csv'
export_csv = df_all.to_csv(file_name, header=True, index=False) # added Index
export_csv = clean.to_csv(file_name, header=True, index=False) # added Index

# Upload the predictions into artifacts
run.upload_file(name=file_name, path_or_stream=file_name)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"This notebook was created using version 1.34.0 of the Azure ML SDK\")\n",
"print(\"This notebook was created using version 1.35.0 of the Azure ML SDK\")\n",
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
]
},
Expand Down
Loading