datfid 0.1.15__py3-none-any.whl → 0.1.17__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 +37 -6
- {datfid-0.1.15.dist-info → datfid-0.1.17.dist-info}/METADATA +1 -1
- datfid-0.1.17.dist-info/RECORD +7 -0
- datfid-0.1.15.dist-info/RECORD +0 -7
- {datfid-0.1.15.dist-info → datfid-0.1.17.dist-info}/WHEEL +0 -0
- {datfid-0.1.15.dist-info → datfid-0.1.17.dist-info}/licenses/LICENSE +0 -0
- {datfid-0.1.15.dist-info → datfid-0.1.17.dist-info}/top_level.txt +0 -0
datfid/client.py
CHANGED
|
@@ -9,6 +9,35 @@ import gc
|
|
|
9
9
|
import psutil
|
|
10
10
|
import logging
|
|
11
11
|
|
|
12
|
+
# for nice output
|
|
13
|
+
class FitResult(SimpleNamespace):
|
|
14
|
+
_ROW4 = ["Estimate", "Standard Error", "T statistic", "P value"]
|
|
15
|
+
_PERF5 = ["R2 within", "R2 between", "R2 overall", "MSE", "MAE"]
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def _df4(rows_list):
|
|
19
|
+
if not isinstance(rows_list, list):
|
|
20
|
+
return rows_list
|
|
21
|
+
return pd.DataFrame(rows_list, index=FitResult._ROW4[:len(rows_list)])
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def _df_perf(rows_list):
|
|
25
|
+
if not isinstance(rows_list, list):
|
|
26
|
+
return rows_list
|
|
27
|
+
return pd.DataFrame(rows_list, index=FitResult._PERF5[:len(rows_list)])
|
|
28
|
+
|
|
29
|
+
def __init__(self, **kwargs):
|
|
30
|
+
# Convert list→DataFrame for table-like fields
|
|
31
|
+
if "alpha" in kwargs:
|
|
32
|
+
kwargs["alpha"] = self._df4(kwargs["alpha"])
|
|
33
|
+
if "beta" in kwargs:
|
|
34
|
+
kwargs["beta"] = self._df4(kwargs["beta"])
|
|
35
|
+
if "Performance" in kwargs:
|
|
36
|
+
kwargs["Performance"] = self._df_perf(kwargs["Performance"])
|
|
37
|
+
if "df" in kwargs and isinstance(kwargs["df"], list):
|
|
38
|
+
kwargs["df"] = pd.DataFrame(kwargs["df"])
|
|
39
|
+
super().__init__(**kwargs)
|
|
40
|
+
|
|
12
41
|
class DATFIDClient:
|
|
13
42
|
def __init__(self, token: str):
|
|
14
43
|
self.api_url = "https://datfid-org-datfid-sdk.hf.space/"
|
|
@@ -54,7 +83,7 @@ class DATFIDClient:
|
|
|
54
83
|
current_features: Optional[list] = None,
|
|
55
84
|
filter_by_significance: bool = False,
|
|
56
85
|
meanvar_test: bool = False
|
|
57
|
-
) ->
|
|
86
|
+
) -> FitResult:
|
|
58
87
|
"""
|
|
59
88
|
Fit a model using the DATFID API.
|
|
60
89
|
|
|
@@ -99,8 +128,8 @@ class DATFIDClient:
|
|
|
99
128
|
raise Exception(f"Model fit failed: {response.text}")
|
|
100
129
|
|
|
101
130
|
result_dict = response.json()
|
|
102
|
-
return
|
|
103
|
-
|
|
131
|
+
return FitResult(**result_dict)
|
|
132
|
+
|
|
104
133
|
def forecast_model(
|
|
105
134
|
self,
|
|
106
135
|
df_forecast: pd.DataFrame
|
|
@@ -156,7 +185,7 @@ class DATFIDClient:
|
|
|
156
185
|
current_features: Optional[list] = None,
|
|
157
186
|
filter_by_significance: bool = False,
|
|
158
187
|
meanvar_test: bool = False
|
|
159
|
-
) ->
|
|
188
|
+
) -> Dict[str, FitResult]:
|
|
160
189
|
"""
|
|
161
190
|
Fit a model individual by individual using the DATFID API.
|
|
162
191
|
|
|
@@ -200,8 +229,10 @@ class DATFIDClient:
|
|
|
200
229
|
if response.status_code != 200:
|
|
201
230
|
raise Exception(f"Model fit failed: {response.text}")
|
|
202
231
|
|
|
203
|
-
|
|
204
|
-
|
|
232
|
+
raw = response.json() # { "<id>": { ... per-id result ... }, ... }
|
|
233
|
+
# Wrap each per-id result into a SimpleNamespace for dot access:
|
|
234
|
+
result_per_id = {str(k): FitResult(**v) for k, v in raw.items()}
|
|
235
|
+
return result_per_id # Dict[str, SimpleNamespace]
|
|
205
236
|
|
|
206
237
|
def forecast_model_ind(
|
|
207
238
|
self,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
|
|
2
|
+
datfid/client.py,sha256=Nz5Up8cs5qjo2vKxap9NViRx0ukKXn8VTYoMVhUFf3o,9359
|
|
3
|
+
datfid-0.1.17.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
|
|
4
|
+
datfid-0.1.17.dist-info/METADATA,sha256=ISe-w7e3PLhAAbW3xZ2LhdktvdbMf7OESMmZPTR_30w,5146
|
|
5
|
+
datfid-0.1.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
datfid-0.1.17.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
|
|
7
|
+
datfid-0.1.17.dist-info/RECORD,,
|
datfid-0.1.15.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|