Dav Exp
Dav Exp
Knowledge In depth
Unable to answer Unable to answer Able to answer all
knowledge of the questions (0) few questions (1) questions (2)
Experiment (2)
Assessment Marks:
Timeline
Completion and
Organization
Program Performance
Knowledge
Total: (Out of 15)
EXPERIMENT 3
Aim
Tools Python, R
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
X = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12])
plt.scatter(X, y, color='blue')
plt.title("Scatter Plot of X vs y")
plt.xlabel("X")
plt.ylabel("y")
plt.show()
mean_X = np.mean(X)
mean_y = np.mean(y)
b1 = np.sum((X - mean_X) * (y - mean_y)) / np.sum((X -
mean_X)**2)
b0 = mean_y - b1 * mean_X
y_pred = b0 + b1 * X
x_new = 10
y_new = b0 + b1 * x_new
print(f"Predicted value of y for x = 10: y = {y_new:.2f}")
3. Perform the above task in R
4.
X <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
y <- c(1, 3, 2, 5, 7, 8, 8, 9, 10, 12)
plot(X, y, main = "Scatter Plot of X vs y", xlab = "X", ylab = "y", pch =
19, col = "blue")
regression_equation <- paste("y =", round(b0, 2), "+", round(b1, 2), "*
X")
cat("Regression Line Equation:", regression_equation, "\n")
y_pred <- b0 + b1 * X
abline(a = b0, b = b1, col = "red") # Add the regression line to the
scatter plot
x_new <- 10
y_new <- b0 + b1 * x_new # Use the regression formula to predict y
for x = 10
Conclusion