datfid 0.1.16__tar.gz → 0.1.17__tar.gz
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.
Potentially problematic release.
This version of datfid might be problematic. Click here for more details.
- {datfid-0.1.16 → datfid-0.1.17}/PKG-INFO +1 -1
- {datfid-0.1.16 → datfid-0.1.17}/datfid/client.py +34 -5
- {datfid-0.1.16 → datfid-0.1.17}/datfid.egg-info/PKG-INFO +1 -1
- {datfid-0.1.16 → datfid-0.1.17}/setup.py +1 -1
- {datfid-0.1.16 → datfid-0.1.17}/LICENSE +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/README.md +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/datfid/__init__.py +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/datfid.egg-info/SOURCES.txt +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/datfid.egg-info/dependency_links.txt +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/datfid.egg-info/requires.txt +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/datfid.egg-info/top_level.txt +0 -0
- {datfid-0.1.16 → datfid-0.1.17}/setup.cfg +0 -0
|
@@ -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
|
-
) -> Dict[str,
|
|
188
|
+
) -> Dict[str, FitResult]:
|
|
160
189
|
"""
|
|
161
190
|
Fit a model individual by individual using the DATFID API.
|
|
162
191
|
|
|
@@ -202,7 +231,7 @@ class DATFIDClient:
|
|
|
202
231
|
|
|
203
232
|
raw = response.json() # { "<id>": { ... per-id result ... }, ... }
|
|
204
233
|
# Wrap each per-id result into a SimpleNamespace for dot access:
|
|
205
|
-
result_per_id = {str(k):
|
|
234
|
+
result_per_id = {str(k): FitResult(**v) for k, v in raw.items()}
|
|
206
235
|
return result_per_id # Dict[str, SimpleNamespace]
|
|
207
236
|
|
|
208
237
|
def forecast_model_ind(
|
|
@@ -17,7 +17,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
17
17
|
|
|
18
18
|
setup(
|
|
19
19
|
name="datfid",
|
|
20
|
-
version="0.1.
|
|
20
|
+
version="0.1.17",
|
|
21
21
|
description="SDK to access the DATFID API hosted on Hugging Face Spaces",
|
|
22
22
|
long_description=long_description,
|
|
23
23
|
long_description_content_type="text/markdown", # Important!
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|