```python
from statsmodels.tsa.seasonal import seasonal_decompose
import matplotlib.pyplot as plt
import scipy.stats as st
import seaborn as sns
import pandas as pd
from scipy.stats import norm, uniform, expon, t, probplot
import scipy.stats as st
from scipy.integrate import quad
from sympy.solvers import solve
from sympy import Symbol
import numpy as np
from pandas import Series, DataFrame
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.stattools import acf
from pandas.plotting import lag_plot
```


```python
w = DataFrame(np.random.normal(size=1000))
MA = DataFrame(w.rolling(window=3).mean()).dropna()
plot_acf(MA, lags=12, c="C1")
plt.vlines(x=2.1, ymin=0, ymax=1/3, color="red", linestyle='--', label="Geschaetzt")
plt.vlines(x=1.1, ymin=0, ymax=2/3, color="red", linestyle='--')
plt.vlines(x=0.1, ymin=0, ymax=1, color="red", linestyle='--')
plt.legend()

```


```python
df = pd.read_table("wave.dat")
```


```python
df.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>waveht</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>367</td>
    </tr>
    <tr>
      <th>1</th>
      <td>407</td>
    </tr>
    <tr>
      <th>2</th>
      <td>-255</td>
    </tr>
    <tr>
      <th>3</th>
      <td>-515</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-500</td>
    </tr>
  </tbody>
</table>
</div>




```python
df.plot()
plt.xlabel("Time")
plt.ylabel("Wave height (mm)")
plt.show()
```


```python
df.loc[0:59,:].plot()
plt.xlabel("Time")
plt.ylabel("Wave height (mm)")
plt.show()
```


```python
from statsmodels.tsa.stattools import acf, plot_acf
acf(df["waveht"])[1]
```




    0.47025639618837917




```python

```


```python
lag_plot(df,1)
plt.xlabel("x_t")
plt.ylabel("x_(t+k)")
plt.show()
```


```python
acf(df["waveht"])[[2,3,5,10]]
```

    C:\Users\flori\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:541: FutureWarning: fft=True will become the default in a future version of statsmodels. To suppress this warning, explicitly set fft=False.
      warnings.warn(msg, FutureWarning)





    array([-0.26291153, -0.49891702, -0.21499293, -0.07431329])




```python
plt.subplot(221)
lag_plot(df,2)
plt.xlabel("x_t")
plt.ylabel("x_(t+k)")
plt.subplot(222)
lag_plot(df,3)
plt.xlabel("x_t")
plt.ylabel("x_(t+k)")
plt.subplot(223)
lag_plot(df,5)
plt.xlabel("x_t")
plt.ylabel("x_(t+k)")
plt.subplot(224)
lag_plot(df,10)
plt.xlabel("x_t")
plt.ylabel("x_(t+k)")
plt.show()
```


```python
plot_acf(df["waveht"])
```


```python
AirP = pd.read_csv("AirPassengers.csv")
AirP.head()
AirP["TravelDate"] = pd.to_datetime(AirP["TravelDate"])
AirP.set_index("TravelDate", inplace = True)
AirP.head()
plot_acf(AirP["Passengers"])
```


```python
from statsmodels.tsa.seasonal import seasonal_decompose
remainder = seasonal_decompose(AirP["Passengers"], model="multiplicative").resid[6:138]
```


```python
remainder.plot()
```


```python
plot_acf(remainder, lags = 21)
```


```python
print(AirP["Passengers"][6:138].std())
trend = seasonal_decompose(AirP["Passengers"], model="multiplicative").trend[6:138]
print((AirP["Passengers"][6:138]-trend).std())
decomp = seasonal_decompose(AirP["Passengers"])
seasonal_decompose(AirP["Passengers"], model="multiplicative").plot()
print((decomp.observed - decomp.trend)[6:138].std())
print(seasonal_decompose(AirP["Passengers"]).resid[6:138].std())
```


```python
], model="multiplicative")
```

3a547a42e06b9e394ab28a26e20d7d39a5e91a97
ipynb
Jupyter Notebook
Lernphase/SW12/Skript.ipynb
florianbaer/STAT
7cb86406ed99b88055c92c1913b46e8995835cbb
MIT
Lernphase/SW12/Skript.ipynb
florianbaer/STAT
7cb86406ed99b88055c92c1913b46e8995835cbb
MIT
Lernphase/SW12/Skript.ipynb
florianbaer/STAT
7cb86406ed99b88055c92c1913b46e8995835cbb
MIT
Qwen/Qwen-72B
1. YES
2. YES