GitLab wurde erfolgreich aktualisiert. Durch regelmäßige Updates bleibt das THM GitLab sicher. Danke für Ihre Geduld.

Commit f18fc5a0 authored by Jens Plüddemann's avatar Jens Plüddemann

added sea ice

parent b82869c7
PID,ST_NUM,ST_NAME,OWN_OCCUPIED,NUM_BEDROOMS,NUM_BATH,SQ_FT
100001000,104,PUTNAM,Y,3,1,1000
100002000,197,LEXINGTON,N,3,1.5,--
100003000,,LEXINGTON,N,n/a,1,850
100004000,201,BERKELEY,12,1,NaN,700
100005000,203,BERKELEY,Y,3,2,1600
100006000,207,BERKELEY,Y,NA,1,800
100007000,NA,WASHINGTON,,2,HURLEY,950
100008000,213,TREMONT,Y,1,1,
100009000,215,TREMONT,Y,na,2,1800
Time,Arctic,Antarctica
1990M01,12.72,3.27
1990M02,13.33,2.15
1990M03,13.44,2.71
1990M04,12.16,5.1
1990M05,10.84,7.37
1990M06,9.12,10.26
1990M07,6.44,12.17
1990M08,4.92,13.95
1990M09,4.5,14.3
1990M10,6.67,13.71
1990M11,9.58,11.24
1990M12,11.4,6.56
1991M01,12.49,3.39
1991M02,13.15,2.01
1991M03,13.35,2.54
1991M04,12.79,5.1
1991M05,11.44,7.77
1991M06,9.6,9.87
1991M07,6.66,12.12
1991M08,5.14,13.96
1991M09,4.46,14.38
1991M10,7.7,13.7
1991M11,9.19,11.35
1991M12,11.19,6.48
1992M01,12.54,3.12
1992M02,13.51,1.79
1992M03,13.41,2.39
1992M04,12.76,4.91
1992M05,11.37,7.53
1992M06,9.89,9.9
1992M07,7.14,12.48
1992M08,5.35,14.08
1992M09,5.37,14.04
1992M10,7.69,13.76
1992M11,9.69,11.09
1992M12,11.66,6
1993M01,12.85,2.43
1993M02,13.54,1.3
1993M03,13.71,2.15
1993M04,12.95,4.82
1993M05,11.35,7.8
1993M06,9.2,10.28
1993M07,6.17,12.63
1993M08,4.65,13.83
1993M09,4.52,14.62
1993M10,6.98,14.09
1993M11,9.49,11.72
1993M12,11.41,6.49
1994M01,12.8,3.26
1994M02,13.46,2.17
1994M03,13.47,3.13
1994M04,12.84,5.38
1994M05,11.6,8.12
1994M06,9.62,10.63
1994M07,6.85,13.03
1994M08,5.1,14.39
1994M09,5.08,14.52
1994M10,7.17,13.98
1994M11,9.64,11.65
1994M12,11.43,6.95
1995M01,12.72,3.62
1995M02,13.3,2.12
1995M03,13.28,2.74
1995M04,12.32,5.35
1995M05,10.76,8.23
1995M06,8.86,10.37
1995M07,6.05,12.47
1995M08,4.61,14.16
1995M09,4.38,14.42
1995M10,5.91,13.47
1995M11,8.95,11.38
1995M12,11.02,7.03
1996M01,12.07,3.43
1996M02,12.9,1.69
1996M03,12.83,2.56
1996M04,12.23,5.28
1996M05,11.22,8.57
1996M06,9.78,11
1996M07,7.36,12.79
1996M08,5.65,13.8
1996M09,5.58,14.45
1996M10,7.49,13.85
1996M11,8.7,11.14
1996M12,10.96,6.04
1997M01,12.3,2.65
1997M02,13.36,1.66
1997M03,13.24,2.23
1997M04,12.48,4.76
1997M05,11.17,7.82
1997M06,9.14,10.12
1997M07,6.41,12.66
1997M08,5.03,14
1997M09,4.84,14.49
1997M10,6.39,14.01
1997M11,9,11.49
1997M12,11.19,6.84
1998M01,12.73,2.91
1998M02,13.7,1.81
1998M03,13.5,2.64
1998M04,12.77,5.03
1998M05,11.35,7.82
1998M06,9.11,10.25
1998M07,6.38,12.56
1998M08,4.61,13.98
1998M09,4.24,14.76
1998M10,6.65,14.45
1998M11,8.82,11.76
1998M12,10.85,6.61
1999M01,12.54,2.99
1999M02,13.38,1.7
1999M03,13.47,2.51
1999M04,13.08,5.05
1999M05,11.61,7.99
1999M06,9.18,10.74
1999M07,6.49,12.97
1999M08,4.67,14.15
1999M09,4.22,14.53
1999M10,6.77,14.13
1999M11,9.21,11.4
1999M12,10.93,6.62
2000M01,12.22,2.79
2000M02,13.02,1.63
2000M03,13.1,2.6
2000M04,12.51,5.23
2000M05,11.18,8.47
2000M06,8.99,10.95
2000M07,6.31,12.89
2000M08,4.71,14.55
2000M09,4.31,14.98
2000M10,6.64,14.16
2000M11,8.81,11.71
2000M12,10.9,6.77
2001M01,12.27,3.55
2001M02,13.14,2.38
2001M03,13.57,3.3
2001M04,12.99,5.22
2001M05,11.32,7.92
2001M06,9.01,10.47
2001M07,6.22,12.49
2001M08,4.87,13.66
2001M09,4.55,14.27
2001M10,6.59,13.24
2001M11,9.02,10.88
2001M12,10.49,6.16
2002M01,12.19,2.81
2002M02,13.36,1.75
2002M03,13.36,2.29
2002M04,12.35,4.49
2002M05,11.11,7.09
2002M06,9.13,9.6
2002M07,6.34,12.42
2002M08,4.23,13.65
2002M09,3.98,14
2002M10,6.2,13.73
2002M11,8.69,11.55
2002M12,10.58,7.47
2003M01,12.21,4.01
2003M02,13.16,2.6
2003M03,13.36,3.16
2003M04,12.38,5.48
2003M05,10.82,8.35
2003M06,9.05,11.07
2003M07,6.06,13.08
2003M08,4.44,13.66
2003M09,4.01,14.05
2003M10,5.93,13.78
2003M11,8.5,11.36
2003M12,10.74,7.03
2004M01,12.19,3.69
2004M02,12.87,2.28
2004M03,12.93,3.1
2004M04,12.08,5.33
2004M05,10.86,8.09
2004M06,9.18,10.8
2004M07,6.43,13.07
2004M08,4.57,14.15
2004M09,4.35,14.51
2004M10,6.35,14.03
2004M11,8.9,11.94
2004M12,10.91,6.76
2005M01,11.84,3.02
2005M02,12.27,1.91
2005M03,12.67,2.66
2005M04,12.16,5.12
2005M05,10.83,7.87
2005M06,8.74,10.2
2005M07,5.81,12.63
2005M08,4.14,13.86
2005M09,4.03,14.76
2005M10,5.71,13.92
2005M11,8.73,11.69
2005M12,10.51,6.12
2006M01,11.57,2.67
2006M02,12.28,1.72
2006M03,12.44,1.94
2006M04,11.97,4.2
2006M05,10.39,7.08
2006M06,8.34,10.49
2006M07,5.71,12.79
2006M08,4.24,14.45
2006M09,3.97,15.09
2006M10,5.74,14.58
2006M11,8.07,11.5
2006M12,10.1,6.28
2007M01,11.79,2.87
2007M02,12.52,1.89
2007M03,12.49,2.48
2007M04,11.75,4.62
2007M05,10.71,7.44
2007M06,8.15,10.39
2007M07,5.03,12.52
2007M08,3.11,13.94
2007M09,2.78,15.29
2007M10,4.21,14.5
2007M11,8,12.03
2007M12,10.11,8.28
2008M01,11.89,3.91
2008M02,12.81,2.32
2008M03,13.17,3.62
2008M04,12.42,6.14
2008M05,10.83,8.51
2008M06,8.47,11.31
2008M07,5.7,12.8
2008M08,3.43,13.96
2008M09,2.93,14.27
2008M10,5.4,14
2008M11,8.7,11.81
2008M12,10.6,7.15
2009M01,11.91,3.33
2009M02,12.82,1.89
2009M03,13.04,2.94
2009M04,12.54,5.86
2009M05,11.08,8.32
2009M06,8.86,10.97
2009M07,5.71,12.95
2009M08,3.79,14.29
2009M09,3.42,14.92
2009M10,4.85,14.19
2009M11,7.98,11.64
2009M12,10.17,6.87
2010M01,11.59,3.16
2010M02,12.52,2.03
2010M03,13.11,2.58
2010M04,12.43,4.88
2010M05,10.48,8.19
2010M06,7.98,11.51
2010M07,5.21,13.6
2010M08,3.54,14.78
2010M09,3.02,14.24
2010M10,5.13,14.26
2010M11,8.06,11.75
2010M12,10.02,6.67
2011M01,11.38,2.87
2011M02,12.32,1.8
2011M03,12.4,2.18
......@@ -199,13 +199,13 @@ class AirlinePassengers:
if __name__ == '__main__':
data_set = AirlinePassengers('../../res/airline-passengers.xls')
data_set.plot_initial()
data_set.plot_moving_average_without_pandas([3, 7, 11, 27])
data_set.plot_exponential_average_without_pandas()
data_set.plot_moving_averages_with_pandas([3, 7, 11, 27])
data_set.plot_auto_correlation_hyndman_without_pandas()
data_set.plot_adjacent_values()
data_set.plot_auto_correlation_with_stats_models()
data_set.plot_naive_forecast()
data_set.plot_arima_model()
# data_set.plot_initial()
# data_set.plot_moving_average_without_pandas([3, 7, 11, 27])
# data_set.plot_exponential_average_without_pandas()
# data_set.plot_moving_averages_with_pandas([3, 7, 11, 27])
# data_set.plot_auto_correlation_hyndman_without_pandas()
# data_set.plot_adjacent_values()
# data_set.plot_auto_correlation_with_stats_models()
# data_set.plot_naive_forecast()
# data_set.plot_arima_model()
data_set.plot_arima_forecast()
from typing import List
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.arima_model import ARIMA
register_matplotlib_converters()
class SeaIce:
def __init__(self, file_path: str):
df = pd.read_csv(file_path)
df['Time'] = pd.to_datetime(df['Time'], format='%YM%m')
df.insert(3, 'Arctic-Antarctica', df['Arctic'] - df['Antarctica'])
self.df = df
self.time = self.df['Time']
self.arctic = self.df['Arctic']
self.antarctica = self.df['Antarctica']
self.difference = self.df['Arctic-Antarctica']
self.to_plot = [self.arctic, self.antarctica, self.difference]
def plot_initial(self):
plt.plot(self.time, self.arctic, label='Arctic ice')
plt.plot(self.time, self.antarctica, label='Antarctic ice')
plt.plot(self.time, self.difference, label='Arctic - Antarctic ice')
plt.title('Arctic vs Antarctic vs Difference')
plt.xlabel('Time')
plt.ylabel('Ice')
plt.legend()
plt.show()
def plot_moving_averages(self, windows: List[int] = None):
if windows is None:
windows = [11, 17]
fig, ax = plt.subplots(len(self.to_plot))
plt.subplots_adjust(hspace=.5)
for idx, plot in enumerate(self.to_plot):
ax[idx].plot(self.time, plot, label=f'{plot.name} initial')
for window in windows:
rolling_mean = plot.rolling(window).mean()
ax[idx].plot(self.time, rolling_mean, label=f'{plot.name} window={window}')
ax[idx].set_title(plot.name, y=1)
ax[idx].legend(loc='lower left')
plt.show()
def plot_acf(self, lags=20):
fig, ax = plt.subplots(len(self.to_plot))
plt.subplots_adjust(hspace=.5)
for idx, plot in enumerate(self.to_plot):
plot_acf(plot, lags=20, ax=ax[idx], title=f'Autocorrelation {plot.name} with τ={lags}')
plt.show()
def plot_arima(self):
fig, ax = plt.subplots(len(self.to_plot))
plt.subplots_adjust(hspace=.5)
for idx, plot in enumerate(self.to_plot):
# Antarctica throws error
if plot.name != 'Antarctica':
res = ARIMA(plot, order=(2, 1, 2)).fit(disp=-1)
predictions = res.fittedvalues.cumsum()
ax[idx].plot(plot, label='Given data')
ax[idx].plot(res.fittedvalues, label='estimated differences')
ax[idx].plot(predictions, label='cumulated sum')
fig = res.plot_predict(200, 400)
fig.suptitle(f'{plot.name} prediction')
ax[idx].set_title(plot.name)
ax[idx].legend()
plt.show()
if __name__ == '__main__':
data_set = SeaIce('../../res/sea_ice.csv')
data_set.plot_initial()
data_set.plot_moving_averages()
data_set.plot_acf()
data_set.plot_arima()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment