CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python

Slides:



Advertisements
Similar presentations
Python for Science Shane Grigsby. What is python? Why python? Interpreted, object oriented language Free and open source Focus is on readability Fast.
Advertisements

Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Java Script Session1 INTRODUCTION.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 7: Program flow control.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
The Python Programming Language Matt Campbell | Steve Losh.
Recitation 1 Programming for Engineers in Python.
Python Control of Flow.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
CIS Computer Programming Logic
Introduction to Python
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
If statements while loop for loop
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Python Let’s get started!.
Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Lecture 3.1: Operator Precedence and Eclipse Tutorial Michael Hsu CSULA.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
Python Programming Challenge
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
Python Let’s get started!.
Introduction to Python
Arrays: Checkboxes and Textareas
CSC 352– Unix Programming, Fall 2012
Python Comprehension and Generators
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Intro to PHP & Variables
Engineering Innovation Center
Engineering Innovation Center
CISC101 Reminders Quiz 2 this week.
Introduction to Python
Python Primer 2: Functions and Control Flow
CSS 161 Fundamentals of Computing Introduction to Computers & Java
WEB PROGRAMMING JavaScript.
Introduction to Python
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Loops CIS 40 – Introduction to Programming in Python
CSC 458– Predictive Analytics I, Fall 2018, Intro. To Python
CSC1018F: Intermediate Python
Introduction to Programming
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Python Primer 1: Types and Operators
CS190/295 Programming in Python for Life Sciences: Lecture 3
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
CISC101 Reminders All assignments are now posted.
Module 2 - Part 1 Variables, Assignment, and Data Types
CSC 352– Unix Programming, Fall, 2011
12th Computer Science – Unit 5
CSC 352– Unix Programming, Fall 2012
Introduction to Programming
Class code for pythonroom.com cchsp2cs
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python This is an outline. Come to class or attend via RTVC and play along as we play with Python to learn how it works. Updated 8/31/2017 for Python 3.x.

Introduction to Python ~parson/DataMine/prepdata1 has two examples. lsTOarff.py is my completed, working code example. psTOarff.py is the starting point for assignment 1. Both of these Python programs extract data from a “raw data” text file and format it for an ARFF file (Attribute Relation File Format) for use by the Weka data mining tool. In ~parson/DataMine see lsTOarff.rawtestdata.txt lsTOarff.arff.ref psTOarff.rawtestdata.txt psTOarff.arff.ref.

Python’s read-eval-print UI. You can interaction with Python to compute interactively. It can also interpret script files. You create variables on the fly. They hold whatever type of data you put into them. $ python –V # Can be version 2.x or 3.x. Use 3.x per course page. Python 3.6.0 $ python >>> a = 2 ; b = 4.7 ; (a - 7) * b -23.5 # ; and newline are command separators

Python uses indentation, not {}, to delimit flow-of-control constructs >>> a = 7 >>> if a <= 7: print (a, "Is low”) else: print(a, "is high”) 7 Is low # Do NOT mix leading spaces with TABS in assignments. # Use leading spaces to be compatible with handouts.

for loop iterates over list of values. >>> a = 7 >>> mylist = [a, 'a', "Strings use either delimiter"] >>> for s in mylist: print(s) 7 a Strings use either delimiter

range() creates a list of numbers >>> for i in range(1,3): print("i is", i) # Note that the final value is exclusive i is 1 i is 2 >>> for i in range(3,-3,-2): # -2 here is an increment print("i is", i) i is 3 i is -1

Use and, or, not instead of &&, ||, ! as used in Java or C++ >>> a = 1 ; b = 5 >>> while (a <= 3) and (b >= 3): print("a, b", a, b) a += 1 ; b = b - 2 a, b 1 5 a, b 2 3 >>> print("a, b", a, b) a, b 3 1

Basic data types Basic data types include strings, ints, floats, and None, which is Python’s “no value” type. Use a raw string to make escape sequences literal. >>> a = "a string" ; b = 'another string' ; c = -45 ; d = 4.5 ; e = None >>> print(a,b,c,d,e) a string another string -45 4.5 None >>> raws = r'a\n\nraw string' >>> print(raws) a\n\nraw string

Aggregate data types A Python list is a sequence of values. A dictionary maps keys to values. We won’t use sets or tuples in assignment 1. >>> L = ['a', 1, ["b", 2]] >>> for e in L: print(e) a 1 ['b', 2]

Dictionary maps keys to values >>> m = {'a': 1, "b" : 2} ; m['c'] = 3 >>> for k in m.keys(): print(k, m[k]) a 1 c 3 b 2 >>> 'b' in m # same as 'b' in m.keys() # Python 2.x allows: m.has_key('b') True >>> 'z' in m False

Python has functions and classes We will not use them in assignment 1. >>> def f(a, b): ... return a + b ... >>> f(1, 3.5) 4.5 >>> f("prefix", 'suffix') 'prefixsuffix'

Library modules & more We will go over the re (regular expression), sys (system), and datetime modules’ functions used in assignment 1 when we go over it. Come to class. We will explore Python in class in person or via RTVC. https://docs.python.org/3/ has a tutorial and more detailed documentation.