PLEASE DO THIS IN PYTHON. THERE IS A PSEUDOCODE TOO. IF YOU DO NOT KNOW HOW TO DO THIS, PLEASE DON'T PUT WRONG ANSWERS.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

PLEASE DO THIS IN PYTHON. THERE IS A PSEUDOCODE TOO. IF YOU DO NOT KNOW HOW TO DO THIS, PLEASE DON'T PUT WRONG ANSWERS.

Post by answerhappygod »

PLEASE DO THIS IN PYTHON. THERE IS A PSEUDOCODE
TOO. IF YOU DO NOT KNOW HOW TO DO THIS, PLEASE DON'T PUT WRONG
ANSWERS.
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 1
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 1 (96.57 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 2
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 2 (96.31 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 3
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 3 (89.15 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 4
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 4 (52.65 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 5
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 5 (52.65 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 6
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 6 (135.86 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 7
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 7 (94.38 KiB) Viewed 27 times
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 8
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 8 (85.26 KiB) Viewed 27 times
Below are AudUsd.csv and utilitiesModule.py and
pandaUtilities.py
AudUsd.csv
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 9
Please Do This In Python There Is A Pseudocode Too If You Do Not Know How To Do This Please Don T Put Wrong Answers 9 (25.53 KiB) Viewed 27 times
utilitiesModule.py
import numpy as np
def getRandomInts(min, maxPlusOne, numInts):
"""Assumes the following:
min is an int which specifies the smallest random int to
generate
maxPlusOne is an int which specifies one more than largest random
int to generate
numInts is an int that specifies how many random ints to
generate
Returns the list of random ints
"""
#start with empty list of random ints
randInts = []

#use for loop to iterate to get required number of random
ints
for i in range(numInts):
newInt = np.random.randint(min, maxPlusOne)
#append newInt to randInts list
randInts.append(newInt)
return randInts
def displayListSubset(oneList, subsetSize):
""" Assumes onelist is a python list
subsetSize is a positive int that specifies how many elements of
the list to display
"""
#set up a list to contain the subset
listSubset = []
for i in range(subsetSize + 1):
listSubset.append((oneList))

print(listSubset)

def isValidInteger (strInt):
"""Assumes strInt is a string of len >= 1
Returns True if all chars of the string are numeric;
else returns False
"""
#set up named constants for min and max numeric chars
MIN_UNICODE = ord('0')
MAX_UNICODE = ord('9')
#initialize bool var to true
isValid = True
#iterate through the chars in the string
for i in range(len(strInt)):
#determine Unicode val of this char
charVal = ord(strInt)
#if not in correct range, flip isValid to False
if (charVal < MIN_UNICODE or charVal > MAX_UNICODE):
isValid = False

return isValid
def getValidInteger():
isValid = False

#initialize strInput
strInput = ""

while (not isValid):
#get string input from the user
#'Enter an integer: '
strInput = input()
isValid = isValidInteger(strInput)
if (not isValid):
print('Invalid integer was entered: try again')

#after exiting the loop return strInput cast to an int
return int(strInput)
def fact(n):
result = 1
numItreations = 0
while n > 1:
result *= n
n-=1
numItreations += 1

return result
def gcdIterative(a, b):
"""Assumbes a and b are ints
Implements loop to determine gcd of a and b
Returns the gcd and numIterations required to determine this
"""
#keep track of numIterations required
numIterations = 0
#initialize remainder to zero
remainder = 0
#implement loop to compute gcd
while (b != 0):
remainder = a % b
a = b
b = remainder
numIterations += 1
#after exiting loop return a and numIterations
return a, numIterations
def getGcdList(listA, listB):
"""Assumes listA and listB are equivalently sized python lists of
ints in
Implements iterative gcd method to determine gcd of each pair
Returns the following:
execution time required
list of gcd values
list of num iterations required
"""
#initialize list of gcd vals
gcdList = []
numIterations = []
#get start time
#startTime = time. time()
#iterate through the lists and determine gcd of each pair
for i in range(len(listA)):
curGcd, numIt = gcdIterative(listA, listB)
#append this gcd to gcdList
gcdList.append(curGcd)
#append this numIterations to the numIterations list
numIterations.append(numIt)
#endTime = time.time()
#itExeTime = endTime - startTime
#return exe time, gcdList and numIterations list
#return itExeTime, gcdList, numIterations
return gcdList
def getLines(fn):
"""Function to read a file and return a list of the lines in the
file;
Assumes fn is a string which is the name of the file
"""
#open the file so that it can be read (i.e. 'r')
nameHandle = open(fn, 'r')
#create an empty list of lines
lines = []
for line in nameHandle:
#as each line is read, append (i.e. add) this to the list
lines.append(line)
#don't forget to close the file...or you will have problems
nameHandle.close()
#return the list of lines
return lines
def readFile(fn):
"""Function to read a file and display each line in the file that
has been read
"""
inFile = open(fn, 'r')
for line in inFile:
print(line)
#don't forget to close the file or you will have a problem
inFile.close()

def writeFile(fn, lines):
"""Assumes fn is a string that is the name of the file to
write
Assumes lines is a list of the lines to write to file
Writes the list of lines to file
"""
#create the file handle
outFile = open(fn, 'w')
#iterate through the list of lines, appending each on to the
file
for i in range(len(lines)):
outFile.write(lines)
outFile.close()

def variance(nums):
"""Assumes that nums is a list of numbers. """

mean = sum(nums) / len(nums)
tot = 0.0
for x in nums:
tot += (x - mean) **2
return tot / len(nums)
def stdDev(nums):
"""Assumes that nums is a list of numbers.
Returns the standard deviation of nums
"""
#the std deviation is the square root of the variance
return variance(nums)**0.5
def nChooseK(n,k):
num = fact(n)
den = fact(k) * fact((n-k))
return num // den
def intMeans(totalInts, intsPerSubset, minVal, maxVal):

numMeans = totalInts// intsPerSubset
means = []

for i in range(numMeans):
vals = 0
for j in range (intsPerSubset):
vals += np.random.randint(minVal, maxVal)
means.append(vals / intsPerSubset)

return means
def getMean(nums):

totalVal = sum(nums)

meanVal = totalVal / len (nums)

return meanVal
def formatRegressionGraph(pDegree):
if pDegree == 1:
strFormatData = 'b--'
elif pDegree == 2:
strFormatData = 'c--'
elif pDegree == 3:
strFormatData = 'r--'
elif pDegree == 4:
strFormatData = 'g--'
elif pDegree == 5:
strFormatData = 'g--'
else:
strFormatData = 'm--'
return strFormatData
pandaUtilities.py
import pandas as pd
import numpy as np
def getFit(xVals, yVals, n):

fit = np.polyfit(xVals, yVals, n)

return np.polyval(fit, xVals)
def readFile(inFile):

in_handle = open(inFile, 'r')

df = pd.read_csv(in_handle)

in_handle.close()

return df
def writeFile(outFile, df):

out_handle = open(outFile, 'w')

df.to_csv(out_handle, sep = ',' , float_format = '%.4f', index
=False, index_label = None, mode = 'w', line_terminator =
'\n')

out_handle.close()


def get_index_list(strt, stop, dFrm):

index = dFrm.loc[strt: stop:].index

return np.array(index, dtype = int)
Project 6 Data file ● The data file is the AudUsd.csv file ● This data is the forex currency month time frame data • There are 248 months of data in the file ● Screen shot of the first few lines of the file Note that each line contains five pieces of data, delimited by the comma Date, Open, High, Low, Close 12/1/1994, 0.7688,0.78, 0.7656,0.775 1/1/1995, 0.775, 0.7765, 0.755, 0.7563 2/1/1995, 0.7564, 0.7605, 0.735, 0.7387 3/1/1995, 0.7388,0.7472, 0.7212, 0.7335 4/1/1995, 0.7338,0.7462, 0.7228,0.7275 5/1/1995, 0.7274, 0.744, 0.7119, 0.7177 6/1/1995, 0.7179,0.7288,0.7072, 0.7092 7/1/1995, 0.7104, 0.7409, 0.707,0.7383 8/1/1995, 0.7381, 0.7591, 0.7293, 0.7509 9/1/1995, 0.7503, 0.7671, 0.7435, 0.7551 10/1/1995, 0.7553, 0.7705, 0.7447,0.7605 3

Project 6 Problem to solve Read the data file Calculate the average price from the high and low ● Add this new data to an 'Average' column in the data frame • Write the new data frame to file • Read the newly written data frame == • Plot all the data and regression models: linear (n 1) and cubic (n == 3) • Plot the index value on the x axis ● Plot the average price value on the y axis Plot a subset of the data and the linear and cubic regression models for this subset ● Subset start value: 20 ● Subset stop value: 80

Project 6 Modified data file . The modified file has the added column for the Average That is, the average of the high and the low prices ● Date, Open, High, Low, Close, Average 12/1/1994, 0.7688, 0.7800, 0.7656,0.7750,0.7728 1/1/1995, 0.7750,0.7765, 0.7550,0.7563, 0.7657 2/1/1995, 0.7564, 0.7605, 0.7350,0.7387,0.7477 3/1/1995, 0.7388,0.7472,0.7212,0.7335, 0.7342 4/1/1995, 0.7338,0.7462,0.7228,0.7275, 0.7345 5/1/1995, 0.7274,0.7440,0.7119, 0.7177,0.7280 6/1/1995, 0.7179,0.7288, 0.7072, 0.7092, 0.7180 7/1/1995, 0.7104,0.7409, 0.7070, 0.7383,0.7240 8/1/1995, 0.7381,0.7591,0.7293,0.7509, 0.7442 9/1/1995, 0.7503, 0.7671, 0.7435, 0.7551, 0.7553 10/1/1995, 0.7553, 0.7705, 0.7447, 0.7605,0.7576

Project 6 Program output ● · Plot all the data 11 10 Price 0.9 0.8 0.7 0.6 0.5 AudUsd Ave Month Prices; months 0 to 248 -Ave AudUsd Prices model degree: 1 model degree: 3 50 0 100 Month 150 ückenfe 200 250

Project 6 Program output ● · Plot all the data 11 10 Price 0.9 0.8 0.7 0.6 0.5 AudUsd Ave Month Prices; months 0 to 248 -Ave AudUsd Prices model degree: 1 model degree: 3 50 0 100 Month 150 ückenfe 200 250

To begin solving Project 6 do the following: • Create a new folder named yourLastName-project6 folder ● Copy the utilitiesModule.py file from Lab 20 and paste in this folder function in that module • You will need the formatRegressionGraph() ● Copy the pandaUtilities.py file from Lab 20 and paste this inside this folder ● This file does not need to be modified ● From the Canvas Project 6 Assignment area, download the AudUsd.csv file and save this in the yourLastName-project6 folder ● Start a new Python file named project6.py Save this inside the yourLastName-project6 folder • Verify that your name is in the header of all .py files ● After understanding the problem that needs to be solved, identify the pseudocode that you will need to follow to solve this ● This will help you avoid "spaghetti code." 9

Program requirements: ● The program generates correct output ● The output must be similar to what is seen in the sample output in earlier slides • The program implements a plotData() function • The docstring displayed in an earlier slide specifies the requirements of this function ● The program meets all the criteria in the grading rubric • The grading rubric is available in the Project 6 assignment area ● of Canvas

Possible pseudocode that you may follow to meet the requirements of the plotData() function in Project 6: def plotData(pDegrees, start, stop, dFrm, strCol): Assumes: pDegrees is a list of ints of regression model degrees start is an int which is the beginning of the subset to plot stop is an int which is the end of the subset to plot dFrm is the DataFrame strCol is a string which specifies the column to plot on y axis Function plots the experimental data and the models specified by pDegrees The index values are on the x axis The data, and predicted values, in the column specified by strCol are on the y axis #format string that will be plot title #construct numpy array of the column's data #set up the figure. plt.figure() #get the indexVals of the data frame rows #set up numpy array of vals on y axis #first plot the experimental data #iterate through all values of n in pDegrees for n in pDegrees: #get the predicted values of this model #set up strings for the plot #now plot the regression model #after exiting for loop annotate the plot plt.title(strTitle) plt.xlabel('Month') plt.ylabel('Price') plt.legend (loc = 'best') 58 59

A 1 Date Open High Low 2 0.7688 0.78 3 1/1/1995 0.775 0.7765 4 2/1/1995 0.7564 0.7605 5 3/1/1995 0.7388 0.7472 0.7212 6 4/1/1995 0.7338 0.7462 0.7228 7 5/1/1995 0.7274 0.744 0.7119 8 6/1/1995 0.7179 0.7288 0.7072 0.7104 0.7409 0.707 9 7/1/1995 10 8/1/1995 0.7381 0.7591 0.7293 IT Close 0.7656 0.775 0.755 0.7563 0.735 0.7387 0.7335 0.7275 0.7177 0.7092 0.7383 0.7509
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply