# Open Ended 1 - Linear Regression on Weather Dataset (kagglehub)
import kagglehub
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score

path = kagglehub.dataset_download("muthuj7/weather-dataset")

df = pd.read_csv(path + "/weatherHistory.csv")

df = df[['Temperature (C)', 'Humidity', 'Wind Speed (km/h)']]
df = df.dropna()

X = df[['Humidity', 'Wind Speed (km/h)']]
y = df['Temperature (C)']

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

model = LinearRegression()
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

print("Mean Squared Error:", mean_squared_error(y_test, y_pred))
print("R2 Score:", r2_score(y_test, y_pred))

plt.scatter(y_test, y_pred, color='blue', label='Predicted Points')
plt.plot([y_test.min(), y_test.max()],
         [y_test.min(), y_test.max()],
         color='red', linewidth=2, label='Ideal Prediction Line')

plt.xlabel("Actual Temperature")
plt.ylabel("Predicted Temperature")
plt.title("Linear Regression Prediction")
plt.legend()
plt.show()
