3.14 - 3.15 Hacks
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.
-
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
-
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
-
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).
-
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?
-
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
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)
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))
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))