3.14 Hacks

Research two other Python Libraries NOT DISCUSSED DURING LESSON and make a markdown post, explaining their function and how it helps programmers code.

  1. Pandas

    • A Berkeley Software Distribution licensed open source library
    • used in data science
    • used for data analysis, manipulation, and cleaning
    • makes programming easier by allowing for simple data modeling and data analysis operations without switching to other languages
    • can slice data frames
    • can join and merge data frames
    • can concatenate columns from 2 data frames
    • can change index values in a data frame
    • can change column headers
    • can convert data into many forms
  2. Scikit Learn

    • open source library for machine learning algorithms
    • can be used with both supervised and unsupervised learning algorithms
    • does cross validation: checking the accurary of supervised models on unseen data
      • most common use is for music suggestions on spotify
    • has Unsupervised learning algorithms: ex. clustering, factor analysis, principal component analysis, and unsupervised neural networks
    • can extract features from photos and text
    • helps programmers code because it includes many algorithms and can be used to perform machine learning and data mining tasks
      • applications in dimensionality reduction, classification, regression, clustering, and model selection

3.15 Hacks

  1. Write a procedure that generates n random numbers, then sorts those numbers into lists of even and odd numbers (JS or Python, Python will be easier).

  2. Using NumPy and only coding in python cell, find the answer to the following questions: a. What is the derivative of 2x^5 - 6x^2 + 24x? b. What is the derivative of (13x^4 + 4x^2) / 2 when x = 9?

  3. Suppose you have a group of 10 dogs and 10 cats, and you want to create a random order for them. Show how random number generation could be used to create this random order.

import random # import all numbers

def sortList(numList): # define a function sortList
    
    numList = random.sample(range(1, 100), 10) # generate a list of 10 numbers between 1 and 100, and assign it to variable "numList"
    print("Your list of 10 random numbers: " + str(numList)) # print the list of 10 random numbers between 1 and 100
    evenList = [] # create an empty list for even numbers
    oddList = [] # create an empty list for odd numbers
    
    for i in numList: # iterate through numList
        if i % 2 == 0: # check if number is divisible by 2 -- remainder must be 0
            evenList.append(i) # if the number is divisible by 2, add it to evenList
        else:
            oddList.append(i) # if the number is not divisible by 2, add it to oddList
    print("Your sorted list of even numbers: " + str(evenList)) # print the evenList
    print("Your sorted list of odd numbers: " + str(oddList)) # print the oddList

newList = (str(sortList(str(numList)))) # calling the function
Your list of 10 random numbers: [77, 24, 11, 92, 47, 15, 27, 28, 58, 10]
Your sorted list of even numbers: [24, 92, 28, 58, 10]
Your sorted list of odd numbers: [77, 11, 47, 15, 27]
import numpy as np
 
# defining polynomial function
var = np.poly1d([2, 0, 0, -6, 24, 0]) # kept trying different zero placement until i got the right polynomial; left is highest power and right is lowest power
print("Polynomial function f(x)=\n", var)
 
# calculating the derivative
derivative = var.deriv()
print("Derivative f'(x)=", derivative)
Polynomial function f(x)=
    5     2
2 x - 6 x + 24 x
Derivative f'(x)=     4
10 x - 12 x + 24
import numpy as np
 
# defining polynomial function
var = np.poly1d([13, 0, 4, 0, 0])
function = var / 2
print("f(x)=\n", function)
 
# calculating the derivative
derivative = function.deriv()
print("f'(x)=", derivative)
 
# calculates the derivative of after
# given value of x
print("When x=9  f'(x)=", derivative(9))
f(x)=
      4     2
6.5 x + 2 x
f'(x)=     3
26 x + 4 x
When x=9  f'(x)= 18990.0
import random

dogs = ["oreo", "mocha", "coffee", "lilly", "daisy", "buddy", "bubba", "mothi", "leo", "sunny"] # create list of 10 dog names
cats = ["mimi", "kyoto", "billy", "whiskers", "bobby", "basil", "simba", "mitten", "cora", "gwen"] # create list of 10 cat names

random.shuffle(dogs) # use "random.shuffle" command to shuffle the elements in the list of 10 dog names
print("Shuffled dog name list: " + str(dogs))

random.shuffle(cats) # use "random.shuffle" command to shuffle the elements in the list of 10 cat names
print("Shuffled cat name list: " + str(cats))
Shuffled dog name list: ['mocha', 'leo', 'sunny', 'mothi', 'daisy', 'bubba', 'lilly', 'buddy', 'coffee', 'oreo']
Shuffled cat name list: ['kyoto', 'basil', 'whiskers', 'mitten', 'bobby', 'cora', 'gwen', 'simba', 'billy', 'mimi']