Menu

[Solved]-Python Dont Copy Entire Code Work Inside Function Def Zipflaw Wf1 Need Create X Index List Q37170741

python. dont have to copy this entire code, just have to workinside the function def ZipfLaw(wf1): need to create x (index oflist from 1 to length of list) and y (normalised frequency of list,divide every element in list by sum of total number of words)createlists of length. Then need to take log transform of every elementthen do linear regression to find slope and expoential ofintercept. You dont have to plot. Thanks ·Write code to plot the normalized data from the file on a log-log plot using matplotlib. Your plot should include axes labelmport sys 2import re Bimport matplotlib.pyplot as plt 4 5######### HINT: These libraries are useful ######## 6from math impor26 27 # calculate 1) the slope (m) and 2) the intercept 28 # from the above equations by using stats. Linregress from SciPy 2the first ten numbers of theinput .txt file

220386151254582510741073103438851014420069964376332195430395539782653872477·Write code to plot the normalized data from the file on a log-log plot using matplotlib. Your plot should include axes labels, and a plot abe Write code to compute the linear regression of the logarithms of the data, i.e., use stats.linregress (xl,yl) where xl is the log of each of the indices 1,..,n (here, n 5,000), and yl is the log of each of the normalized frequencies yi, . . . , yn Plot the regression line on the log-log plot. Note, if the regression line returns slope m and intercept b then you should plot the function y-ex”, since this corresponds to log(y) = m log(x) + b. Your code to generate the regression line should be written as a function that takes as input the unnormalized (but sorted) frequencies fi..n (with fi > ..>n), and returns the slope m and intercept b of the above regression line mport sys 2import re Bimport matplotlib.pyplot as plt 4 5######### HINT: These libraries are useful ######## 6from math import log, exp from collections import Counter 8from scipy import stats 9import numpy as np 10 12def ZipfLaw_coef(wf1): 13 14 wfl (list of int): word counts (the occurrence of words, 15 16 17 18 The above regression holds: 19 Thus, the regression line has: b = exp(intercept) 20 21 sorted by frequency in descending order) log(y)log (b) + m * log(x) log(b)intercept; mslope Recall this becomes # generate x, y from wfL x= [1,1,1,1] # placeholder y- 23 [1, 1, 1, 1] # placeholder 25 26 26 27 # calculate 1) the slope (m) and 2) the intercept 28 # from the above equations by using stats. Linregress from SciPy 29 30 31 32 slope, intercept 1,1 # placeholder 34 35 return x, y, slope, exp(intercept) 36 37 38def ZipfLaw plot(x, y. slope, intercept, outputFileName): 39 40 41 y (list of float): 42 slope (float): 43 intercept (float): 44 outputFileName (str): the file name of the resultant figure 45 46 plt.figure() # return x, y, slope, b 1,. ..,len(y) normalized frequencies slope of the linear regression line intercept of the linear regression line x (list of int): Show transcribed image text ·Write code to plot the normalized data from the file on a log-log plot using matplotlib. Your plot should include axes labels, and a plot abe Write code to compute the linear regression of the logarithms of the data, i.e., use stats.linregress (xl,yl) where xl is the log of each of the indices 1,..,n (here, n 5,000), and yl is the log of each of the normalized frequencies yi, . . . , yn Plot the regression line on the log-log plot. Note, if the regression line returns slope m and intercept b then you should plot the function y-ex”, since this corresponds to log(y) = m log(x) + b. Your code to generate the regression line should be written as a function that takes as input the unnormalized (but sorted) frequencies fi..n (with fi > ..>n), and returns the slope m and intercept b of the above regression line
mport sys 2import re Bimport matplotlib.pyplot as plt 4 5######### HINT: These libraries are useful ######## 6from math import log, exp from collections import Counter 8from scipy import stats 9import numpy as np 10 12def ZipfLaw_coef(wf1): 13 14 wfl (list of int): word counts (the occurrence of words, 15 16 17 18 The above regression holds: 19 Thus, the regression line has: b = exp(intercept) 20 21 sorted by frequency in descending order) log(y)log (b) + m * log(x) log(b)intercept; mslope Recall this becomes # generate x, y from wfL x= [1,1,1,1] # placeholder y- 23 [1, 1, 1, 1] # placeholder 25 26
26 27 # calculate 1) the slope (m) and 2) the intercept 28 # from the above equations by using stats. Linregress from SciPy 29 30 31 32 slope, intercept 1,1 # placeholder 34 35 return x, y, slope, exp(intercept) 36 37 38def ZipfLaw plot(x, y. slope, intercept, outputFileName): 39 40 41 y (list of float): 42 slope (float): 43 intercept (float): 44 outputFileName (str): the file name of the resultant figure 45 46 plt.figure() # return x, y, slope, b 1,. ..,len(y) normalized frequencies slope of the linear regression line intercept of the linear regression line x (list of int):

Expert Answer


Answer to python. dont have to copy this entire code, just have to work inside the function def ZipfLaw(wf1): need to create x (in… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *