-
Notifications
You must be signed in to change notification settings - Fork 0
Stepshift
ViEWS uses a bespoke modelling approach which involves shifting all independent variables in time, in order to train models that can predict future values of the dependent variable. This approach is described in more detail in Appendix A of Hegre et al. (2020).
The modelling technique is implemented in a python package called stepshift
, which can be installed using pip
:
pip install stepshift
Stepshift has a module called stepshift.views
which contains a class called
StepshiftedModels
. This class wraps the stepshifting procedure, exposing a
simple, Scikit-Learn-like (but not equivalent) API. The model takes three
arguments: A scikit learn estimator, a list containing integers, which denotes
the steps, and a string variable which is the name of the dependent variable:
from sklearn.linear_model import LogisticRegression
from stepshift.views import StepshiftedModels
mdl = StepshiftedModels(LogisticRegression(),[1,2,3,4,5,6,7,8],"outcome")
This model(s) object can subsequently be fitted to a time-unit indexed pandas dataframe, like so:
# In this example, the train partition is comprised of time units 1:100
mdl.fit(dataframe.loc[1:100,:])
Similarly, model outputs are produced by using the .predict
method
predictions = mdl.predict(dataframe.loc[101:150,:])
- Hegre H, Bell C, Colaresi M, et al. ViEWS2020: Revising and evaluating the ViEWS political Violence Early-Warning System. Journal of Peace Research. 2021;58(3):599-611. doi:10.1177/0022343320962157
The contents of this repository is the outcome of projects that have received funding from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (Grant agreement No. 694640, ViEWS) and Horizon Europe (Grant agreement No. 101055176, ANTICIPATE; and No. 101069312, ViEWS (ERC-2022-POC1)), Riksbankens Jubileumsfond (Grant agreement No. M21-0002, Societies at Risk), Uppsala University, Peace Research Institute Oslo, the United Nations Economic and Social Commission for Western Asia (ViEWS-ESCWA), the United Kingdom Foreign, Commonwealth & Development Office (GSRA – Forecasting Fatalities in Armed Conflict), the Swedish Research Council (DEMSCORE), the Swedish Foundation for Strategic Environmental Research (MISTRA Geopolitics), the Norwegian MFA (Conflict Trends QZA-18/0227), and the United Nations High Commissioner for Refugees (the Sahel Predictive Analytics project).