Uploaded by Bilal El Shal

CIV E 779 Machine Learning for Engineers - Assignment 1

advertisement
CIV E 779 Machine Learning for Engineers - Assignment 1
September 8, 2023
CIV E 779 Machine Learning for Engineers - Assignment 1
Instructor: Dr. Qipei (Gavin) Mei (qipei.mei@ualberta.ca)
Student Name:
CCID:
1
1. Python Basics [10 Marks]
1.1 [5 Marks] Create a function called check_divisibility and show the output of n=30. The
function should do the following: Given an integer n, return a list called answer where:
answer[i] == “Divisible by 3 and 5” if i is divisible by 3 and 5.
answer[i] == “Divisible by 3” if i is divisible by 3 only.
answer[i] == “Divisible by 5” if i is divisible by 5 only.
answer[i] == i (as a string) if none of the above conditions are true.
For example: + Input: n = 5
Output: [“1”,“2”,“Divisible by 3”,“4”,“Divisible by 5”]
• Input: n = 15
Output: [“1”,“2”,“Divisible by 3”,“4”,“Divisible by 5”,“Divisible by 3”,“7”,“8”,“Divisible by
3”,“Divisible by 5”,“11”,“Divisible by 3”,“13”,“14”,“Divisible by 3 and 5”]
[96]: # Define the function check_divisibility
# TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
# Print check_divisibility(30)
# TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
1.2 [5 Marks] Please use the library matplotlib to regenerate the figure in this link as closely as
possible. You should add the exact same title, x/y labels, data ranges for x and y axes, and grid
lines. You should adjust the bar width (1.5), colors (green and red) and line style (dashed line for
the trendline) to match the provided figure. Don’t worry about the font, font size or resolution.
1
The data points for the figure are fomulated in the table below:
Strenth
Frequency
Y value of trendline (red line)
20
22
24
26
28
30
32
34
36
38
40
42
44
0
2
3
6
11
22
30
24
16
11
4
2
1
0.25
1
3.2
8
15.7
24.2
29.2
27.7
20.6
12
5.5
2
0.6
[97]: import matplotlib.pyplot as plt
# TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2
2. Matrix operations in Python [10 Marks]
Given two matrices,
5 2 1
⎡
𝐴 = ⎢3 1 2 ⎤
⎥
0
4
1
⎦
⎣
1 −5 0
⎡
𝐵 = ⎢−5 6 −3⎤
⎥
0
−3
2
⎣
⎦
Use the package numpy to do the following:
2.1 [0.5 Mark] Create two numpy arrays to store matrices A and B
[98]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.2 [0.5 Mark] Calculate the transpose of A
2
[99]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.3 [0.5 Mark] Calculate the trace of A
[100]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.4 [0.5 Mark] Calculate the rank of A
[101]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.5 [1 Mark] Calculate the inverse of A
[102]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.6 [1 Mark] Calculate the determinant of A
[103]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.7 [1 Mark] Calculate the addition of A and B
[104]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.8 [1 Mark] Calculate the multiplication of A and B
[105]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.9 [2 Marks] Find out whether the matrix B is a orthorgonal matrix or not
3
[106]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
2.10 [2 Marks] Find out whether the matrix B is positive definite or not. Hint: a matrix is postive
definite if all the eigenvalues are positive.
[107]: # TODO: Please provide your answers here. You can add more cells for code or␣
↪texts if needed.
# Don't delete these two comments so that it would be easier for me to locate␣
↪your answers.
4
Download