Plotting • Plot the generated data points, the true line y = ax + ẞ, and the fitted line y [17]: def plot_fit(n): alpha beta = = np.random. uniform (1.0,5.0) np.random.uniform (0.0, 10.0) x, y = generate_data(n) slope = find_optimal_slope (x, y) intercept = find_optimal_intercept(x,y) fitted line = slope x + intercept true_line = alphax beta plot_fit (50) = wxwo on the same plot. ← 古早 G
Plotting • Plot the generated data points, the true line y = ax + ẞ, and the fitted line y [17]: def plot_fit(n): alpha beta = = np.random. uniform (1.0,5.0) np.random.uniform (0.0, 10.0) x, y = generate_data(n) slope = find_optimal_slope (x, y) intercept = find_optimal_intercept(x,y) fitted line = slope x + intercept true_line = alphax beta plot_fit (50) = wxwo on the same plot. ← 古早 G
Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter20: Queuing Theory
Section20.2: Modeling Arrival And Service Processes
Problem 3P
Related questions
Question
alpha = np.random.uniform(1.0,5.0)
beta = np.random.uniform(0.0,10.0)
def generate_data(n):
x = np.random.uniform(-10, 10)
epsilon = np.random.uniform(-n,n)
y = alpha * x + beta + epsilon
return x,y
def find_optimal_slope(x,y):
x_mean = np.mean(x)
y_mean = np.mean(y)
numerator = np.sum((x - x_mean) * (y - y_mean))
denominator = np.sum((x - x_mean)**2)
if denominator == 0:
slope = 9999999
else:
slope = numerator / denominator
return slope
def find_optimal_intercept(x,y):
slope = find_optimal_slope(x, y)
x_mean = np.mean(x)
y_mean = np.mean(y)
intercept = y_mean - slope * x_mean
return intercept
![Plotting
• Plot the generated data points, the true line y = ax + ẞ, and the fitted line y
[17]: def plot_fit(n):
alpha
beta =
=
np.random. uniform (1.0,5.0)
np.random.uniform (0.0, 10.0)
x, y = generate_data(n)
slope = find_optimal_slope (x, y)
intercept =
find_optimal_intercept(x,y)
fitted line = slope x + intercept
true_line = alphax beta
plot_fit (50)
=
wxwo on the same plot.
←
古早
G](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F098df008-9aa4-4c00-94a3-cbfce220eb9c%2F1328eb98-9ff4-48b1-9701-7ce0506fe43a%2Fil6o8xo_processed.png&w=3840&q=75)
Transcribed Image Text:Plotting
• Plot the generated data points, the true line y = ax + ẞ, and the fitted line y
[17]: def plot_fit(n):
alpha
beta =
=
np.random. uniform (1.0,5.0)
np.random.uniform (0.0, 10.0)
x, y = generate_data(n)
slope = find_optimal_slope (x, y)
intercept =
find_optimal_intercept(x,y)
fitted line = slope x + intercept
true_line = alphax beta
plot_fit (50)
=
wxwo on the same plot.
←
古早
G
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage

A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr

Principles of Information Systems (MindTap Course…
Computer Science
ISBN:
9781285867168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning