!pip install pystan==2.19.1.1 prophet import numpy as np import pandas as pd import tensorflow as tf import seaborn as sns import matplotlib.pyplot as plt import tensorflow as tf import os from sklearn.preprocessing import MinMaxScaler from prophet import Prophet from prophet.plot import add_changepoints_to_plot, plot_plotly, plot_components_plotly import warnings import plotly.graph_objects as go import plotly.express as px warnings.filterwarnings("ignore") sns.set_theme() data = pd.read_csv('/content/Final dataset - CHITTAGONG 2023-01-20 to 2023-02-18.csv') data.head() # Prepare data for Prophet days = int(7) predicted_data = pd.DataFrame() model1 = Prophet() df_for_humidity=data[['Date', 'Humidity%']] df_for_humidity['Date']=pd.to_datetime(df_for_humidity['Date']) df_for_humidity.rename(columns = {'Date':'ds'}, inplace = True) df_for_humidity.rename(columns = {'Humidity%':'y'}, inplace = True) model1.fit(df_for_humidity) future = model1.make_future_dataframe(periods = days) future.tail(5) forecast = model1.predict(future) predicted_data['Date'] = forecast['ds'] predicted_data['Humidity%'] = forecast['yhat'] # forecast = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']] forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail() fig = model1.plot(forecast,figsize=(26, 6)) # fig = m.plot(forecast,figsize=(20, 12)) a = add_changepoints_to_plot(fig.gca(), model1, forecast) plt.xlabel('Date') plt.ylabel('Humidity') plt.tight_layout() plt.show() data1 = pd.read_csv('/content/Final dataset - CHITTAGONG 2023-01-20 to 2023-02-18.csv') data1.head() model2 = Prophet() df_for_temp=data1[['Date', 'Temparature(c)']] df_for_temp df_for_temp['Date']=pd.to_datetime(df_for_temp['Date']) df_for_temp.rename(columns = {'Date':'ds'}, inplace = True) df_for_temp.rename(columns = {'Temparature(c)': 'y'}, inplace = True) df_for_temp model2.fit(df_for_temp) future = model2.make_future_dataframe(periods = days) future.tail(5) forecast = model2.predict(future) predicted_data['Temparature(c)'] = forecast['yhat'] # forecast = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']] forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail() fig = model2.plot(forecast,figsize=(26, 6)) # fig = m.plot(forecast,figsize=(20, 12)) a = add_changepoints_to_plot(fig.gca(), model2, forecast) plt.xlabel('Date') plt.ylabel('Temperature') plt.tight_layout() plt.show() predicted_data.iloc[-7:,:] from sklearn import linear_model from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error, r2_score ls = linear_model.LinearRegression() X = data["Humidity%"].values.reshape(-1,1) y = data["Temparature(c)"].values.reshape(-1,1) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, shuffle=True, random_state=0) print("Linear Regression") ls.fit(X_train, y_train) print("alpha = ",ls.coef_[0]) print("beta = ",ls.intercept_) print("\n\nCalculating some regression quality metrics") y_pred = ls.predict(X_test) print("MSE = ",mean_squared_error(y_test, y_pred)) print("R2 = ",r2_score(y_test, y_pred))