├── README.md └── code /README.md: -------------------------------------------------------------------------------- 1 | # Climate-Change-Impact-Analysis 2 | Climate Change Impact Analysis is a Python-based application designed to explore and analyze datasets related to temperature, precipitation, and sea level rise. 3 | -------------------------------------------------------------------------------- /code: -------------------------------------------------------------------------------- 1 | # Climate-Change-Impact-Analysis 2 | 3 | import pandas as pd 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | from sklearn.linear_model import LinearRegression 7 | from sklearn.metrics import r2_score 8 | 9 | # Load dataset (example: temperature and precipitation data) 10 | def load_data(file_path): 11 | """Load climate data from a CSV file.""" 12 | data = pd.read_csv(file_path, parse_dates=['Date']) 13 | data.set_index('Date', inplace=True) 14 | return data 15 | 16 | # Preprocess dataset 17 | def preprocess_data(data): 18 | """Handle missing values and resample to yearly means.""" 19 | data = data.resample('Y').mean() 20 | data = data.interpolate(method='linear') 21 | return data 22 | 23 | # Trend Analysis 24 | def trend_analysis(data, column): 25 | """Perform linear regression to detect trends.""" 26 | X = np.array(range(len(data))).reshape(-1, 1) 27 | y = data[column].values 28 | model = LinearRegression() 29 | model.fit(X, y) 30 | trend = model.predict(X) 31 | r2 = r2_score(y, trend) 32 | return trend, r2 33 | 34 | # Plot trends 35 | def plot_trends(data, column, trend): 36 | """Plot the original data and the trend line.""" 37 | plt.figure(figsize=(10, 6)) 38 | plt.plot(data.index, data[column], label=f'Actual {column}') 39 | plt.plot(data.index, trend, label=f'Trend line', linestyle='--') 40 | plt.title(f'{column} Trend Analysis') 41 | plt.xlabel('Year') 42 | plt.ylabel(column) 43 | plt.legend() 44 | plt.grid(True) 45 | plt.show() 46 | 47 | # Main function 48 | def main(): 49 | file_path = 'climate_data.csv' # Your CSV file path here 50 | data = load_data(file_path) 51 | data = preprocess_data(data) 52 | 53 | # Analyze Temperature 54 | temp_trend, temp_r2 = trend_analysis(data, 'Temperature') 55 | print(f"Temperature Trend R^2: {temp_r2:.2f}") 56 | plot_trends(data, 'Temperature', temp_trend) 57 | 58 | # Analyze Precipitation 59 | precip_trend, precip_r2 = trend_analysis(data, 'Precipitation') 60 | print(f"Precipitation Trend R^2: {precip_r2:.2f}") 61 | plot_trends(data, 'Precipitation', precip_trend) 62 | 63 | if __name__ == "__main__": 64 | main() 65 | --------------------------------------------------------------------------------