Azure - Machine - Learning - Studio - Uniosun - 2023.ipynb - Colaboratory-1
Azure - Machine - Learning - Studio - Uniosun - 2023.ipynb - Colaboratory-1
ipynb - Colaboratory
1. You want to create a model to predict sales of ice cream based on historic data that
includes daily ice cream sales totals and weather measurements. Which Azure service
should you use?
B. Azure Bot
C. Language
2. You are designing an AI application that uses images to detect cracks in car windshields
and warn drivers when a windshield should be repaired or replaced. What AI workload is
described?
A. Computer Vision
B. Anomaly Detection
3. A predictive app provides audio output for visually impaired users. Which principle of
Responsible AI is reflected here?
A. Transparency
B. Inclusiveness
C. Fairness
import pandas
!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-lear
!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-lear
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 1/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
data = {
'boot_size' : [ 39, 38, 37, 39, 38, 35, 37, 36, 35, 40,
40, 36, 38, 39, 42, 42, 36, 36, 35, 41,
42, 38, 37, 35, 40, 36, 35, 39, 41, 37,
35, 41, 39, 41, 42, 42, 36, 37, 37, 39,
42, 35, 36, 41, 41, 41, 39, 39, 35, 39
],
'harness_size': [ 58, 58, 52, 58, 57, 52, 55, 53, 49, 54,
59, 56, 53, 58, 57, 58, 56, 51, 50, 59,
59, 59, 55, 50, 55, 52, 53, 54, 61, 56,
55, 60, 57, 56, 61, 58, 53, 57, 57, 55,
60, 51, 52, 56, 55, 57, 58, 57, 51, 59
]
}
dataset = pandas.DataFrame(data)
(dataset)
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 2/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
boot_size harness_size
0 39 58
1 38 58
2 37 52
3 39 58
4 38 57
5 35 52
6 37 55
7 36 53
8 35 49
9 40 54
10 40 59
11 36 56
12 38 53
13 39 58
14 42 57
15 42 58
16 36 56
17 36 51
18 35 50
19 41 59
20 42 59
21 38 59
22 37 55
23 35 50
24 40 55
25 36 52
26 35 53
27 39 54
28 41 61
29 37 56
30 35 55
31 41 60
32 39 57
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 3/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
32 39 57
33 41 56
34 42 61
35 42 58
36 36 53
37 37 57
38 37 57
dataset = pandas.read_csv('doggy-boot-harness.csv')
39 39 55
40 42 60
(dataset)
41 35 51
42 36 52
43 41 56
44 41 55
45 41 57
46 39 58
47 39 57
48 35 51
49 39 59
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 4/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
0 39 58 male 12.0
1 38 58 male 9.6
2 37 52 female 8.6
3 39 58 male 10.2
4 38 57 male 7.8
5 35 52 female 4.4
6 37 55 female 6.0
7 36 53 female 14.2
8 35 49 male 13.2
9 40 54 female 15.2
10 40 59 male 3.6
11 36 56 male 10.0
12 38 53 female 7.0
13 39 58 male 12.4
14 42 57 male 7.4
15 42 58 male 12.0
16 36 56 male 11.4
17 36 51 female 5.0
18 35 50 female 15.2
19 41 59 male 11.4
20 42 59 female 6.6
21 38 59 male 9.6
22 37 55 female 7.8
23 35 50 male 6.4
24 40 55 female 8.8
25 36 52 female 13.2
26 35
print(dataset.harness_size) 53 female 13.2
del dataset["sex"]
del dataset["age_years"]
print(dataset.columns.values)
['boot_size' 'harness_size']
(dataset)
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 6/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
boot_size harness_size
0 39 58
1 38 58
2 37 52
3 39 58
4 38 57
5 35 52
6 37 55
7 36 53
8 35 49
9 40 54
10 40 59
11 36 56
12 38 53
13 39 58
14 42 57
15 42 58
16 36 56
17 36 51
18 35 50
19 41 59
20 42 59
21 38 59
22 37 55
23 35 50
24 40 55
25 36 52
26 35 53
27 39 54
28 41 61
29 37 56
30 35 55
31 41 60
32 39 57
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 7/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
32 39 57
33 41 56
34 42 61
35 42 58
36 36 53
37 37 57
38 37 57
39 39 55
40 42 60
41 35 51
42 36 52
43 41 56
44 41 55
45 41 57
46 39 58
47 39
print(dataset.head()) 57
48 35 51
boot_size harness_size
049 3939 5859
1 38 58
2 37 52
3 39 58
4 38 57
print(dataset.tail())
boot_size harness_size
45 41 57
46 39 58
47 39 57
48 35 51
49 39 59
print(is_small)
0 False
1 False
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 8/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
2 True
3 False
4 False
5 True
6 False
7 True
8 True
9 True
10 False
11 False
12 True
13 False
14 False
15 False
16 False
17 True
18 True
19 False
20 False
21 False
22 False
23 True
24 False
25 True
26 True
27 True
28 False
29 False
30 False
31 False
32 False
33 False
34 False
35 False
36 True
37 False
38 False
39 False
40 False
41 True
42 True
43 False
44 False
45 False
46 False
47 False
48 True
49 False
Name: harness_size, dtype: bool
data_from_small_dogs = dataset[is_small]
print(data_from_small_dogs)
boot_size harness_size
2 37 52
5 35 52
7 36 53
8 35 49
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipynb… 9/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
9 40 54
12 38 53
17 36 51
18 35 50
23 35 50
25 36 52
26 35 53
27 39 54
36 36 53
41 35 51
42 36 52
48 35 51
print(f"We now have {len(data_smaller_paws)} rows in our dataset. The last few rows are:")
data_smaller_paws.tail()
We now have 34 rows in our dataset. The last few rows are:
boot_size harness_size
42 36 52
46 39 58
47 39 57
48 35 51
49 39 59
import plotly.express
import graphing
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 10/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
39
38
boot_size
36
39
35
50 52 54 56 58
38
harness_size
boot_size
37
36
35
19.5 20 20.5
dataset['boot_size'].mean()
38.32
import pandas
!pip install statsmodels
!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-lear
!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-lear
data = pandas.read_csv('doggy-boot-harness.csv')
data.head()
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 11/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
0 39 58 male 12.0
1 38 58 male 9.6
2 37 52 female 8.6
import3statsmodels.formula.api
39 58as smf
male 10.2
4 38 57 male 7.8
model = smf.ols(formula = "boot_size ~ harness_size", data = data).fit()
print("Model trained!")
Model trained!
import joblib
model_filename = './avalanche_dog_boot_model.pkl'
joblib.dump(model, model_filename)
print("Model saved!")
Model saved!
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 12/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
model_loaded = joblib.load(model_filename)
# Load the model from file and print basic information about it
loaded_model = joblib.load(model_filename)
return predicted_boot_size
This returns a message for the customer that should be shown before
they complete their payment
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 13/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
# Round to the nearest whole number because we don't sell partial sizes
estimated_boot_size = int(round(estimated_boot_size))
KNOWLEDGE CHECK
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 14/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
A. The training data is used to make changes to the model. These changes help the model get
better at achieving the objective.
B. The training data is used to make changes to the objective. These changes help the objective
be more like the model.
C. The model is used to make changes to the training data. These changes help the training
data get better at achieving the objective.
sns.boxplot(dataset['harness_size']);
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 15/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
https://docs.google.com/spreadsheets/d/1Ku_Zpj8mXrrkYUsJBynQifTzKcKuCR4O/edit#gid=19
67990280
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn
import sklearn
Choose Files No file chosen Upload widget is only available when the cell has been
executed in the current browser session. Please rerun this cell to enable.
Saving AI Invasion In-Class Dataset xlsx to AI Invasion In-Class Dataset xlsx
import io
df = pd.read_excel(io.BytesIO(uploaded['AI_Invasion_In-Class_Dataset.xlsx']))
df.head()
Amount
Location Maker Model Year Colour (Million Type Distance_Km
₦)
Mercedes- Foreign
0 Abuja GLA 250 2015 Brown 14.50 50000.0
Benz Used
Nigerian
1 Abuja Hyundai Accent 2013 Red 1.55 NaN
Used
GX 460 Foreign
2 Lagos Lexus 2011 White 14.00 85000.0
Premium Used
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4487 entries, 0 to 4486
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 16/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
df.describe()
df.columns
df.isnull().sum()
Location 0
Maker 0
Model 0
Year 0
Colour 0
Amount (Million ₦) 0
Type 0
Distance_Km 1555
dtype: int64
mean_value = df["Distance_Km"].mean()
print(mean_value)
df["Distance_Km"].fillna(mean_value, inplace=True)
101038.32128240108
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 17/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
df.isnull().sum()
Location 0
Maker 0
Model 0
Year 0
Colour 0
Amount (Million ₦) 0
Type 0
Distance_Km 0
dtype: int64
cat_features = {
"Location",
"Model",
"Maker",
"Year",
"Colour",
"Type",
}
Amount (Million
Location Maker Year Colour Type Distance_Km
₦)
Mercedes- Foreign
0 Abuja 2015 Brown 14.50 50000.000000
Benz Used
Nigerian
1 Abuja Hyundai 2013 Red 1.55 101038.321282
Used
Foreign
2 Lagos Lexus 2011 White 14.00 85000.000000
Used
cat_features = ["Location","Maker","Year","Colour","Type"]
df.head()
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 19/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
Amount
Location Maker Year Colour (Million Type Distance_Km Location_cat
df.drop(["Location","Maker","Year","Colour", "Type"],
₦) axis=1, inplace=True)
df.head()
Mercedes- Foreign
0 Abuja 2015 Brown 14.50 50000.000000 0
Benz Used
Amount
(Million Distance_Km Location_cat Maker_cat Year_cat Colour_cat Type_cat
Nigerian
1 Abuja
₦) Hyundai 2013 Red 1.55 101038.321282 0
Used
0 14.50 50000.000000 0 26
Foreign 22 3 1
2 Lagos Lexus 2011 White 14.00 85000.000000 2
Used
1 1.55 101038.321282 0 14 20 14 2
2 14.00 85000.000000 2 23 18 17 1
3 4.95 101038.321282 2 23 18 6 1
▾ LinearRegression
LinearRegression()
reg.predict(X_test)
MAE 7.563289386706154
dt_reg = DecisionTreeRegressor()
dt_reg.fit(X_train, y_train)
y_pred = dt_reg.predict(X_test)
print("MAE",mean_absolute_error(y_test,y_pred))
MAE 5.057523970799307
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 20/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
sv_reg = SVR()
sv_reg.fit(X_train, y_train)
y_pred = sv_reg.predict(X_test)
print("MAE",mean_absolute_error(y_test,y_pred))
MAE 6.827446911476295
a = 3^2
b = int(4^2)
print(a == b)
False
4e² - 20e + 25 = 0
<ipython-input-8-d48b71a8ecc1>:3: SymPyDeprecationWarning:
See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-eq
for details.
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 21/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
saved_pin = 20221609
new_pin = input("Please enter your pin: ")
if int(new_pin) == saved_pin:
print("Pin was correctly entered, you are now logged in")
else:
print("You do not have permission to access this account")
x−y+3=0
x+y−5=0
x, y = symbols('x y')
eq1 = Eq(x - y + 3, 0)
eq2 = Eq(x + y - 5, 0)
{x: 1, y: 4}
x = 1
y = 4
p(x) = x4 - 4x2 + 3x
def p(x):
return x**4 - 4*x**2 + 3*x
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 22/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
-1 -6
0 0
2 6
3 54
4 204
import numpy as np
import matplotlib.pyplot as plt
plt.show()
x = symbols("x")
f = x**3 -4*x**2 +6*x -2
ans = diff(f, x)
ans
3x2 − 8x + 6
Question 3: ∫sinx dx
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 23/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
x = symbols('x')
f = sin(x)
integral = integrate(f, x)
integral
− cos (x)
sin (x2 − 5)
∫8x3 dx
2x4
09076425843
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 24/25
11/08/2023, 11:18 Azure_Machine_Learning_Studio_Uniosun_2023.ipynb - Colaboratory
https://colab.research.google.com/github/holatung/DSN-AI-INVASION-OSUN/blob/main/Azure_Machine_Learning_Studio_Uniosun_2023.ipyn… 25/25