Assignment No:-07
Assignment Name:- Regression Analysis using Linear Regression.
Roll No:-05
import numpy as np
# Sample data: Years of Experience (X) and Salary (y)
X = np.array([1, 2, 3, 4, 5])
y = np.array([15000, 18000, 21000, 25000, 30000])
# Number of observations
n = len(X)
# Calculate slope (m) and intercept (b)
m = (n * np.sum(X * y) - np.sum(X) * np.sum(y)) / (n * np.sum(X**2) - (np.sum(X))**2)
b = (np.sum(y) - m * np.sum(X)) / n
# Print coefficients
print(f"Slope (m): {m}, Intercept (b): {b}")
# Make predictions
y_pred = m * X + b
# Print predictions
for i in range(n):
print(f"Predicted salary for {X[i]} years of experience: {y_pred[i]}")
….OUTPUT….
Assignment No:-07
Assignment Name:- Regression Analysis using Linear Regression.
Roll No:-06
import numpy as np
# Sample data: Years of Experience (X) and Salary (y)
X = np.array([1, 2, 3, 4, 5])
y = np.array([15000, 18000, 21000, 25000, 30000])
# Number of observations
n = len(X)
# Calculate slope (m) and intercept (b)
m = (n * np.sum(X * y) - np.sum(X) * np.sum(y)) / (n * np.sum(X**2) - (np.sum(X))**2)
b = (np.sum(y) - m * np.sum(X)) / n
# Print coefficients
print(f"Slope (m): {m}, Intercept (b): {b}")
# Make predictions
y_pred = m * X + b
# Print predictions
for i in range(n):
print(f"Predicted salary for {X[i]} years of experience: {y_pred[i]}")
….OUTPUT….
Assignment No:-07
Assignment Name:- Regression Analysis using Linear Regression.
Roll No:-07
import numpy as np
# Sample data: Years of Experience (X) and Salary (y)
X = np.array([1, 2, 3, 4, 5])
y = np.array([15000, 18000, 21000, 25000, 30000])
# Number of observations
n = len(X)
# Calculate slope (m) and intercept (b)
m = (n * np.sum(X * y) - np.sum(X) * np.sum(y)) / (n * np.sum(X**2) - (np.sum(X))**2)
b = (np.sum(y) - m * np.sum(X)) / n
# Print coefficients
print(f"Slope (m): {m}, Intercept (b): {b}")
# Make predictions
y_pred = m * X + b
# Print predictions
for i in range(n):
print(f"Predicted salary for {X[i]} years of experience: {y_pred[i]}")
….OUTPUT….
Assignment No:-07
Assignment Name:- Regression Analysis using Linear Regression.
Roll No:-08
import numpy as np
# Sample data: Years of Experience (X) and Salary (y)
X = np.array([1, 2, 3, 4, 5])
y = np.array([15000, 18000, 21000, 25000, 30000])
# Number of observations
n = len(X)
# Calculate slope (m) and intercept (b)
m = (n * np.sum(X * y) - np.sum(X) * np.sum(y)) / (n * np.sum(X**2) - (np.sum(X))**2)
b = (np.sum(y) - m * np.sum(X)) / n
# Print coefficients
print(f"Slope (m): {m}, Intercept (b): {b}")
# Make predictions
y_pred = m * X + b
# Print predictions
for i in range(n):
print(f"Predicted salary for {X[i]} years of experience: {y_pred[i]}")
….OUTPUT….