CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Advertisements

A Level Computing#BristolMet Session Objectives#U2 S8 MUST identify the difference between a procedure and a function SHOULD explain the need for parameters.
Complexity (Running Time)
More on Regular Expressions Regular Expressions More character classes \s matches any whitespace character (space, tab, newline etc) \w matches.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Compsci 101.2, Fall Plan for TDAFB (after fall break) l Hear via about plans to catch-up and stay-ahead  Profs. Rodger and Astrachan to.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
Chapter 9 Introduction to Arrays Fundamentals of Java.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
Compsci 101.2, Fall Plan for LWoC l Power of Regular Expressions  From theoretical computer science to scraping webpages  Using documentation,
By: Megan Funk. I will: 1. Explain the binary number system How to: -Generate binary from a number -Add binary 2. Explain the base-b number system 3.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
Compsci 101.2, Fall Plan for ThBThB l Programming and understanding …  Hierarchical structures and concepts What is a file system on a computer?
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Lecture 9: introduction to recursion reading: 12.1
Whatcha doin'? Aims: To start using Python. To understand loops.
Strings and Serialization
CompSci 101 Introduction to Computer Science
Building Java Programs
MSc/ICY Software Workshop , Semester 2
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Lecture 19 Strings and Regular Expressions
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
© 2016 Pearson Education, Ltd. All rights reserved.
Arrays: Checkboxes and Textareas
Containers and Lists CIS 40 – Introduction to Programming in Python
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
Chapter 7 Part 1 Edited by JJ Shepherd
CS 1428 Exam I Review.
CompSci 101 Introduction to Computer Science
Variables, Expressions, and IO
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Strings Part 1 Taken from notes by Dr. Neil Moore
Announcements Final Exam on August 17th Wednesday at 16:00.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction To Programming Information Technology , 1’st Semester
CS 1111 Introduction to Programming Fall 2018
(more) Python.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Summary of what we learned yesterday
Introduction to Computer Science
Building Java Programs
CS 1428 Exam I Review.
Presentation transcript:

CompSci 101 Introduction to Computer Science ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 Dec 1, 2016 Prof. Rodger compsci 101 fall 2016

Announcements Reading and RQ due Tuesday Assign 8 due Tue., Assign9 due Dec 9 APT 11 due Dec 9, no penalty til Dec 12! Today: Review Recursion Regular Expressions Assignment 8 Recommender compsci 101 fall 2016

Assignment 9 Due Dec 9 Shhh! No late penalty til Dec 12! Write a song, make a video about your experience with CompSci 101 compsci 101 fall 2016

Assignment 8 From User Rating to Recommendations Spectre Martian Southpaw Everest PitchPerfect 2 3 -3 5 -2 2 4 1 -1 What should I choose to see? What does this depend on? Who is most like me? How do we figure this out compsci 101 fall 2016

ReadFood modules: Food Format bit.ly/101f16-1201-A All Reader modules return a tuple of strings: itemlist and dictratings dictionary Translated to: Give the example formated

Data For Recommender Users/Raters rate Items We need to know the items We need to know how users rate each item Which eatery has highest average rating? Conceptually: average columns in table How is data provided in this assignment? Seven items – 3 sets of ratings for each – have to rate everything Divide by 2 – don’t count 0 – allratings don’t include 0 One way of doing a recommendation – what yelp does Average rating ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 compsci 101 fall 2016

Data For Recommender itemlist are provided in a list of strings Parsing data provides this list dictratings provided in dictionary Key is user ID Value is list of integer ratings ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 You need items as a list of strings (restaurants) Required to create a dictionary Note they are in the same order compsci 101 fall 2016

Data For Recommender Given Parameters Can you write itemlist: a list of strings dictratings: dictionary of ID to ratings list Can you write Average(itemlist, dictratings) Id is person and list of their ratings as ints Average for McDonalds? 4 ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 compsci 101 fall 2016

Drawbacks of Item Averaging Are all ratings the same to me? Shouldn't I value ratings of people "near" me as more meaningful than those "far" from me? Collaborative Filtering https://en.wikipedia.org/wiki/Collaborative_filtering How do we determine who is "near" me? Mathematically: treat ratings as vectors in an N-dimensional space, N = # ratings Informally: assign numbers, higher the number, closer to me All ratings are the same. Don’t you want to only consider ratings that are near you and value their ratings. compsci 101 fall 2016

Collaborative Filtering: Recommender First determine closeness of all users to me: "Me" is a user-ID, parameter to function Return list of (ID, closeness-#) tuples, sorted Use just the ratings of person closest to me Is this a good idea? What about the 10 closest people to me? What about weighting ratings Closer to me, more weight given to rating How many do you use You could weight those closer to you and use everyone compsci 101 fall 2016

How do you calculate a similarity? Me: [3, 5, -3] Joe: [5, 1, -1] Sue: [-1, 1, 3] Joe to Me = (3*5 + 5*1 + -3 * -1) = 23 Sue to Me = (3*-1 + 5 * 1 + -3 * 3) = -7

How do you calculate a similarity? Me: [3, 5, -3] Joe: [5, 1, -1] Sue: [-1, 1, 3] Joe to Me = (3*5 + 5*1 + -3 * -1) = 23 Sue to Me = (3*-1 + 5 * 1 + -3 * 3) = -7 The higher the number the closer they are to me. Negative numbers are really far from me.

Collaborative Filtering For Chris: 12 * [1,1,0,3,0,-3] = [12,12,0,36,0,-36] For Sam: [0,75,125,0,-75,125] Sam:25 Nat:37 Chris:12 Here we are calculating ratings with weights. Chris is 12 away from me Nat is 37 away from me Sam is 25 away from me High number is closer to you . Show how you multiple the closeness number times every rating. ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 compsci 101 fall 2016

Adding lists of numbers [12, 12, 0, 36, 0,-36] [ 0, 75, 125, 0,-75,125] [-111,111,111,185,37, -37] --------------------------- [-99, 198, 236, 221, -38, 52] Adding columns in lists of numbers Using indexes 0, 1, 2, … sum elements of list sum([val[i] for val in d.values()]) I would probably like 236 item, then Note the -75 could be an outlier, only one person rated it. compsci 101 fall 2016

Then divide by number of nonzeros [12, 12, 0, 36, 0,-36] [ 0, 75, 125, 0,-75,125] [-111,111,111,185,37, -37] --------------------------- [-99, 198, 236, 221, -38, 52] /2 /3 /2 /2 /2 /3 [ -49, 66, 118, 110 -19, 17] I would probably like 139 item, then Note the -75 could be an outlier, only one person rated it. Recommend 3rd item ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 compsci 101 fall 2016

Follow 12-step process ReadFood first! Read input and save it Get list of restaurants – use that ordering! Set? For each person For each restaurant and its rating Must find location of restaurant in itemlist Then update appropriate counter Print any structure you create to check it compsci 101 fall 2016

Recursion Review Function calls a clone of itself Smaller problem Must be a way out of recursion Solving a smaller version of the original problem, must be smaller in some way. Must also get smaller and smaller and then must be a way where it is so small you can just solve the problem. compsci 101 fall 2016

Example Mystery(5) is 1 + Mystery(2) = 1 + 4 = 5 = 1 + 3 = 4 = 1 + 2 = 3 compsci 101 fall 2016

Review: Recursion to find ALL files in a folder A folder can have sub folders and files A file cannot have sub files def visit(dirname): for inner in dirname: if isdir(inner): visit(inner) else: print name(inner), size(inner) Is that a directory? If not a directory, it will be a file Calls an instance that is smaller compsci 101 fall 2016

Revisit the APT Bagels Recursively compsci 101 fall 2016

APT Bagels Recursively bit.ly/101f16-1201-2 D) compsci 101 fall 2016

Recursion in Pictures http://xkcd.com/543/ compsci 101 fall 2016

More: Recursion in Pictures http://xkcd.com/688/ compsci 101 fall 2016

What is Computer Science? … "it is the study of automating algorithmic processes that scale." https://en.wikipedia.org/wiki/Computer_science If you need to find one email address on a webpage, you don't need computer science If you need to scrape every email address, that number in the 10's to 100's, you could use help compsci 101 fall 2016

How do you solve a problem like … How many words end in "aria"? Start with "aria"? Contain "aria"? Why would you care about this? Can you find ola@cs.duke.edu, susan.rodger@duke.edu, and andrew.douglas.hilton@gmail.com when searching through a webpage source? What is the format of a "real" email address? How do you solve a problem like "Maria" is from sound of music compsci 101 fall 2016

Examples of regex's at work What do aria$ and ^aria and aria share? Answers to previous question What about the regex .+@.+ Turns out that . has special meaning in regex, so does +, so do many characters We'll use a module RegexDemo.py to check Uses the re Python library Details won't be tested, regex knowledge will compsci 101 fall 2016

Regex expressions Regex parts combined in powerful ways Each part of a regex "matches" text, can extract matches using programs and regex library ^ is start of word/line, $ is end Expressions that match single characters: A, a, 9 or … Any character matches itself . Matches any character \w Matches alphanumeric and _ \d Matches digit \s Matches whitespace compsci 101 fall 2016

Regex expressions Repeat and combine regex parts * means 0 or more occurrences/repeats + means 1 or more occurrences/repeats ? Means (after * or +) to be non-greedy Expressions match more than one character [a-zAB] Brackets create character class (regex) Tag or group a regex \1 or \2 Matches previously grouped regex {1} or {n} Repeat regex 1 or n times compsci 101 fall 2016

Regex examples tried and explained Five letter words ending in p? Starts 'd'? ^\w\w\w\wp$ but not ....p$ Seven letter words, or seven ending with 'z' Difference between ^\w{7}$ and ^\w{7} Words that start with a consonant: ^[^aeiou] double meaning of ^ compsci 101 fall 2016

Regex examples tried and explained Five letter words ending in p? Starts 'd'? ^\w\w\w\wp$ but not ....p$ Seven letter words, or seven ending with 'z' Difference between ^\w{7}$ and ^\w{7} Start and end with the same two letters like sense and metronome, decipher this: ^(\w\w).*\1$ Start and end with three letters reversed, like despised and foolproof? compsci 101 fall 2016

Summary of Regular Expressions regex purpose . any character * zero or more of previous regex \w any alphanumeric character (and _) + one or more of previous regex \s any whitespace character *? or +? non-greedy version of either * or + \d any digit character () tag/group a regular expression [] character class, e.g., [A-Z] or [aeiou] \1, \2, .. match numbered tagged/grouped regex {n} n occurrences of preceding regex ^ beginning of line/string [^...] not the characters in the class, e.g., [^aeiou] $ end of line/string compsci 101 fall 2016

Regex Questions bit.ly/101f16-1201-3 compsci 101 fall 2016

Take Exam questions compsci 101 fall 2016