Practical Test

Opened: Thursday, 11 February 2021, 6:05 PM
Due: Thursday, 11 February 2021, 8:00 PM

Solve the four problems in the attached PDF file.

Submit your code in one pdf file.

Practical Test

 

 1. NumPy Arrays

Write a Python program that performs the following steps:

  1. Creates a three dimensional NumPy array (size: 2x3x4) of double-precision floating-point random numbers of standard normal distribution.
  2. Without using loops, finds the sum of items smaller than 0.

 

 2. pandas

The following code uses pandas-datareader package to access Yahoo Finance and download the stock prices and volumes for Apple (AAPL) and Tesla (TSLA).

import pandas as pd
import pandas_datareader.data as web
all_data = {ticker: web.get_data_yahoo(ticker) for ticker in ['AAPL', 'TSLA']}

Considering the adjusted closing price and volume of both companies, what is the total amount in dollars of their shares traded in January 2021?

 

 3. pandas - 2

Use pandas to read the attached file (Marks.xlsx). Then, for each of the last four columns, find the minimum, average, and maximum mark, without using the describe() method.

  

 4. Keras and Fashion MNIST

Complete the following code to build a sequential model of three full-connected hidden layers. Each hidden layer should be of 100 cells. Train your model on the train and validate sets for 5 epochs and evaluate its accuracy on the test set.

 

from tensorflow import keras

# Get the Fashion MNIST
fashion_mnist = keras.datasets.fashion_mnist
(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()

# Prepare the data train (55000), val (5000), test (10000)
Xv = X_train[:5000] / 255.
Xt = X_train[5000:] / 255.
yv, yt = y_train[:5000], y_train[5000:]
X_test = X_test / 255.

model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[28, 28]))

# Insert your code here

print('Accuracy:', score[1]*100)