DATA100
Principles of Data Science
Data Science Primer
What is
computational
thinking?
Challenges when defining CT
Computational thinking (CT) is strongly related to computer science.
● Both include abstracting and concretizing ideas
● Both can be applied to almost anywhere
● Both have “comput” in it
But because of the broad definition, what separates one from the other?
Computational Thinking vs Computer
Science
Computer science is a broad Computational thinking is an
field that studies the theory everyday skill that is used in
and application of computing computer science, but it can be
concepts. applied in different fields.
Computational Thinking vs Programming
Computational thinking is an approach Learning how to program involves the
to problem solving. following:
● It’s a thought process used by a 1. Logic → what you’ll use to create the
programmer, but isn’t limited to just idea
programmers. 2. Syntax → what you’ll write to
express the idea
Table taken from page 8 of Beecher, K. (2017)
Table taken from page 8 of Beecher, K. (2017)
Computational Thinking
● Relevance of CT in Data Science
● An approach to problem solving
● Uses practices and principles from computer science in constructing a solution
● It is an everyday skill not limited to just programmers
Beecher (2017)’s CT concepts
● Logical thinking ● Evaluation
● Algorithmic thinking ● Data representation
● Decomposition ● Critical thinking
● Generalization and pattern ● Computer science
recognition
● Automation
● Modelling
● Simulation / visualization
● Abstraction
We’ll focus on these four
● Logical thinking ● Evaluation
● Algorithmic thinking ● Data representation
● Decomposition ● Critical thinking
● Generalization and pattern ● Computer science
recognition
● Automation
● Modelling
● Simulation / visualization
● Abstraction
Decomposition
Decomposition highlights that you
breakdown the hard problem into
smaller, easier to solve problems.
Decomposition
Real-world problems tend to be too big to solve right away
● Organize a simple get together with close friends
● Write a term paper
● Putting together self-assembly furniture
● Creating a good meme
● Build a health tracking application
● Solve world peace???
Decomposed Problem
Organize a simple get together with close friends
● Who to invite
● Where are we going
● Food to check
● Allergies
● Preference
● Price
● How are you getting the food
● Online + Delivery
● In person
● Al fresco
● Inside
● Identify a good date / time to hold the event
● Weekday / weekend?
● Morning or at night?
Decomposed Problem
● Creating a good meme
Decomposed Problem
● Get a 4.0 in class
Some sub-problems
need to be solved in
order, but not all
do.
Decomposition
Spaghetti and Salad: Chicken Cordon Bleu :
1. Cook in Parallel 1. Slice chicken
○ Pasta 2. Insert cheese strips
○ Meat 3. Wrap and chill
○ Sauce
4. Deep fry
2. Mix together under heat
Steps need to follow order.
Steps can be done in parallel.
Abstraction
a way of expressing an idea in a specific context
while at the same time suppressing details irrelevant
in that context
Decomposition
Cooking Pasta , Sauce and Salad Which detail is irrelevant?
Steps can be done in parallel.
1. In Parallel
1. Cook
○ Drop Pasta in Water
Which is Irrelevant?
○ Heat up Meat
○ Boil + Stir Sauce
2. Mix together under heat
3. Toss Salad
Algorithmic
Thinking
Algorithmic Thinking
An algorithm is a sequence of clearly defined steps that describe a process to follow a
finite set of unambiguous instructions with clear start and end points
Coming up with an algorithm is equal to expressing of a thought process
Is PREMDAS an ALGORITHM? Is FOIL an ALGORITHM?
Think of recipes…
Recipes are meant to give
Ingredients: you a clear picture of how
4 slices of white bread; to cook a dish.
3 tablespoons butter, divided; Read the recipe and
2 slices Cheddar cheese check if there are
unclear steps.
Steps:
1. Preheat skillet (pan)
2. Generously butter one side of a slice of bread.
3. Place bread on the skillet and add 1 slice of cheese.
4. Butter a second slice of bread on one side and place on top of sandwich.
5. Grill and flip over; continue grilling until cheese is melted.
Another Sample
Create targeted ads across platform
IS THIS AN ALGORITHM
Steps:
1. Get the universe of users’ data
2. Calculate their age using birthday column
3. Create ads for Tiktok for young people
4. Create ads for Facebook for mid-aged people
5. Email blast for oldies
Algorithmic Thinking
Similarly, if you have code that is unclear to a computer, it won’t know
what to do
Algorithmic thinking advocates for a solution that is clear and precise
print(x) x = "hello"
print(x)
Evaluation
Evaluation
After analyzing a problem, breaking it down, and creating a solution, you must
ask yourself:
How good is your solution?
Is the problem solved?
Does your solution solve it quickly?
You might have one or many solutions, but regardless, there are ways to
measure how good your design is (even without implementing the
algorithm!)
Can you imagine how computational
thinking relate to programming?
How computers work, generally.
Input Process Output
algorithm
Examples
Input → Process → Output
Ingredients /
→ Cooking Steps → Finished Dish
Equipment
Processed Data /
Data → Excel Processing →
Insights
Some input → Some algorithm → Some output
Algorithms… process… program?
When applying computational thinking…
● How to tackle a problem using a CT point of view
● How to develop algorithms/solutions to any given problem
In most cases, we’re expressing our logic in the means of words.
● Directions, tricks/tips
Programming
We’re going to learn about:
Logic formulation should know no bounds
● You can come up with many types of solutions to one problem
● But there has to be a way to express your solution
● Pseudocode
Syntax then allow you to express your thoughts but has limitations.
● You have to follow the rules of the programming language
● You are limited by how you can manipulate these rules
Computer Programs
A programming language is a language that is understood both by a
programmer and a computer.
It is a common language used
to write solutions (called programs)
that may be executed by the
computer.
Data Preparation
with Python
Input & Output
Data Types
Data Type Description Sample
String Text data (numbers and letters) ‘Hi’, ‘123’, ‘Sheesh -!’
Integer Whole numbers (index) 1,2,3,4,5,6
Float Numbers with decimals 1.5, 3.14, 1.0
List Stores multiple items [1,2,’A’]
* Use the function ‘type()’ to check for the data type
Strings
- Contains Text
- Letters, numbers symbols
- Enclosed in quotation marks (either single or double)
-Earl’s
-She said “YES”
- “Juan”,2 and 3’s
Strings - Operations
- Substrings can be accessed using an index
- Index starts at 0
- Reverse indexing is possible
- Concatenation can be done
-Using +
-Multiple concatenation can be done using *
Integers vs Float
Integers *Mathematical
-Whole numbers Operation :
-No decimal points
-Usually used for counting, indeces, etc. Add
-negative infinity to positive infinity Multiply
Subtract
Float Divide
-Numbers WITH decimal point
-negative infinity to negative infinity Follows PREMDAS
List
- A collection of data
- CAN contain multiple datatypes
- Elements can be accessed via indexing
- initialized using an open and close brackets
Typecasting and Other Functions
- type()
- print()
- len()
Typecasting
- ‘IFS’ : Integer -> Float -> String
- str()
- float()
- int()
Boolean
-True or False only