datfid 0.1.13__py3-none-any.whl → 0.1.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datfid/client.py +102 -0
- {datfid-0.1.13.dist-info → datfid-0.1.15.dist-info}/METADATA +1 -1
- datfid-0.1.15.dist-info/RECORD +7 -0
- datfid-0.1.13.dist-info/RECORD +0 -7
- {datfid-0.1.13.dist-info → datfid-0.1.15.dist-info}/WHEEL +0 -0
- {datfid-0.1.13.dist-info → datfid-0.1.15.dist-info}/licenses/LICENSE +0 -0
- {datfid-0.1.13.dist-info → datfid-0.1.15.dist-info}/top_level.txt +0 -0
datfid/client.py
CHANGED
|
@@ -144,3 +144,105 @@ class DATFIDClient:
|
|
|
144
144
|
except Exception as e:
|
|
145
145
|
self.logger.error(f"Forecast generation failed: {str(e)}")
|
|
146
146
|
raise
|
|
147
|
+
|
|
148
|
+
def fit_model_ind(
|
|
149
|
+
self,
|
|
150
|
+
df: pd.DataFrame,
|
|
151
|
+
id_col: str,
|
|
152
|
+
time_col: str,
|
|
153
|
+
y: str,
|
|
154
|
+
lag_y: Optional[Union[int, str, list[int]]] = None,
|
|
155
|
+
lagged_features: Optional[Dict[str, int]] = None,
|
|
156
|
+
current_features: Optional[list] = None,
|
|
157
|
+
filter_by_significance: bool = False,
|
|
158
|
+
meanvar_test: bool = False
|
|
159
|
+
) -> SimpleNamespace:
|
|
160
|
+
"""
|
|
161
|
+
Fit a model individual by individual using the DATFID API.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
df: DataFrame containing the data
|
|
165
|
+
id_col: Name of the ID column
|
|
166
|
+
time_col: Name of the time column
|
|
167
|
+
y: Name of the target variable
|
|
168
|
+
lagged_features: Dictionary of features and their lag values
|
|
169
|
+
current_features: List of current features to use
|
|
170
|
+
filter_by_significance: Whether to filter features by significance
|
|
171
|
+
meanvar_test: Whether to perform mean-variance test
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
SimpleNamespace containing the model fit results
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
df = df.copy()
|
|
178
|
+
for col in df.columns:
|
|
179
|
+
if pd.api.types.is_datetime64_any_dtype(df[col]):
|
|
180
|
+
df[col] = df[col].astype(str)
|
|
181
|
+
|
|
182
|
+
data = {
|
|
183
|
+
"df": df.to_dict(orient="records"),
|
|
184
|
+
"id_col": id_col,
|
|
185
|
+
"time_col": time_col,
|
|
186
|
+
"y": y,
|
|
187
|
+
"lag_y": lag_y,
|
|
188
|
+
"lagged_features": lagged_features or {},
|
|
189
|
+
"current_features": current_features or [],
|
|
190
|
+
"filter_by_significance": filter_by_significance,
|
|
191
|
+
"meanvar_test": meanvar_test
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
response = requests.post(
|
|
195
|
+
f"{self.api_url}modelfit_ind/",
|
|
196
|
+
json=data,
|
|
197
|
+
headers=self.headers
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
if response.status_code != 200:
|
|
201
|
+
raise Exception(f"Model fit failed: {response.text}")
|
|
202
|
+
|
|
203
|
+
result_dict = response.json()
|
|
204
|
+
return SimpleNamespace(**result_dict)
|
|
205
|
+
|
|
206
|
+
def forecast_model_ind(
|
|
207
|
+
self,
|
|
208
|
+
df_forecast: pd.DataFrame
|
|
209
|
+
) -> pd.DataFrame:
|
|
210
|
+
"""
|
|
211
|
+
Generate forecasts using the fitted individual by individual model.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
df_forecast: DataFrame containing the forecast data
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
DataFrame containing the forecast results
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
try:
|
|
221
|
+
df_forecast = df_forecast.copy()
|
|
222
|
+
for col in df_forecast.columns:
|
|
223
|
+
if pd.api.types.is_datetime64_any_dtype(df_forecast[col]):
|
|
224
|
+
df_forecast[col] = df_forecast[col].astype(str)
|
|
225
|
+
|
|
226
|
+
# Convert DataFrame to list of records
|
|
227
|
+
data = df_forecast.to_dict(orient="records")
|
|
228
|
+
|
|
229
|
+
response = requests.post(
|
|
230
|
+
f"{self.api_url}modelforecast_ind/",
|
|
231
|
+
json=data,
|
|
232
|
+
headers=self.headers
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
if response.status_code != 200:
|
|
236
|
+
raise Exception(f"Forecast generation failed: {response.text}")
|
|
237
|
+
|
|
238
|
+
result = pd.DataFrame(response.json())
|
|
239
|
+
|
|
240
|
+
# Clean up memory after operation
|
|
241
|
+
del df_forecast
|
|
242
|
+
del data
|
|
243
|
+
self._cleanup_memory()
|
|
244
|
+
|
|
245
|
+
return result
|
|
246
|
+
except Exception as e:
|
|
247
|
+
self.logger.error(f"Forecast generation failed: {str(e)}")
|
|
248
|
+
raise
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
|
|
2
|
+
datfid/client.py,sha256=TG5uQ7CdGPPzT6AjcDIEutif1Su6b7SIlWz1ESyKeRY,8053
|
|
3
|
+
datfid-0.1.15.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
|
|
4
|
+
datfid-0.1.15.dist-info/METADATA,sha256=6Jp03iucoUMM7ewaNhOce2ju9G8zjfErSFqZj18JlHU,5146
|
|
5
|
+
datfid-0.1.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
datfid-0.1.15.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
|
|
7
|
+
datfid-0.1.15.dist-info/RECORD,,
|
datfid-0.1.13.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
|
|
2
|
-
datfid/client.py,sha256=XH8wTBsHOHT3Fl1DzDWP9PfIUxJGg24eLH7_cWuymic,4656
|
|
3
|
-
datfid-0.1.13.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
|
|
4
|
-
datfid-0.1.13.dist-info/METADATA,sha256=fleRinV54vP271uLNgLk5sTyQDy4zxw-edkcF3dSIjE,5146
|
|
5
|
-
datfid-0.1.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
-
datfid-0.1.13.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
|
|
7
|
-
datfid-0.1.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|