0% found this document useful (0 votes)
14 views61 pages

Y12 CS - Week 24 - Learning Plan

Uploaded by

karlzhu313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views61 pages

Y12 CS - Week 24 - Learning Plan

Uploaded by

karlzhu313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

Week 24

Please do now! 
How many rows the table have?
How many columns does the table have?
What is the data type of the values stored under “Height”?
Database
• A database is a structured way to store data so that it can be retrieved
using queries
Table name Field Field name
Animals
Table Animal Length TopSpeed
Brown bear 2.48 21.7
Elk 1.4 45.1
Record Lion 2.8 49.7
Pig 0.9 10.9
8.3 Data Definition Language
(DDL) and Data Manipulation
Language (DML)
To Do List
SQL
• SQL (pronounced S-Q-L or Sequel) stands for Structured Query
Language
• It is a declarative language used for querying and updating tables in a
relational database
• It can also be used to create tables
• You can create SQL statements in a programming language such as
Python to access and manipulate a database
Activity
• Go to: https://sqliteonline.com/

• Enter the following SQL commands:

CREATE TABLE Dogs (DogID INTEGER PRIMARY KEY, Name VARCHAR(20), Breed VARCHAR(20), Colour VARCHAR(20), Gender CHAR(1), Age
INTEGER);
INSERT INTO Dogs VALUES (1, "Coco", "Labrador", "Brown", 'M', 3);
INSERT INTO Dogs VALUES (2, "Milly", "Spaniel", "Black", 'F', 5);
INSERT INTO Dogs VALUES (3, "Sasha", "Retriever", "Golden", 'F', 4);
INSERT INTO Dogs VALUES (4, "Mark", "Labrador", "Black", 'M', 3);
INSERT INTO Dogs VALUES (5, "Marlee", "Retriever", "Golden", 'F', 2);
INSERT INTO Dogs VALUES (6, "Alfie", "Spaniel", "Brown", 'M', 6);
INSERT INTO Dogs VALUES (7, "Georgie", "Labrador", "Black", 'F', 5);
• Insert three animals into the table
Data types
Data type Description Example
CHARACTER Char string of fixed length ProductCode CHARACTER

VARCHAR(n) Character string variable length, max. n Surname VARCHAR(25)

BOOLEAN TRUE or FALSE ReviewComplete BOOLEAN


INTEGER Integer Quantity INTEGER

Length FLOAT (10,2) (maximum number of


FLOAT Number with a floating decimal point
digits is 10 with max. 2 after decimal point)

DATE Stores Day, Month, Year values HireDate DATE


TIME Stores Hour, Minute, Second RaceTime TIME
SELECT .. FROM .. WHERE
• The SELECT statement is used to extract fields from one or more
tables
• The syntax of the statement is:
SELECT list of fields to be displayed
FROM list the table or tables the data will come from
WHERE list of search criteria
ORDER BY list the fields that the data is to be sorted on
(ASC or DESC, default is ASCending order)
Activity
tblProduct
productID productName subject level price
p24 Equations Maths 2 £12.00
p36 Programming Comp Science 4 £5.00
p47 Database Comp Science 4 £5.00

Which products will be selected by the following SQL statement? In what order?

SELECT productID, productName, subject, price


FROM tblProduct
WHERE level = 4
ORDER BY productName
SQL Results
productID productName subject level price
p24 Equations Maths 2 £12.00
p36 Programming Comp Science 4 £5.00
p47 Database Comp Science 4 £5.00

SELECT productID, productName, subject, price


FROM tblProduct
WHERE level = 4
ORDER BY productName

Results
productID productName subject price
p47 Database Comp Science £5.00
p36 Programming Comp Science £5.00
Activity
Using a wild card
tblProduct
productID productName subject level price
p24 Equations Maths 2 £12.00
p36 Programming Comp Science 4 £5.00
p47 Database Comp Science 4 £5.00
p54 Hardware Computing 3 £6.00

• You can use a “wild card” * to mean “all” or “one or many characters”
SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*”
• “LIKE” is used to search for a pattern
Activity

• Write a SQL query to: Show the values of all fields in the table.
Activity
Write a query to select the field values of any record from the “demo”
table where the value of the Name field starts with “Crea”.

Hint: Use LIKE and the % wild card, which means 0 or more characters.

Result should look like:


Operators in the WHERE clause
productID productName subject level price
p24 Equations Maths 2 £12.00
p36 Programming Comp Science 4 £5.00
p47 Database Comp Science 4 £5.00
p54 Hardware Computing 3 £6.00

• You can also use the following in SQL queries:


BETWEEN between an inclusive range
IN specify multiple possible values for a column
For example:
SELECT *
FROM tblProduct
WHERE price BETWEEN 5.00 AND 10.00
Activity
Write a query to select all field values of all record from the “demo”
table where the ID is at least 6 and at most 9:

Result should look like:


productID productName subject level price
p24 Equations Maths 2 £12.00

Activity p36
p47
Programming
Database
Comp Science
Comp Science
4
4
£5.00
£5.00
p54 Hardware Computing 3 £6.00

The following operators may be used in the WHERE clause

= <> > < >= <= AND, OR, NOT

What is the result of the following query?

SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*” AND level = 4
Use of semi-colon
• Some database systems require a semicolon at the end of each SQL
statement
• A semicolon is the standard way to separate each SQL statement
• Do NOT put a semicolon at the end of each line, only the last line
SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*” AND level = 4;

Note: In your exam, use a semi-colon. Past papers use them too.
Activity
1. What is the name of the
table?
2. How many records does the
table have?
3. How many columns does the
table have?
4. Which attribute is the
primary key?
5. What is the data type of the
values for Price?
6. What is the data type for the
values for Name?
Sorting: the ORDER BY keyword
• ORDER BY allows a query to sort data by ascending or descending order
• For ascending order
SELECT *
FROM members
ORDER BY Surname ASC
• For descending order
SELECT *
FROM members
ORDER BY Surname DESC
Activity
MemberID FirstName Surname Gender Town
1 David Johnson M Ipswich
2 Christine Bates F Woodbridge
3 Jasmine Hamid F Ipswich
4 Peter Okello M Colchester
5 Stephen Hines M Woodbridge

• What will the result be for the following query?


SELECT FirstName, Surname
FROM members
ORDER BY Town ASC
Result of sorting
• Result after execution of the statement:
SELECT FirstName, Surname, Town
FROM members
ORDER BY Town ASC
FirstName Surname Town
Peter Okello Colchester
David Johnson Ipswich
Jasmine Hamid Ipswich
Christine Bates Woodbridge
Stephen Hines Woodbridge
Activity
• SQL is often used to count records or find the sum of a particular field

• COUNT is number of non-null field values. Sum is the total of field values.

• What do you think the results of the following queries are?

SELECT COUNT(Quantity) Receipts


FROM Receipts ReceiptID Product Quantity Cost
1 Apples 6 £2.20
SELECT SUM(Cost) 2 Cheese 1 £2.50
FROM Receipts 3 Bread 2 £1.50
4 Pears 6 £1.80
Result of SUM and COUNT
• What do you think the results of the following queries are?

SELECT COUNT(Quantity)
FROM Receipts
Result: COUNT(Quantity) Receipts
4
ReceiptID Product Quantity Cost
1 Apples 6 2.20

SELECT SUM(Cost) 2 Cheese 1 2.50

FROM Receipts 3 Bread 2 1.50


4 Pears 6 1.80
Result: SUM(Cost)
8.00
Animals
Animal Height_m Weight_kg
Activity Rhino 1.8 2000
Giraffe 5.5 1800
Emu 1.8 55
• Look at the table called Animals to the right Llama 1.7 200
Sea lion 2.4 360

• In pairs create SQL statements for the following:

• Find all animal names in alphabetical order

• Find all animal names and weights that are over 1000 kg

• Find all animals, including all fields that are over 2 m


Week 24
Extra
Activity
1. Login to Smart Revise:
https://smartrevise.online

2. Complete “Quiz” questions for 10


minutes.

How many questions did you


attempt?

How many questions did you get


correct?
AI vs Machine Learning

• AI = computer simulating
human intelligence

• ML = computer improves at a
task (i.e., “learns”)
• WITH experience, and
• WITHOUT explicit
programming
Characteristics of AI systems
• There are a number of characteristics of AI including:
• Collection of data
• Rules for using the data
• The ability to reason
• The ability to learn or adapt
• Nowadays the most common way is to let the system learn the rules
by itself, but before we would have domain experts create the rules
Rules
• Rules are used by AI to determine the answers to questions
• They may be programmed by a human or ‘discovered’ by machine learning
• Create a set of rules that determines if a photo shows someone to be happy
or sad
Rules
• Happy:
• Teeth are showing; crease around edges of lips; eyes are wider; edges of
mouth raised
• Sad:
• Eyes more closed; mouth bends down at edges; possibly tears; teeth not
showing
Reasoning
• Artificial intelligence is able to use reasoning to find out new
information based on the rules it is given
• A deductive reasoning example:
• Humans eat vegetables
• Zach is human
• Reasoning deduces: Zach eats vegetables
Expert systems

• An expert system is a computer program that simulates a human expert


• For example, a website that finds the right future career for you could ask a series
of questions before suggesting suitable options
• Expert systems are made up of:
• A knowledge base
• A rule base
• An inference engine
• An interface
Knowledge base and rule base
• The knowledge base and rule base are like a database that stores a
set of facts and rules
• These rules are like IF-THEN statements
• For instance, in an expert system that suggests future careers, one
rule in the rule base could be:
• IF you like football AND you like talking THEN
we suggest being a football commentator
Inference engine
• Controls the steps taken to solve the problem
• You can think of an inference engine as carrying out a large number of IF-
THEN type statements to reach a conclusion
• There are two ways for an inference engine to work:
• Forward chaining – give a number of facts to the system which the inference
engine then uses to reach new facts
• Backward chaining – give a goal and then determine the facts that are
needed to reach a goal
Forward chaining – example
• Let’s consider an inference engine for choosing a future career
• Which job would you like?
• Do you like science? Yes
• Do you like working with people? Yes
• Do you want to help make people’s health better? Yes
• Do you faint if you see blood? No
• The inference engine is forward chaining by finding facts to find the
following goal:
• You should be doctor
Backward chaining - example
• In backward chaining the inference engine starts with the goal and
then determines all the facts needed to achieve the goal
• For example:
• Goal: I want to be a doctor
• The inference engine backward chains to establish that you need the
following:
• You must not faint if you see blood
• You must want to help make people better
• You must like people
• You must like science
Interface
• The interface is the method in which users interact with the expert system
• Interfaces include:
• Web pages
• Chat bots
• Telephone systems
• Have you used an expert system before?
Machine learning
• Machine learning is where a program is able to automatically adapt its
own processes or data
• Rather than giving the program rules, a large amount of data is collected by
the program and which then makes its own rules
Data
(Structur
ed)
Structured Data (Visualized)
Supervised Learning
• Uses labeled data, i.e., the “right answers” are given
• Uses “training” data to create a model that generalizes to “test” data
• Examples:
• Classification  Predicting classes / discrete values
• Regression  Predicting continuous values
• Problems:
• Overfitting
• Labeling data requires human intervention
Supervised Learning (Example)
Regression (Example)
Detecting fish or chips
• In machine learning we don’t give the computer the rules to detect
the difference
• Instead we give sets of data for it to learn from
• For instance, we could give a set of properties of many example foods for it to
learn from
Machine learning meals
• Here are some properties that are given:
• Colour of meal
• Number of items
• Weight
• Temperature
• Crispness
Machine learning meals
• The program has no knowledge of what fish or chips are

• What patterns do you think it will find from the following data?

Item Golden Number Weight Temp Crispness Food item


number intensity of items
1 8 1 300 25 9 Fish
2 7 2 250 20 8 Fish
3 5 20 400 30 4 Chips
4 8 1 150 35 7 Fish
5 9 1 200 25 8 Fish
6 6 15 200 20 5 Chips
Machine learning rules
• The machine learning detects the following rules:
• Golden intensity 7-9 is fish; intensity 5-6 is chips
• Number of items 15-20 is chips; number of items 1-2 is fish
• Weight and temperature can be ignored
• Crispiness 7-9 is fish; crispiness 4-5 is chips
Item number Golden intensity Number of items Weight Temp Crispness Food item

1 8 1 300 25 9 Fish
2 7 2 250 20 8 Fish
3 5 20 400 30 4 Chips
4 8 1 150 35 7 Fish
5 9 1 200 25 8 Fish
6 6 15 200 20 5 Chips
Machine learning rules
• The machine learning will also give weights to the importance of each
property
• For instance, a small weight may be given to the Weight property if it is high
• A large weight will be given to the number of items as the difference is so big

Item number Golden intensity Number of items Weight Temp Crispness Food item

1 8 1 300 25 9 Fish
2 7 2 250 20 8 Fish
3 5 20 400 30 4 Chips
4 8 1 150 35 7 Fish
5 9 1 200 25 8 Fish
6 6 15 200 20 5 Chips
Activity
Fill in the gaps with the words beneath.

AI stands for ___________. The main characteristics include the


collection of ____________, the ability to ___________ and the ability
to learn and adapt. ___________ systems are one use of AI. Another
technique is ___________. Here ___________ is given to a computer
program which then creates its own rules.

training data artificial intelligence reason


data and rules machine learning expert

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy