datfid 0.1.16__py3-none-any.whl → 0.1.18__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 +39 -5
- {datfid-0.1.16.dist-info → datfid-0.1.18.dist-info}/METADATA +1 -1
- datfid-0.1.18.dist-info/RECORD +7 -0
- datfid-0.1.16.dist-info/RECORD +0 -7
- {datfid-0.1.16.dist-info → datfid-0.1.18.dist-info}/WHEEL +0 -0
- {datfid-0.1.16.dist-info → datfid-0.1.18.dist-info}/licenses/LICENSE +0 -0
- {datfid-0.1.16.dist-info → datfid-0.1.18.dist-info}/top_level.txt +0 -0
datfid/client.py
CHANGED
|
@@ -9,6 +9,40 @@ 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
|
+
@property
|
|
18
|
+
def id(self):
|
|
19
|
+
"""Return list of all individual IDs"""
|
|
20
|
+
return list(self.keys())
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def _df4(rows_list):
|
|
24
|
+
if not isinstance(rows_list, list):
|
|
25
|
+
return rows_list
|
|
26
|
+
return pd.DataFrame(rows_list, index=FitResult._ROW4[:len(rows_list)])
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def _df_perf(rows_list):
|
|
30
|
+
if not isinstance(rows_list, list):
|
|
31
|
+
return rows_list
|
|
32
|
+
return pd.DataFrame(rows_list, index=FitResult._PERF5[:len(rows_list)])
|
|
33
|
+
|
|
34
|
+
def __init__(self, **kwargs):
|
|
35
|
+
# Convert list→DataFrame for table-like fields
|
|
36
|
+
if "alpha" in kwargs:
|
|
37
|
+
kwargs["alpha"] = self._df4(kwargs["alpha"])
|
|
38
|
+
if "beta" in kwargs:
|
|
39
|
+
kwargs["beta"] = self._df4(kwargs["beta"])
|
|
40
|
+
if "Performance" in kwargs:
|
|
41
|
+
kwargs["Performance"] = self._df_perf(kwargs["Performance"])
|
|
42
|
+
if "df" in kwargs and isinstance(kwargs["df"], list):
|
|
43
|
+
kwargs["df"] = pd.DataFrame(kwargs["df"])
|
|
44
|
+
super().__init__(**kwargs)
|
|
45
|
+
|
|
12
46
|
class DATFIDClient:
|
|
13
47
|
def __init__(self, token: str):
|
|
14
48
|
self.api_url = "https://datfid-org-datfid-sdk.hf.space/"
|
|
@@ -54,7 +88,7 @@ class DATFIDClient:
|
|
|
54
88
|
current_features: Optional[list] = None,
|
|
55
89
|
filter_by_significance: bool = False,
|
|
56
90
|
meanvar_test: bool = False
|
|
57
|
-
) ->
|
|
91
|
+
) -> FitResult:
|
|
58
92
|
"""
|
|
59
93
|
Fit a model using the DATFID API.
|
|
60
94
|
|
|
@@ -99,8 +133,8 @@ class DATFIDClient:
|
|
|
99
133
|
raise Exception(f"Model fit failed: {response.text}")
|
|
100
134
|
|
|
101
135
|
result_dict = response.json()
|
|
102
|
-
return
|
|
103
|
-
|
|
136
|
+
return FitResult(**result_dict)
|
|
137
|
+
|
|
104
138
|
def forecast_model(
|
|
105
139
|
self,
|
|
106
140
|
df_forecast: pd.DataFrame
|
|
@@ -156,7 +190,7 @@ class DATFIDClient:
|
|
|
156
190
|
current_features: Optional[list] = None,
|
|
157
191
|
filter_by_significance: bool = False,
|
|
158
192
|
meanvar_test: bool = False
|
|
159
|
-
) -> Dict[str,
|
|
193
|
+
) -> Dict[str, FitResult]:
|
|
160
194
|
"""
|
|
161
195
|
Fit a model individual by individual using the DATFID API.
|
|
162
196
|
|
|
@@ -202,7 +236,7 @@ class DATFIDClient:
|
|
|
202
236
|
|
|
203
237
|
raw = response.json() # { "<id>": { ... per-id result ... }, ... }
|
|
204
238
|
# Wrap each per-id result into a SimpleNamespace for dot access:
|
|
205
|
-
result_per_id = {str(k):
|
|
239
|
+
result_per_id = {str(k): FitResult(**v) for k, v in raw.items()}
|
|
206
240
|
return result_per_id # Dict[str, SimpleNamespace]
|
|
207
241
|
|
|
208
242
|
def forecast_model_ind(
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
|
|
2
|
+
datfid/client.py,sha256=J-ite930zdIlU-ExEhcWCdhIIITxqyXuUAIdDKeCpoI,9477
|
|
3
|
+
datfid-0.1.18.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
|
|
4
|
+
datfid-0.1.18.dist-info/METADATA,sha256=qU93KNxZgZNSS2Fq2txjRJob3OyKNTTowioPqTkN36A,5146
|
|
5
|
+
datfid-0.1.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
datfid-0.1.18.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
|
|
7
|
+
datfid-0.1.18.dist-info/RECORD,,
|
datfid-0.1.16.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
datfid/__init__.py,sha256=PojdUQsimZvawR8lgqVpzs3EkRtkA7iwuDk7fovJF54,34
|
|
2
|
-
datfid/client.py,sha256=uza0OZBtm5aQF0xdFF2TIBUOYeQ9zYmX-hS8-OBXWqw,8267
|
|
3
|
-
datfid-0.1.16.dist-info/licenses/LICENSE,sha256=5b2JLb1-P8Nt919phjUmP0umS82SxGMlIF2QFn9ILgM,1084
|
|
4
|
-
datfid-0.1.16.dist-info/METADATA,sha256=frz6VkxxFwrNeY7-ZbN2U4H7nCwN3-DIH9WkEQyHJtU,5146
|
|
5
|
-
datfid-0.1.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
-
datfid-0.1.16.dist-info/top_level.txt,sha256=VFG23u9NMNQJ8S_IFfW-S5d8oSUd71SFA346ovh_uxA,7
|
|
7
|
-
datfid-0.1.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|