0% found this document useful (0 votes)
12 views4 pages

DM Practical07

The document contains multiple assignments focused on regression analysis using linear regression, with each assignment showcasing the same code structure. The code calculates the slope and intercept for a linear regression model based on years of experience and salary data, and then makes predictions. Each assignment outputs the calculated coefficients and predicted salaries for given years of experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

DM Practical07

The document contains multiple assignments focused on regression analysis using linear regression, with each assignment showcasing the same code structure. The code calculates the slope and intercept for a linear regression model based on years of experience and salary data, and then makes predictions. Each assignment outputs the calculated coefficients and predicted salaries for given years of experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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….

You might also like