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
icon
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
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
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
C++ Programming: From Problem Analysis to Program…
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
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
A Guide to SQL
A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr
Principles of Information Systems (MindTap Course…
Principles of Information Systems (MindTap Course…
Computer Science
ISBN:
9781285867168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning