Skip to content

timothyshores/machine-learning-data-science-and-deep-learning-with-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Machine Learning, Data Science and Deep Learning with Pythonn

My person notes for the Machine Learning, Data Science and Deep Learning with Python course by Frank Kane on Udemy

Getting Started

  1. Install Anaconda Individual Edition
  2. Reopen a terminal window and run the following terminal commands
    • conda install pydotplus
    • conda install tensorflow
  3. Download course materials 3.1 In terminal navigate to the location of the unzipped course materials folder and run jupyter notebook 3.2 This will open a browser tab with the url http://localhost:8888/tree with the script files and accompanying data

Python Basics

Python 101

In terminal navigate to the MLCourse directory , run jupyter notebook and click on Python101.ipynb

Python Syntax

  • Whitespace matters in Python sort of like {} in JavaScript
  • There is no ; required to terminate the end of a linelike in JavaScript
  • For loops and if else statements end with :
  • Variables are declared without types similiar to JavaScript since it is a dynamically typed language

Example: Write a python program to create a list of numbers from 1 to 6 and then print whether that number is either even or odd

listOfNumbers = [1, 2, 3, 4, 5, 6]

for number in listOfNumbers:
    if (number % 2 == 0):
        print(number, "is even")
    else:
        print(number, "is odd")
        
print ("All done.")

Importing Modules

  • Use the keyword import to import
  • Can define an alias using the as keyword

Example: Import the numpy library and generate a list of 10 numbers with a mean of 25 and a standard deviation of 5

import numpy as np

A = np.random.normal(25.0, 5.0, 10)
print (A)

Lists

Python's version of JavaScript arrays

x = [1, 2, 3, 4, 5, 6]
print(len(x)) # 6
x[:3]  			# [1, 2, 3]
x[3:]  			# [4, 5, 6]
x[-2:] 			# [5, 6]
x.extend([7,8]) # [1, 2, 3, 4, 5, 6, 7, 8]
x.append(9) 	# [1, 2, 3, 4, 5, 6, 7, 8, 9]

y = [10, 11, 12]
listOfLists = [x, y]
print(listOfLists) # [[1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12]]

z = [3, 2, 1]
z.sort() 				# [1, 2, 3]
z.sort(reverse=True) 	# [3, 2, 1]

Tuples

Immutable lists used for functional programming or working with Apache Spark

x = (1, 2, 3)
len(x) # 3

y = (4, 5, 6)
y[2] # 6

listOfTuples = [x, y]
listOfTuples # [(1, 2, 3), (4, 5, 6)]

(age, income) = "32,120000".split(',')
print(age) # 32
print(income) # 120000

Dictionaries

Similiar to objects in JavaScript also reffered to as a map or hash table in other languages

captains = {}
captains["Enterprise"] = "Kirk"
captains["Enterprise D"] = "Picard"
captains["Deep Space Nine"] = "Sisko"
captains["Voyager"] = "Janeway"

print(captains["Voyager"]) 			# Janeway
print(captains.get("Enterprise")) 	# Kirk
print(captains.get("NX-01"))		# none

for ship in captains:
    print(ship + ": " + captains[ship])
    
# Enterprise: Kirk
# Enterprise D: Picard
# Deep Space Nine: Sisko
# Voyager: Janeway

Functions

# Example syntax
def FunctionName(param1, param2, ... , paramn):
	return param1 + param2 + ... + paramn

# Return the square of a given number
def SquareIt(x):
    return x * x

# Pass function in as a parameter
def DoSomething(f, x):
    return f(x)

print(SquareIt(2)) # 4
print(DoSomething(SquareIt, 3))

# Inline simple function using Lambda function
print(DoSomething(lambda x: x * x * x, 3)) # 27

Boolean Expressions

print(1 == 3) 			# False
print(True or False)	# True
print(1 is 3)			# False

if 1 is 3:
 print("How did that happen?")
elif 1 > 3:
 print("Yikes")
else:
 print("All is well with the world")

# All is well with the world

Looping

for x in range(10):
    print(x)

for x in range(10):
    if (x is 1):
        continue
    if (x > 5):
        break
    print(x)

x = 0
while (x < 10):
    print(x)
    x += 1

myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for x in myList:
    if (x % 2 == 0):
        print(x)

Types of Data

Numerical

  • Represents some sort of quantitative measurement
    • Heights of people, page load times, stockprices, etc.
  • Discrete Data
    • Integerbased;oftencountsofsomeevent.
      • How many purchases did a customer make in a year?
      • How many times did I flip “heads”?
  • Continuous Data
    • Has an infinite number of possible values
      • How much time did it take for a user to check out?
      • How much rain fell on a given day?

Categorical

  • Qualitative data that has no inherent mathematical meaning
    • Gender, Yes/no (binary data)
    • Race
    • State of Residence
    • Product Category,
    • Political Party
  • You can assign numbers to categories in order to represent them more compactly, but the numbers don’t have mathematical meaning

Ordinal

  • A mixture of numerical and categorical
  • Categorical data that has mathematical meaning
  • Example: movie ratings on a 1-5 scale.
    • Ratings must be 1, 2, 3, 4, or 5
    • These values have mathematical meaning; 1 means it’s a worse movie than a 2.