Forecasting incrementally with patsy
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza con los puntos de entrada dmatrix e incr_dbuilder y reproduce el ejemplo de panel no balanceado proporcionado. Investiga cómo la evaluación incremental gestiona las dependencias entre chunks y determina cómo una selección de filas podría preservar el comportamiento de retardos y de panel. Se considera terminado cuando la evaluación solicitada solo de filas está definida y demostrada para el caso de pronóstico.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This is either a feature request or a request for help with current functionality. I am doing some work with unbalanced panel data work that involves using patsy to forecast some series. Here's a basic example:
import io, pandas, patsy
#raw panel data indexed on ID, YEAR. Y is the forecast variable of interest. There are no gaps in the data for an individual entity but the panel is potentially unbalanced (meaning different start/end dates).
data = '''ID,YEAR,Y,B,C,D
1,1999,0,2,3,4
1,2000,.,2,3,4
1,2001,.,2,3,4
1,2002,.,2,3,4
2,1996,1,2,3,4
2,1997,.,2,3,4
3,1998,3,2,3,4
3,1999,3,2,3,4
3,2000,.,2,3,4
3,2001,3,2,3,4
'''
data = io.StringIO(data)
df = pandas.read_csv(data, index_col=['ID','YEAR'], na_values=['.'])
print(df)
def lag(series, n=1):
return series.groupby(level=0).shift(n)
formula = '1+lag(Y)+B+C+D' #This is the forecast equation for Y
x = patsy.dmatrix(formula,df, return_type='dataframe')
params = pandas.Series([1,2,3,4,5], index=x.columns) #these are the coefficients on the forecast vars
#Now forecast year by year
for yr in range(1997,2010):
ind = df.index.get_level_values('YEAR')==yr
x = patsy.dmatrix(formula,df, return_type='dataframe').reindex(df.index)
x = x.loc[ind]
df.loc[ind, 'Y'] = df.loc[ind, 'Y'].fillna(x@params)
print('================')
print(yr)
print(df)
Note that to produce the entire forecast we need to call dmatrix over and over. The problem that I'm having is that it is quite inefficient to have to call dmatrix on the entire DataFrame repeatedly, but because the forecast formula can contain arbitrary numbers of lags I can't just pass in a df filtered to the current year (or a set number of lags from the current year). What would be ideal is if I could replace
ind = df.index.get_level_values('YEAR')==yr
x = patsy.dmatrix(formula,df, return_type='dataframe').reindex(df.index)
x = x.loc[ind]
with version of dmatrix that takes a boolean rows and only evaluates and returns the rows that are needed
ind = df.index.get_level_values('YEAR')==yr
x = patsy.dmatrix(formula,df, return_type='dataframe', rows=ind) #evaluates only on rows there ind==True and returns a dataframe with only those rows
I thought incr_dbuilder might be able to handle this, but it seems that it expects each chunk returned is completely separate from previous chunks. That won't work in the time series/panel context.
- Lenguaje dominante
- Python
- Estrellas
- 990
- Forks
- 113
- Merge medio
- 2 d 8 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pydata/patsy
-
VarLookupDict should implement __iter__, causes CPython crash when using statsmodels in marimo notebookPosiblemente ocupada @kouyouqi123 la tomó hace 173 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Add link to license in readmePosiblemente ocupada @zheng-guannan577 la tomó hace 9 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
-
Nullable pandas dtypes crash in categorical handling: "Cannot interpret 'BooleanDtype' as a data type"Posiblemente ocupada @RaphaelFakhri la tomó hace 15 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
-
cc() truncates periodic coordinates for integer input with fractional boundsPosiblemente ocupada @ktz03 la tomó hace 39 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
Todos los issues de pydata/patsy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
Harden tools/pr_threads.sh: pass all printed thread fields through the deterministic sanitizerAbiertoarea:cli area:security enhancement priority:medium size:small
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
RonaldHensbergen/composable-data-stack#1338 ·
Los mantenedores suelen responder en 1 día
-
area:stdlib effort:S impact:med platform:linux type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
automated endpoint-dead needs-curation
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
almanac-data/climate-almanac#139 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
UKGovernmentBEIS/inspect_ai#6695 · 1 comentario ·
Los mantenedores suelen responder en 1 día