import pandas as pd #handling data in CSV format
from sklearn.linear_model import LinearRegression #To create and train a linear regression 

data = pd.read_csv(r'C:\Users\udai9\AI_lamp\Arduino_readings.csv') #Reading the arduino data from the CSV file

#Getting the input and output ready for the model
X = data["LDR"].values.reshape(-1, 1)
y = data["LED"].values.reshape(-1, 1)

model = LinearRegression() #This creates the linear regression model


model.fit(X, y) #training the model with the x value(ldr) and y value(led)

w = model.coef_[0][0] #how much y changes with x,slope of the line(the model)
b = model.intercept_[0] #value of y when x = 0 

#shows us the model parameters 
print("Coefficients (Weights):", w)
print("Intercept (Bias):", b)

#makes a prediction on what the led value should be when ldr = 83
prediction = w * 83 + b
print("Prediction for a value of 83:", prediction)