diff --git a/.github/workflows/build-document.yml b/.github/workflows/build-document.yml new file mode 100644 index 0000000..cd42cf7 --- /dev/null +++ b/.github/workflows/build-document.yml @@ -0,0 +1,39 @@ +name: CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + container: + image: blang/latex + + steps: + - uses: actions/checkout@v1 + - name: install pdflatex + run: | + pdflatex -interaction=nonstopmode -halt-on-error -shell-escape stat-python-referenzkarte.tex + - name: create release + if: startsWith(github.event.ref, 'refs/tags') + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: | + Release ${{ github.ref }} generated by the CI. + draft: false + prerelease: false + - name: upload reference card + if: startsWith(github.event.ref, 'refs/tags') + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: stat-python-referenzkarte.pdf + asset_name: stat-python-referenzkarte.pdf + asset_content_type: application/pdf diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 071bd8c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -dist: trusty -language: tex -sudo: false -python: - -"3.7" - -install: - - pip install --user Pygments - - curl https://raw.githubusercontent.com/gvacaliuc/travis-ci-latex-pdf/master/texlive_install.sh > /tmp/texlive_install.sh - - source /tmp/texlive_install.sh - - tlmgr install minted lipsum upquote lineno ifplatform xstring framed tcolorbox environ trimspaces fvextra l3kernel l3packages - -cache: - directories: - - /tmp/texlive - - $HOME/.texlive - -script: -- pdflatex -interaction=nonstopmode -halt-on-error -shell-escape *.tex - -deploy: - provider: releases - api_key: $GIT_AUTH - file: "STAT_Python_Referenzkarte.pdf" - skip_cleanup: true - on: - tags: true diff --git a/README.md b/README.md index c212ce8..6ef9683 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -[![BuildStatus](https://travis-ci.org/KilnOfTheSecondFlame/python_statistics_reference_card.svg?branch=master)](https://travis-ci.org/KilnOfTheSecondFlame/python_statistics_reference_card) -[![GitHub release](https://img.shields.io/github/release/KilnOfTheSecondFlame/python_statistics_reference_card.svg)](https://github.com/KilnOfTheSecondFlame/python_statistics_reference_card/releases/latest) -[![Github All Releases](https://img.shields.io/github/downloads/KilnOfTheSecondFlame/python_statistics_reference_card/total.svg)](https://github.com/KilnOfTheSecondFlame/python_statistics_reference_card/releases) - # Reference Card for Statistics with Python -Python reference cards for statistics with Pandas and Numpy. Created by [@chefe](https://github.com/chefe/) for the Module STAT at HSLU Switzerland. +Python reference cards for statistics with Pandas and Numpy. +Created by [@chefe](https://github.com/chefe/) for the Module STAT at HSLU Switzerland. + +Build this document by running: + +``` +pdflatex -interaction=nonstopmode -halt-on-error -shell-escape *.tex +``` -[Download latest release](https://github.com/KilnOfTheSecondFlame/python_statistics_reference_card/releases/latest/) diff --git a/STAT_Python_Referenzkarte.tex b/stat-python-referenzkarte.tex similarity index 91% rename from STAT_Python_Referenzkarte.tex rename to stat-python-referenzkarte.tex index 8a0520d..04ea8b9 100644 --- a/STAT_Python_Referenzkarte.tex +++ b/stat-python-referenzkarte.tex @@ -43,7 +43,7 @@ \subsection*{Hilfe anzeigen} Hilfetext eines Packages anzeigen \\ \pythoninline{help(np.random.choice)} \\ -Hilfetext einer Funktion anzeigen +Hilfetext einer Funktion anzeigen \subsection*{Numpy Basics} \pythoninline{np.e}: Konstante mit Wert von $e$ \\ @@ -167,11 +167,11 @@ \subsection*{Pandas DataFrame} ) \end{python} -\pythoninline{frame.columns}: Spaltenname auslesen \\ +\pythoninline{frame.columns}: Spaltenname auslesen \\ \pythoninline{frame.shape}: Anzahl Zeilen und Spalten des Frames \\ -\pythoninline{frame.T}: Zeilen und Spalten vertauschen \\ +\pythoninline{frame.T}: Zeilen und Spalten vertauschen \\ \pythoninline{frame.describe()}: Kennzahlen jeder Spalte anzeigen \\ -\pythoninline{frame.mean(axis=0)}: Durchschnitt pro Spalte berechnen \\ +\pythoninline{frame.mean(axis=0)}: Durchschnitt pro Spalte berechnen \\ \pythoninline{frame.mean(axis=1)}: Durchschnitt pro Zeile berechnen \\ \pythoninline{frame.head(n)}: Erste \textit{n} Zeilen des Frames anzeigen \\ \pythoninline{frame.tail(n)}: Letzte \textit{n} Zeilen des Frames anzeigen \\ @@ -195,7 +195,7 @@ \subsection*{Umgang mit DataFrame} \pythoninline{frame.nsmallest(n, 'Luzern')} \\ \pythoninline{frame.nlargest(n, 'Luzern')} \\ -Daten im Frame nach einer Spalte sortieren und dann \\ +Daten im Frame nach einer Spalte sortieren und dann \\ \textit{n} Zeilen mit grösstem oder kleinstem Werte zurückgeben \\ \pythoninline{filtered = frame[frame['Luzern'] == 0]} \\ @@ -235,7 +235,7 @@ \subsection*{Matplotlib PyPlot} \pythoninline{plt.subplot(nrows=2, ncols=3, index=4)} \\ \pythoninline{plt.subplot(234)} \\ -Sub-Plot mit 2 Zeilen und 3 Spalten erstellen und den \\ +Sub-Plot mit 2 Zeilen und 3 Spalten erstellen und den \\ nächsten Plot an der Position 4 einfügen. Die Position wird \\ von links nach rechts und dann von oben nach unten gezählt @@ -252,7 +252,7 @@ \subsection*{Plots erstellen} \pythoninline{series.plot(kind="hist", bins=20, ...)} \\ Anzahl Klassen des Histogramm manuell festlegen \\ -\pythoninline{series.plot(kind='hist', cumulative=True, +\pythoninline{series.plot(kind='hist', cumulative=True, histtype='step', density=True)} \\ Empirische kumulative Verteilungsfunktion plotten \\ @@ -272,8 +272,9 @@ \subsection*{Plots erstellen} Plotten einer Regressionsgerade, bei welcher die Daten \\ einem Polynom ersten Grades angeglichen wurden \\ -\pythoninline{st.probplot(arr, plot=plt)} \\ -QQ-Plot anhand einer Normalverteilung\\ +\pythoninline{st.probplot(arr, dist="norm", plot=plt)} \\ +QQ-Plot anhand einer Normalverteilung \\ +Die Verteilungsart kann mit dem \textit{dist} bestimmt werden \\ \pythoninline{t = np.linspace(start, stop, amount_of_numbers)}\\ \pythoninline{plt.plot(t, f(t), linewidth=1.0)}\\ @@ -425,7 +426,7 @@ \subsubsection*{Wilcoxon-Test} \pythoninline{st.wilcoxon(arr, zero_method="wilcox",}\\ \pythoninline{ correction=True)} -Berechnet den Wilcoxon Vorzeichenrangtest, erwartet das \pythoninline{arr} schon die Differenz zweier Serien beinhaltet +Berechnet den Wilcoxon Vorzeichenrangtest, erwartet das \pythoninline{arr} schon die Differenz zweier Serien beinhaltet \vspace{0.5em}\\ \pythoninline{zero_method} : \{"pratt", "wilcox", "zsplit"\}, \textbf{optional}\\ "wilcox": Wilcox treatment: discards all zero-differences @@ -466,7 +467,7 @@ \subsection*{Varianzanalyse} \pythoninline{sns.boxplot(x="...", y="...", data=frame)} \\ Varianz-Analyse mit Boxplots zwischen \textit{x} und \textit{y} \\ -\pythoninline{sns.distplot(Fstat, kde=False, norm_hist=True, +\pythoninline{sns.distplot(Fstat, kde=False, norm_hist=True, hist_kws=dict(edgecolor="black", linewidth=2))} \\ F-Statistik plotten \\ @@ -486,10 +487,10 @@ \subsection*{Varianzanalyse} }) \end{python} \end{tcolorbox} - + \pythoninline{fit = ols("steak_id~Treatment", data=frame).fit()} \\ \pythoninline{fit.summary()} \\ -Gruppenmittelmodell berechnen zwischen der Id des \\ +Gruppenmittelmodell berechnen zwischen der Id des \\ Steaks und der ausgeführten Behandlung \\ \pythoninline{fit_pred = fit.get_prediction()} \\ @@ -540,6 +541,7 @@ \subsection*{Varianzanalyse} \vfill\null \columnbreak + \subsection*{Zeitreihen} \pythoninline{from statsmodels.tsa.seasonal } \\ \pythoninline{ import seasonal_decompose} \\ @@ -579,7 +581,7 @@ \subsection*{Zeitreihen} Zerlegen einer Zeitreihe in die verschiedenen Faktoren \\ bei einer Fenstergrösse von 12 \\ -\pythoninline{seasonal_decompose(np.log(frame["Passengers"]),} \\ +\pythoninline{seasonal_decompose(np.log(frame["Passengers"]),} \\ \pythoninline{ model="add").resid.plot()} \\ Residuen Plot von logarithmierten Daten anzeigen \\ @@ -587,7 +589,7 @@ \subsection*{Zeitreihen} \vfill\null \columnbreak -\pythoninline{seasonal_decompose(frame["Passengers"], } \\ +\pythoninline{seasonal_decompose(frame["Passengers"], } \\ \pythoninline{ model="mul").plot()} \\ Zerlegen einer Zeitreihe mit dem multiplikativen Modell \\ @@ -595,6 +597,42 @@ \subsection*{Zeitreihen} Zeitreihe so umformen, dass jede Zeile den \\ Jahresdurchschnitt eines Jahres enthält +\subsection*{Autoregressive Modelle} + +\pythoninline{from statsmodels.graphics.tsaplot } \\ +\pythoninline{ import plot_acf, plot_pacf} \\ +\pythoninline{from statsmodels.tsa.arima_model} \\ +\pythoninline{ import ARMA, ArmaProcess} \\ +Benötigte Bibliotheksfunktionen für Autoregressive Modelle + +\pythoninline{plot_acf(frame, lags=50)} \\ +Prüft ob ein Autoregressives modell angebracht ist \\ + +\pythoninline{plot_pacf(frame, lags=50)} \\ +Findet den parameter $p$ heraus (grösste nicht im \\ +Weissen Rauschen verschwindender Wert) \\ + +\pythoninline{model = ARMA(frame, order=(p, 0).fit()} \\ +Erstellt ein autoregressives Modell mit parameter $p$ \\ + +\pythoninline{frame.plot()} \\ +\pythoninline{(frame["Passengers"] - model.resid).plot()} \\ +Vergleich zwischen Daten und Modell \\ + +\pythoninline{fig, ax = plt.subplots()} \\ +\pythoninline{ax = frame.plot(ax=ax)} \\ +\pythoninline{model.plot_predict("start", "end",} \\ +\pythoninline{ dynamic=True, ax=ax, plot_insample=True)} \\ +Vorhersagen des Modells erstellen \\ + +\pythoninline{process = ArmaProcess([a_1, a_2, ...], ma=[1])} \\ +Erstellen eines theoretischen autoregressiven Prozesses \\ +$a_n$, stellt die polynomialparameter dar \\ + +% TODO Remove, just for layout purposes +\vfill\null +\columnbreak + \subsection*{Allgemein} \pythoninline{from scipy.special import comb} \\ \pythoninline{comb(N=5, k=3, exact=True)} \\