#!/usr/bin/env python # coding: utf-8 # # eypsurv # This notes demonstrates the basic usage of `epysurv` # In[2]: import sys sys.path.append("..") # In[3]: import matplotlib.pyplot as plt import pandas as pd from epysurv import data as epidata # In[4]: plt.rc("figure", figsize=(16, 8)) # Let's first get some data and plot it. We use the case counts of Salmonella Newport from Germany between 2004 and 2013. The data is already split into training and test set. We see that there are no outbreaks in the training set, but some around the end of 2011 in the test set. # In[5]: train, test = epidata.salmonella() train.head() # In[6]: fig, ax = plt.subplots() train.add_suffix("_train").plot(drawstyle="steps-post", ax=ax) test.add_suffix("_test").plot(drawstyle="steps-post", ax=ax) # Next we import some classical models: `EarsC1` and `FarringtonFlexible`. The API works really similiar to `scikit-learn`. Finally, we plot the predictions. # In[9]: from epysurv.models.timepoint import EarsC1, FarringtonFlexible from epysurv.visualization.model_diagnostics import plot_prediction, plot_confusion_matrix from sklearn.metrics import confusion_matrix # In[10]: model = EarsC1() model.fit(train) pred = model.predict(test) pred.head() # In[13]: pred.query("alarm != 0") # In[12]: plot_prediction(train, test, pred) # In[14]: model = FarringtonFlexible() model.fit(train) pred = model.predict(test) plot_prediction(train, test, pred) # By looking at the confusion matrix, we can see the the `FarringtonFlexible` successfully detected all outbreak, but also produced some false positives. # In[9]: plot_confusion_matrix(confusion_matrix(test["outbreak"], pred["alarm"]), class_names=["no outbreak", "outbreak"]); # In[ ]: # In[ ]: