Question
data_filename = '' output_filename = '' figure_width, figure_height = 8,8 import numpy as np import matplotlib.pyplot as plt import statsmodels.api as sms data = np.genfromtxt(data_filename,delimiter
data_filename = '' output_filename = ''
figure_width, figure_height = 8,8 import numpy as np import matplotlib.pyplot as plt import statsmodels.api as sms
data = np.genfromtxt(data_filename,delimiter = ',')
# If there are errors importing the data, you can also copy the data in as a list. # e.g. data = [1.95878982, 2.59203983, 1.22704688, ...]
x_values = data[:,0] y_values = data[:,1] X_values = sms.add_constant(x_values) regression_model_a = sms.OLS(y_values, X_values) regression_model_b = regression_model_a.fit() print(regression_model_b.summary()) print() # blank line
gradient = regression_model_b.params[1] intercept = regression_model_b.params[0] Rsquared = regression_model_b.rsquared MSE = regression_model_b.mse_resid pvalue = regression_model_b.f_pvalue
print("gradient =", regression_model_b.params[1]) print("intercept =", regression_model_b.params[0]) print("Rsquared =", regression_model_b.rsquared) print("MSE =", regression_model_b.mse_resid) print("pvalue =", regression_model_b.f_pvalue)
# This line creates the endpoints of the best-fit line: x_lobf = [min(x_values),max(x_values)] y_lobf = [x_lobf[0]*gradient + intercept,x_lobf[1]*gradient + intercept]
# This line creates the figure. plt.figure(figsize=(figure_width,figure_height))
# Uncomment these lines (remove the #) to set the axis limits (otherwise they will be set automatically): #x_min,x_max = 0,5000000 #y_min,y_max = 0,5000000 #plt.xlim([x_min,x_max]) #plt.ylim([y_min,y_max])
# The next lines create and save the plot: plt.plot(x_values,y_values,'b.',x_lobf,y_lobf,'r--') plt.title('ABC') plt.ylabel(DFG'') plt.xlabel('HIJ') plt.savefig(output_filename)
What should I do if I want to copy the data in as a list here since there is an error uploading the file?
x= 0.40, 0.1868178, 0.0759431783, 0.725965669, 0.454626102, 0.34093881, 0.366874, 0.06364415, 0.0448837
y = 13.3, 2, 23, 4.5, 12.5, 21, 29.1, 3, 31
When I put this coding, it doesn't work
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started