මේ Post එකෙන් කතා කරන්නේ Python භාවිතා කරලා Linear Regression Model එක ඉදිරිපත් කරන්නේ කියලා.


 import matplotlib.pyplot as plt

import numpy as np


# Example data set

study_hours = [2, 3, 5, 7, 8, 9, 10, 12, 14, 15]

test_scores = [65, 75, 85, 75, 90, 95, 80, 85, 90, 95]


# Linear regression line coefficients

m = 5

b = 50


# Generate x values for the regression line

x_regression = np.linspace(min(study_hours), max(study_hours), 100)


# Calculate y values for the regression line

y_regression = m * x_regression + b


# Create scatter plot of the data points

plt.scatter(study_hours, test_scores, color="blue", label="Data Points")


# Plot the regression line

plt.plot(x_regression, y_regression, color="red", label="Regression Line")


# Add labels and title

plt.xlabel("Study Hours")

plt.ylabel("Test Scores")

plt.title("Linear Regression Example")


# Add legend

plt.legend()


# Display the plot

plt.show()


Output