Skip to content

Commit 5775f8a

Browse files
committed
update samples from Release-70 as a part of SDK release
1 parent aae823e commit 5775f8a

File tree

56 files changed

+1872
-1642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1872
-1642
lines changed

configuration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"source": [
104104
"import azureml.core\n",
105105
"\n",
106-
"print(\"This notebook was created using version 1.15.0 of the Azure ML SDK\")\n",
106+
"print(\"This notebook was created using version 1.16.0 of the Azure ML SDK\")\n",
107107
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
108108
]
109109
},

contrib/fairness/fairlearn-azureml-mitigation.ipynb

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282
"from sklearn import svm\n",
8383
"from sklearn.preprocessing import LabelEncoder, StandardScaler\n",
8484
"from sklearn.linear_model import LogisticRegression\n",
85-
"import pandas as pd\n",
86-
"import shap"
85+
"import pandas as pd"
8786
]
8887
},
8988
{
@@ -99,8 +98,12 @@
9998
"metadata": {},
10099
"outputs": [],
101100
"source": [
102-
"X_raw, Y = shap.datasets.adult()\n",
103-
"X_raw[\"Race\"].value_counts().to_dict()"
101+
"from sklearn.datasets import fetch_openml\n",
102+
"data = fetch_openml(data_id=1590, as_frame=True)\n",
103+
"X_raw = data.data\n",
104+
"Y = (data.target == '>50K') * 1\n",
105+
"\n",
106+
"X_raw[\"race\"].value_counts().to_dict()"
104107
]
105108
},
106109
{
@@ -116,9 +119,13 @@
116119
"metadata": {},
117120
"outputs": [],
118121
"source": [
119-
"A = X_raw[['Sex','Race']]\n",
120-
"X = X_raw.drop(labels=['Sex', 'Race'],axis = 1)\n",
121-
"X = pd.get_dummies(X)\n",
122+
"A = X_raw[['sex','race']]\n",
123+
"X = X_raw.drop(labels=['sex', 'race'],axis = 1)\n",
124+
"X_dummies = pd.get_dummies(X)\n",
125+
"\n",
126+
"sc = StandardScaler()\n",
127+
"X_scaled = sc.fit_transform(X_dummies)\n",
128+
"X_scaled = pd.DataFrame(X_scaled, columns=X_dummies.columns)\n",
122129
"\n",
123130
"\n",
124131
"le = LabelEncoder()\n",
@@ -139,7 +146,7 @@
139146
"outputs": [],
140147
"source": [
141148
"from sklearn.model_selection import train_test_split\n",
142-
"X_train, X_test, Y_train, Y_test, A_train, A_test = train_test_split(X_raw, \n",
149+
"X_train, X_test, Y_train, Y_test, A_train, A_test = train_test_split(X_scaled, \n",
143150
" Y, \n",
144151
" A,\n",
145152
" test_size = 0.2,\n",
@@ -150,18 +157,7 @@
150157
"X_train = X_train.reset_index(drop=True)\n",
151158
"A_train = A_train.reset_index(drop=True)\n",
152159
"X_test = X_test.reset_index(drop=True)\n",
153-
"A_test = A_test.reset_index(drop=True)\n",
154-
"\n",
155-
"# Improve labels\n",
156-
"A_test.Sex.loc[(A_test['Sex'] == 0)] = 'female'\n",
157-
"A_test.Sex.loc[(A_test['Sex'] == 1)] = 'male'\n",
158-
"\n",
159-
"\n",
160-
"A_test.Race.loc[(A_test['Race'] == 0)] = 'Amer-Indian-Eskimo'\n",
161-
"A_test.Race.loc[(A_test['Race'] == 1)] = 'Asian-Pac-Islander'\n",
162-
"A_test.Race.loc[(A_test['Race'] == 2)] = 'Black'\n",
163-
"A_test.Race.loc[(A_test['Race'] == 3)] = 'Other'\n",
164-
"A_test.Race.loc[(A_test['Race'] == 4)] = 'White'"
160+
"A_test = A_test.reset_index(drop=True)"
165161
]
166162
},
167163
{
@@ -251,7 +247,7 @@
251247
"outputs": [],
252248
"source": [
253249
"sweep.fit(X_train, Y_train,\n",
254-
" sensitive_features=A_train.Sex)\n",
250+
" sensitive_features=A_train.sex)\n",
255251
"\n",
256252
"predictors = sweep._predictors"
257253
]
@@ -274,9 +270,9 @@
274270
" classifier = lambda X: m.predict(X)\n",
275271
" \n",
276272
" error = ErrorRate()\n",
277-
" error.load_data(X_train, pd.Series(Y_train), sensitive_features=A_train.Sex)\n",
273+
" error.load_data(X_train, pd.Series(Y_train), sensitive_features=A_train.sex)\n",
278274
" disparity = DemographicParity()\n",
279-
" disparity.load_data(X_train, pd.Series(Y_train), sensitive_features=A_train.Sex)\n",
275+
" disparity.load_data(X_train, pd.Series(Y_train), sensitive_features=A_train.sex)\n",
280276
" \n",
281277
" errors.append(error.gamma(classifier)[0])\n",
282278
" disparities.append(disparity.gamma(classifier).max())\n",
@@ -440,7 +436,7 @@
440436
"metadata": {},
441437
"outputs": [],
442438
"source": [
443-
"sf = { 'sex': A_test.Sex, 'race': A_test.Race }\n",
439+
"sf = { 'sex': A_test.sex, 'race': A_test.race }\n",
444440
"\n",
445441
"from fairlearn.metrics._group_metric_set import _create_group_metric_set\n",
446442
"\n",

contrib/fairness/fairlearn-azureml-mitigation.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ dependencies:
55
- azureml-contrib-fairness
66
- fairlearn==0.4.6
77
- joblib
8-
- shap

contrib/fairness/upload-fairness-dashboard.ipynb

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282
"from sklearn import svm\n",
8383
"from sklearn.preprocessing import LabelEncoder, StandardScaler\n",
8484
"from sklearn.linear_model import LogisticRegression\n",
85-
"import pandas as pd\n",
86-
"import shap"
85+
"import pandas as pd"
8786
]
8887
},
8988
{
@@ -99,7 +98,10 @@
9998
"metadata": {},
10099
"outputs": [],
101100
"source": [
102-
"X_raw, Y = shap.datasets.adult()"
101+
"from sklearn.datasets import fetch_openml\n",
102+
"data = fetch_openml(data_id=1590, as_frame=True)\n",
103+
"X_raw = data.data\n",
104+
"Y = (data.target == '>50K') * 1"
103105
]
104106
},
105107
{
@@ -115,7 +117,7 @@
115117
"metadata": {},
116118
"outputs": [],
117119
"source": [
118-
"print(X_raw[\"Race\"].value_counts().to_dict())"
120+
"print(X_raw[\"race\"].value_counts().to_dict())"
119121
]
120122
},
121123
{
@@ -134,9 +136,9 @@
134136
"metadata": {},
135137
"outputs": [],
136138
"source": [
137-
"A = X_raw[['Sex','Race']]\n",
138-
"X = X_raw.drop(labels=['Sex', 'Race'],axis = 1)\n",
139-
"X = pd.get_dummies(X)"
139+
"A = X_raw[['sex','race']]\n",
140+
"X = X_raw.drop(labels=['sex', 'race'],axis = 1)\n",
141+
"X_dummies = pd.get_dummies(X)"
140142
]
141143
},
142144
{
@@ -153,8 +155,8 @@
153155
"outputs": [],
154156
"source": [
155157
"sc = StandardScaler()\n",
156-
"X_scaled = sc.fit_transform(X)\n",
157-
"X_scaled = pd.DataFrame(X_scaled, columns=X.columns)\n",
158+
"X_scaled = sc.fit_transform(X_dummies)\n",
159+
"X_scaled = pd.DataFrame(X_scaled, columns=X_dummies.columns)\n",
158160
"\n",
159161
"le = LabelEncoder()\n",
160162
"Y = le.fit_transform(Y)"
@@ -185,18 +187,7 @@
185187
"X_train = X_train.reset_index(drop=True)\n",
186188
"A_train = A_train.reset_index(drop=True)\n",
187189
"X_test = X_test.reset_index(drop=True)\n",
188-
"A_test = A_test.reset_index(drop=True)\n",
189-
"\n",
190-
"# Improve labels\n",
191-
"A_test.Sex.loc[(A_test['Sex'] == 0)] = 'female'\n",
192-
"A_test.Sex.loc[(A_test['Sex'] == 1)] = 'male'\n",
193-
"\n",
194-
"\n",
195-
"A_test.Race.loc[(A_test['Race'] == 0)] = 'Amer-Indian-Eskimo'\n",
196-
"A_test.Race.loc[(A_test['Race'] == 1)] = 'Asian-Pac-Islander'\n",
197-
"A_test.Race.loc[(A_test['Race'] == 2)] = 'Black'\n",
198-
"A_test.Race.loc[(A_test['Race'] == 3)] = 'Other'\n",
199-
"A_test.Race.loc[(A_test['Race'] == 4)] = 'White'"
190+
"A_test = A_test.reset_index(drop=True)"
200191
]
201192
},
202193
{
@@ -380,7 +371,7 @@
380371
"metadata": {},
381372
"outputs": [],
382373
"source": [
383-
"sf = { 'Race': A_test.Race, 'Sex': A_test.Sex }\n",
374+
"sf = { 'Race': A_test.race, 'Sex': A_test.sex }\n",
384375
"\n",
385376
"from fairlearn.metrics._group_metric_set import _create_group_metric_set\n",
386377
"\n",
@@ -499,7 +490,7 @@
499490
"name": "python",
500491
"nbconvert_exporter": "python",
501492
"pygments_lexer": "ipython3",
502-
"version": "3.6.8"
493+
"version": "3.6.10"
503494
}
504495
},
505496
"nbformat": 4,

contrib/fairness/upload-fairness-dashboard.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ dependencies:
55
- azureml-contrib-fairness
66
- fairlearn==0.4.6
77
- joblib
8-
- shap

how-to-use-azureml/automated-machine-learning/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ The main code of the file must be indented so that it is under this condition.
173173
## automl_setup fails
174174
1. On Windows, make sure that you are running automl_setup from an Anconda Prompt window rather than a regular cmd window. You can launch the "Anaconda Prompt" window by hitting the Start button and typing "Anaconda Prompt". If you don't see the application "Anaconda Prompt", you might not have conda or mini conda installed. In that case, you can install it [here](https://conda.io/miniconda.html)
175175
2. Check that you have conda 64-bit installed rather than 32-bit. You can check this with the command `conda info`. The `platform` should be `win-64` for Windows or `osx-64` for Mac.
176-
3. Check that you have conda 4.4.10 or later. You can check the version with the command `conda -V`. If you have a previous version installed, you can update it using the command: `conda update conda`.
176+
3. Check that you have conda 4.7.8 or later. You can check the version with the command `conda -V`. If you have a previous version installed, you can update it using the command: `conda update conda`.
177177
4. On Linux, if the error is `gcc: error trying to exec 'cc1plus': execvp: No such file or directory`, install build essentials using the command `sudo apt-get install build-essential`.
178178
5. Pass a new name as the first parameter to automl_setup so that it creates a new conda environment. You can view existing conda environments using `conda env list` and remove them with `conda env remove -n <environmentname>`.
179179

how-to-use-azureml/automated-machine-learning/automl_env.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python>=3.5.2,<3.6.8
77
- nb_conda
88
- matplotlib==2.1.0
9-
- numpy~=1.18.0
9+
- numpy==1.18.5
1010
- cython
1111
- urllib3<1.24
1212
- scipy==1.4.1
@@ -24,5 +24,5 @@ dependencies:
2424
- pytorch-transformers==1.0.0
2525
- spacy==2.1.8
2626
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
27-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.15.0/validated_win32_requirements.txt [--no-deps]
27+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.16.0/validated_win32_requirements.txt [--no-deps]
2828

how-to-use-azureml/automated-machine-learning/automl_env_linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python>=3.5.2,<3.6.8
77
- nb_conda
88
- matplotlib==2.1.0
9-
- numpy~=1.18.0
9+
- numpy==1.18.5
1010
- cython
1111
- urllib3<1.24
1212
- scipy==1.4.1
@@ -24,5 +24,5 @@ dependencies:
2424
- pytorch-transformers==1.0.0
2525
- spacy==2.1.8
2626
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
27-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.15.0/validated_linux_requirements.txt [--no-deps]
27+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.16.0/validated_linux_requirements.txt [--no-deps]
2828

how-to-use-azureml/automated-machine-learning/automl_env_mac.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- python>=3.5.2,<3.6.8
88
- nb_conda
99
- matplotlib==2.1.0
10-
- numpy~=1.18.0
10+
- numpy==1.18.5
1111
- cython
1212
- urllib3<1.24
1313
- scipy==1.4.1
@@ -25,4 +25,4 @@ dependencies:
2525
- pytorch-transformers==1.0.0
2626
- spacy==2.1.8
2727
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
28-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.15.0/validated_darwin_requirements.txt [--no-deps]
28+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.16.0/validated_darwin_requirements.txt [--no-deps]

how-to-use-azureml/automated-machine-learning/automl_setup.cmd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ set PIP_NO_WARN_SCRIPT_LOCATION=0
66

77
IF "%conda_env_name%"=="" SET conda_env_name="azure_automl"
88
IF "%automl_env_file%"=="" SET automl_env_file="automl_env.yml"
9+
SET check_conda_version_script="check_conda_version.py"
910

1011
IF NOT EXIST %automl_env_file% GOTO YmlMissing
1112

1213
IF "%CONDA_EXE%"=="" GOTO CondaMissing
1314

15+
IF NOT EXIST %check_conda_version_script% GOTO VersionCheckMissing
16+
17+
python "%check_conda_version_script%"
18+
IF errorlevel 1 GOTO ErrorExit:
19+
20+
SET replace_version_script="replace_latest_version.ps1"
21+
IF EXIST %replace_version_script% (
22+
powershell -file %replace_version_script% %automl_env_file%
23+
)
24+
1425
call conda activate %conda_env_name% 2>nul:
1526

1627
if not errorlevel 1 (
@@ -54,6 +65,10 @@ echo If you are running an older version of Miniconda or Anaconda,
5465
echo you can upgrade using the command: conda update conda
5566
goto End
5667

68+
:VersionCheckMissing
69+
echo File %check_conda_version_script% not found.
70+
goto End
71+
5772
:YmlMissing
5873
echo File %automl_env_file% not found.
5974

how-to-use-azureml/automated-machine-learning/automl_setup_linux.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CONDA_ENV_NAME=$1
44
AUTOML_ENV_FILE=$2
55
OPTIONS=$3
66
PIP_NO_WARN_SCRIPT_LOCATION=0
7+
CHECK_CONDA_VERSION_SCRIPT="check_conda_version.py"
78

89
if [ "$CONDA_ENV_NAME" == "" ]
910
then
@@ -20,6 +21,18 @@ if [ ! -f $AUTOML_ENV_FILE ]; then
2021
exit 1
2122
fi
2223

24+
if [ ! -f $CHECK_CONDA_VERSION_SCRIPT ]; then
25+
echo "File $CHECK_CONDA_VERSION_SCRIPT not found"
26+
exit 1
27+
fi
28+
29+
python "$CHECK_CONDA_VERSION_SCRIPT"
30+
if [ $? -ne 0 ]; then
31+
exit 1
32+
fi
33+
34+
sed -i 's/AZUREML-SDK-VERSION/latest/' $AUTOML_ENV_FILE
35+
2336
if source activate $CONDA_ENV_NAME 2> /dev/null
2437
then
2538
echo "Upgrading existing conda environment" $CONDA_ENV_NAME

how-to-use-azureml/automated-machine-learning/automl_setup_mac.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CONDA_ENV_NAME=$1
44
AUTOML_ENV_FILE=$2
55
OPTIONS=$3
66
PIP_NO_WARN_SCRIPT_LOCATION=0
7+
CHECK_CONDA_VERSION_SCRIPT="check_conda_version.py"
78

89
if [ "$CONDA_ENV_NAME" == "" ]
910
then
@@ -20,6 +21,18 @@ if [ ! -f $AUTOML_ENV_FILE ]; then
2021
exit 1
2122
fi
2223

24+
if [ ! -f $CHECK_CONDA_VERSION_SCRIPT ]; then
25+
echo "File $CHECK_CONDA_VERSION_SCRIPT not found"
26+
exit 1
27+
fi
28+
29+
python "$CHECK_CONDA_VERSION_SCRIPT"
30+
if [ $? -ne 0 ]; then
31+
exit 1
32+
fi
33+
34+
sed -i '' 's/AZUREML-SDK-VERSION/latest/' $AUTOML_ENV_FILE
35+
2336
if source activate $CONDA_ENV_NAME 2> /dev/null
2437
then
2538
echo "Upgrading existing conda environment" $CONDA_ENV_NAME
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from distutils.version import LooseVersion
2+
import platform
3+
4+
try:
5+
import conda
6+
except:
7+
print('Failed to import conda.')
8+
print('This setup is usually run from the base conda environment.')
9+
print('You can activate the base environment using the command "conda activate base"')
10+
exit(1)
11+
12+
architecture = platform.architecture()[0]
13+
14+
if architecture != "64bit":
15+
print('This setup requires 64bit Anaconda or Miniconda. Found: ' + architecture)
16+
exit(1)
17+
18+
minimumVersion = "4.7.8"
19+
20+
versionInvalid = (LooseVersion(conda.__version__) < LooseVersion(minimumVersion))
21+
22+
if versionInvalid:
23+
print('Setup requires conda version ' + minimumVersion + ' or higher.')
24+
print('You can use the command "conda update conda" to upgrade conda.')
25+
26+
exit(versionInvalid)

how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"metadata": {},
106106
"outputs": [],
107107
"source": [
108-
"print(\"This notebook was created using version 1.15.0 of the Azure ML SDK\")\n",
108+
"print(\"This notebook was created using version 1.16.0 of the Azure ML SDK\")\n",
109109
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
110110
]
111111
},

0 commit comments

Comments
 (0)