Skip to content

CO3519 Artificial Intelligence


LectureΒΆ

CO3519 Lecture 1 - Introduction To Artificial Intelligence


Lab DocumentsΒΆ

CO3519 Lab 1.pdf


Lab TasksΒΆ

Task 1 - Warm Up Exercise

β€’ Please follow this link where you will find PYTHON EXERCISE under PYTHON EXAMPLES. This exercise will help you get prepare for the lab’s sessions, Tasks, assignments, etc.

β€’ In this exercise, you will get start from very basic and easy questions and you must choose the right answer from the choices. (For instance, Look figure at below figure.) β€’ You will also see the correct answers for these questions. (For instance, look at Figure 2.)

Task 2 - Start with Google Colab

Please follow this link and go through these pages while working.
β€’ Page 3 to 7
β€’ Page 11 to 13
β€’ Page 23 to 24
β€’ Page 36

Mistake Made During Completion

Pages misunderstood for the section numbers. Having checked the content on the pages suggested, covered all basis.

Task 3 - Python with NumPy and important DataTypes

Please follow this [link] as follows:
β€’ Introduction (skip)
β€’ Basics of Python (skip)
β€’ NumPy - Arrays, DataTypes, Array Math and Matplotlib


Lab WorkΒΆ

Starting with Google CollabΒΆ

Google Collab Tutorial

Sections 3 to 7ΒΆ

  • Google Colab uses Google Drive

Creating a New NotebookΒΆ

Accessing Google Colab
- Create NEW PYTHON 3 NOTEBOOK
- The notebook interface is similar to the one provided by Jupyter

Runtime

The time difference between the two outputs is now exactly 5 seconds.

Documenting CodeΒΆ

  • Python comments
  • Colab Text cells support the LaTex language for mathematic representations
  • Text cells are formatted using markdown

Saving WorkΒΆ

  • Can either be saved to google drive, a file, or GitHub

Invoking System CommandsΒΆ

Quote

Jupyter includes shortcuts for many common system operations

message = 'A Great Example!'
greeting = !echo -e '$message'
greeting

---OUTPUT---
['A Great Example!']

Note

  • WGet is also supported.
  • Drive content can be accessed with the directory /content/drive/My Drive/app/

For Other System CommandsΒΆ

Note

!ls /bin

Sections 11 - 13ΒΆ

Magic CellsΒΆ

%ldir

---OUTPUT---
drwxr-xr-x 3 root 4096 Jun 20 10:05 drive/ 
drwxr-xr-x 1 root 4096 May 31 16:17 sample_data/

HTML CellsΒΆ

%%html

<title>Hello World!</title>

For Other Magic Cells Supported ListΒΆ

!lsmagic

Adding FormsΒΆ

Right clicking on a code cell allows a form to be added allowing for easy user input at runtime.

Installing ML (Machine Learning) LibrariesΒΆ

!pip install

OR
!apt-get install

KerasΒΆ
!pip install -q keras
PyTorchΒΆ
!pip3 install torch torchvision
MxNetΒΆ
!apt install libnvrtc8.0
!pip install mxnet-cu80
OpenCVΒΆ
!apt get -qq install -y libsm6 libext6 && pip install -q -U opencv-python
XGBoostΒΆ
!pip install -q xboost==0.4a30
GraphVizΒΆ
!apt-get -qq install graphviz && pip install -q pydot

Python with NumPy & Important Data TypesΒΆ

NumPy is the core library for scientific computing in Python.

Importing PackageΒΆ

import numpy as np

Importing the NumPy package.

ArraysΒΆ

A NumPy array is basically a table (or grid) of numbers that are all the same data type (for example, all integers or all floats).

  • Each value in the array can be located using indexes β€” numbers that tell you where the value is along each axis (like row and column numbers in a spreadsheet).
  • The number of axes an array has (for example, 1D, 2D, 3D, etc.) is called its rank or number of dimensions.
  • The shape of the array is a tuple (a list of numbers in parentheses) that tells you how big the array is in each dimension.
    a = np.array([1, 2, 3])
    

    One Dimensional NumPy Array
    b = np.array([[1,2,3],[1,2,3]])
    

    Two Dimensional NumPy Array

NumPy Functions to Create ArraysΒΆ

a = np.zeros((2,2))

Creates array of all zeros
a = np.ones((1,2))

Creates array of all ones
a = np.full((2, 2), 7)

Create a consistent array

Assigning DataTypesΒΆ

x = np.array([1,2]) # Let NumPy Choose DataType
y = np.array([1.0, 1.0]) # Let NumPy Choose DataType
z = np.array([1, 2], dtype.np.int64) # Forcing Array To 64-bit Integer DataType

print(x.dtype, y.dtype, z.dtype)

MatplotlibΒΆ

Importing PackageΒΆ

import matplotlib.pyplot as plt
%matplotlib inline #iPython special command to display plots inline

PlottingΒΆ

# Compute the x and y coordinates for points on a sign curve
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)

# Plot points
plt.plot(x,y)

Add TitleΒΆ

plt.title('TITLE')

Add LegendΒΆ

plt.legend(['Sine', 'Cosine']) # Colour Key for chart

Add X & Y AxisΒΆ

plt.xlabel('x axis label')
plt.ylabel('y axis label')

CO3519 Lab 2