datfid 0.1.12__tar.gz → 0.1.14__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.
- datfid-0.1.14/PKG-INFO +155 -0
- datfid-0.1.14/README.md +129 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid/client.py +102 -0
- datfid-0.1.14/datfid.egg-info/PKG-INFO +155 -0
- {datfid-0.1.12 → datfid-0.1.14}/setup.py +2 -2
- datfid-0.1.12/PKG-INFO +0 -87
- datfid-0.1.12/README.md +0 -61
- datfid-0.1.12/datfid.egg-info/PKG-INFO +0 -87
- {datfid-0.1.12 → datfid-0.1.14}/LICENSE +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid/__init__.py +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid.egg-info/SOURCES.txt +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid.egg-info/dependency_links.txt +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid.egg-info/requires.txt +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/datfid.egg-info/top_level.txt +0 -0
- {datfid-0.1.12 → datfid-0.1.14}/setup.cfg +0 -0
datfid-0.1.14/PKG-INFO
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datfid
|
|
3
|
+
Version: 0.1.14
|
|
4
|
+
Summary: SDK to access the DATFID API hosted on Hugging Face Spaces
|
|
5
|
+
Author: DATFID
|
|
6
|
+
Author-email: igor.schapiro@datfid.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests>=2.31.0
|
|
14
|
+
Requires-Dist: pandas>=1.0.1
|
|
15
|
+
Requires-Dist: numpy<2.1,>=1.22
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# DATFID SDK
|
|
28
|
+
|
|
29
|
+
A Python SDK to access the DATFID API to forecast your data.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Easy model fitting**: Build panel data models with time-dependent and static features.
|
|
34
|
+
- **Flexible lag handling**: Specify lags for the dependent variable and selected features.
|
|
35
|
+
- **Forecasting**: Generate future predictions with aligned timestamps and IDs.
|
|
36
|
+
- **Statistical options**: Filter features by significance and apply mean-variance tests.
|
|
37
|
+
- **White box full interpretability**: Get fully interpretable model with equation, estimated parameters, and standard errors.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install datfid
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
Before using the SDK, please request an access token by emailing **admin@datfid.com** or by visiting our website [datfid.com](https://datfid.com).
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from datfid import DATFIDClient
|
|
51
|
+
|
|
52
|
+
# Initialize the client with your DATFID token
|
|
53
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
54
|
+
|
|
55
|
+
# Fit a model
|
|
56
|
+
fit_result = client.fit_model(
|
|
57
|
+
df=dataframe,
|
|
58
|
+
id_col="name of id column",
|
|
59
|
+
time_col="name of time column",
|
|
60
|
+
y="name of dependent variable",
|
|
61
|
+
lag_y="starting lag : ending lag",
|
|
62
|
+
lagged_features={
|
|
63
|
+
"feature 1": "starting lag : ending lag",
|
|
64
|
+
"feature 2": "starting lag : ending lag"
|
|
65
|
+
},
|
|
66
|
+
current_features=["feature 3", "feature 4"],
|
|
67
|
+
filter_by_significance=True/False,
|
|
68
|
+
meanvar_test=True/False
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Generate forecasts
|
|
72
|
+
forecast_df = client.forecast_model(
|
|
73
|
+
df_forecast=dataframe
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# The forecast DataFrame contains the individual IDs and timestamps
|
|
77
|
+
# from the original data plus a "forecast" column with predicted values.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Example 1
|
|
81
|
+
|
|
82
|
+
Sample dataset from GitHub (Food and Beverages demand forecasting):
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import pandas as pd
|
|
86
|
+
from datfid import DATFIDClient
|
|
87
|
+
|
|
88
|
+
# Initialize the client with your DATFID token
|
|
89
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
90
|
+
|
|
91
|
+
# Load dataset for model fitting
|
|
92
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages.xlsx"
|
|
93
|
+
df = pd.read_excel(url_fit)
|
|
94
|
+
|
|
95
|
+
# Fit the model
|
|
96
|
+
result = client.fit_model(df=df,
|
|
97
|
+
id_col="Product",
|
|
98
|
+
time_col="Time",
|
|
99
|
+
y="Revenue",
|
|
100
|
+
current_features='all',
|
|
101
|
+
filter_by_significance=True
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Load dataset for forecasting
|
|
105
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages_forecast.xlsx"
|
|
106
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
107
|
+
|
|
108
|
+
# Forecast revenue using the fitted model
|
|
109
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Example 2
|
|
113
|
+
|
|
114
|
+
Slightly larger sample dataset from GitHub (Banking sector, forecasting loan probability):
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import pandas as pd
|
|
118
|
+
from datfid import DATFIDClient
|
|
119
|
+
|
|
120
|
+
# Initialize the client with your DATFID token
|
|
121
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
122
|
+
|
|
123
|
+
# Load dataset for model fitting
|
|
124
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended.xlsx"
|
|
125
|
+
df = pd.read_excel(url_fit)
|
|
126
|
+
|
|
127
|
+
# Fit the model
|
|
128
|
+
result = client.fit_model(df=df,
|
|
129
|
+
id_col="Individual",
|
|
130
|
+
time_col="Time",
|
|
131
|
+
y="Loan Probability",
|
|
132
|
+
lag_y="1:3",
|
|
133
|
+
lagged_features={"Income Level": "1:3"},
|
|
134
|
+
filter_by_significance=True)
|
|
135
|
+
|
|
136
|
+
# Load dataset for forecasting
|
|
137
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended_forecast.xlsx"
|
|
138
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
139
|
+
|
|
140
|
+
# Forecast loan probability using the fitted model
|
|
141
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## API Reference
|
|
145
|
+
|
|
146
|
+
### DATFIDClient
|
|
147
|
+
|
|
148
|
+
#### `client = DATFIDClient(token: str)`
|
|
149
|
+
Initialize the client with your DATFID token.
|
|
150
|
+
|
|
151
|
+
#### `client.fit_model(df: pd.DataFrame, id_col: str, time_col: str, y: str, lag_y: Optional[Union[int, str, list[int]]] = None, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> SimpleNamespace`
|
|
152
|
+
Fit a model using the provided dataset.
|
|
153
|
+
|
|
154
|
+
#### `client.forecast_model(df_forecast: pd.DataFrame) -> pd.DataFrame`
|
|
155
|
+
Generate forecasts using the fitted model.
|
datfid-0.1.14/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# DATFID SDK
|
|
2
|
+
|
|
3
|
+
A Python SDK to access the DATFID API to forecast your data.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Easy model fitting**: Build panel data models with time-dependent and static features.
|
|
8
|
+
- **Flexible lag handling**: Specify lags for the dependent variable and selected features.
|
|
9
|
+
- **Forecasting**: Generate future predictions with aligned timestamps and IDs.
|
|
10
|
+
- **Statistical options**: Filter features by significance and apply mean-variance tests.
|
|
11
|
+
- **White box full interpretability**: Get fully interpretable model with equation, estimated parameters, and standard errors.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install datfid
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Before using the SDK, please request an access token by emailing **admin@datfid.com** or by visiting our website [datfid.com](https://datfid.com).
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from datfid import DATFIDClient
|
|
25
|
+
|
|
26
|
+
# Initialize the client with your DATFID token
|
|
27
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
28
|
+
|
|
29
|
+
# Fit a model
|
|
30
|
+
fit_result = client.fit_model(
|
|
31
|
+
df=dataframe,
|
|
32
|
+
id_col="name of id column",
|
|
33
|
+
time_col="name of time column",
|
|
34
|
+
y="name of dependent variable",
|
|
35
|
+
lag_y="starting lag : ending lag",
|
|
36
|
+
lagged_features={
|
|
37
|
+
"feature 1": "starting lag : ending lag",
|
|
38
|
+
"feature 2": "starting lag : ending lag"
|
|
39
|
+
},
|
|
40
|
+
current_features=["feature 3", "feature 4"],
|
|
41
|
+
filter_by_significance=True/False,
|
|
42
|
+
meanvar_test=True/False
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Generate forecasts
|
|
46
|
+
forecast_df = client.forecast_model(
|
|
47
|
+
df_forecast=dataframe
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# The forecast DataFrame contains the individual IDs and timestamps
|
|
51
|
+
# from the original data plus a "forecast" column with predicted values.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Example 1
|
|
55
|
+
|
|
56
|
+
Sample dataset from GitHub (Food and Beverages demand forecasting):
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import pandas as pd
|
|
60
|
+
from datfid import DATFIDClient
|
|
61
|
+
|
|
62
|
+
# Initialize the client with your DATFID token
|
|
63
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
64
|
+
|
|
65
|
+
# Load dataset for model fitting
|
|
66
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages.xlsx"
|
|
67
|
+
df = pd.read_excel(url_fit)
|
|
68
|
+
|
|
69
|
+
# Fit the model
|
|
70
|
+
result = client.fit_model(df=df,
|
|
71
|
+
id_col="Product",
|
|
72
|
+
time_col="Time",
|
|
73
|
+
y="Revenue",
|
|
74
|
+
current_features='all',
|
|
75
|
+
filter_by_significance=True
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Load dataset for forecasting
|
|
79
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages_forecast.xlsx"
|
|
80
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
81
|
+
|
|
82
|
+
# Forecast revenue using the fitted model
|
|
83
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Example 2
|
|
87
|
+
|
|
88
|
+
Slightly larger sample dataset from GitHub (Banking sector, forecasting loan probability):
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import pandas as pd
|
|
92
|
+
from datfid import DATFIDClient
|
|
93
|
+
|
|
94
|
+
# Initialize the client with your DATFID token
|
|
95
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
96
|
+
|
|
97
|
+
# Load dataset for model fitting
|
|
98
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended.xlsx"
|
|
99
|
+
df = pd.read_excel(url_fit)
|
|
100
|
+
|
|
101
|
+
# Fit the model
|
|
102
|
+
result = client.fit_model(df=df,
|
|
103
|
+
id_col="Individual",
|
|
104
|
+
time_col="Time",
|
|
105
|
+
y="Loan Probability",
|
|
106
|
+
lag_y="1:3",
|
|
107
|
+
lagged_features={"Income Level": "1:3"},
|
|
108
|
+
filter_by_significance=True)
|
|
109
|
+
|
|
110
|
+
# Load dataset for forecasting
|
|
111
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended_forecast.xlsx"
|
|
112
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
113
|
+
|
|
114
|
+
# Forecast loan probability using the fitted model
|
|
115
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## API Reference
|
|
119
|
+
|
|
120
|
+
### DATFIDClient
|
|
121
|
+
|
|
122
|
+
#### `client = DATFIDClient(token: str)`
|
|
123
|
+
Initialize the client with your DATFID token.
|
|
124
|
+
|
|
125
|
+
#### `client.fit_model(df: pd.DataFrame, id_col: str, time_col: str, y: str, lag_y: Optional[Union[int, str, list[int]]] = None, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> SimpleNamespace`
|
|
126
|
+
Fit a model using the provided dataset.
|
|
127
|
+
|
|
128
|
+
#### `client.forecast_model(df_forecast: pd.DataFrame) -> pd.DataFrame`
|
|
129
|
+
Generate forecasts using the fitted model.
|
|
@@ -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,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datfid
|
|
3
|
+
Version: 0.1.14
|
|
4
|
+
Summary: SDK to access the DATFID API hosted on Hugging Face Spaces
|
|
5
|
+
Author: DATFID
|
|
6
|
+
Author-email: igor.schapiro@datfid.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests>=2.31.0
|
|
14
|
+
Requires-Dist: pandas>=1.0.1
|
|
15
|
+
Requires-Dist: numpy<2.1,>=1.22
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# DATFID SDK
|
|
28
|
+
|
|
29
|
+
A Python SDK to access the DATFID API to forecast your data.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Easy model fitting**: Build panel data models with time-dependent and static features.
|
|
34
|
+
- **Flexible lag handling**: Specify lags for the dependent variable and selected features.
|
|
35
|
+
- **Forecasting**: Generate future predictions with aligned timestamps and IDs.
|
|
36
|
+
- **Statistical options**: Filter features by significance and apply mean-variance tests.
|
|
37
|
+
- **White box full interpretability**: Get fully interpretable model with equation, estimated parameters, and standard errors.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install datfid
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
Before using the SDK, please request an access token by emailing **admin@datfid.com** or by visiting our website [datfid.com](https://datfid.com).
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from datfid import DATFIDClient
|
|
51
|
+
|
|
52
|
+
# Initialize the client with your DATFID token
|
|
53
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
54
|
+
|
|
55
|
+
# Fit a model
|
|
56
|
+
fit_result = client.fit_model(
|
|
57
|
+
df=dataframe,
|
|
58
|
+
id_col="name of id column",
|
|
59
|
+
time_col="name of time column",
|
|
60
|
+
y="name of dependent variable",
|
|
61
|
+
lag_y="starting lag : ending lag",
|
|
62
|
+
lagged_features={
|
|
63
|
+
"feature 1": "starting lag : ending lag",
|
|
64
|
+
"feature 2": "starting lag : ending lag"
|
|
65
|
+
},
|
|
66
|
+
current_features=["feature 3", "feature 4"],
|
|
67
|
+
filter_by_significance=True/False,
|
|
68
|
+
meanvar_test=True/False
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Generate forecasts
|
|
72
|
+
forecast_df = client.forecast_model(
|
|
73
|
+
df_forecast=dataframe
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# The forecast DataFrame contains the individual IDs and timestamps
|
|
77
|
+
# from the original data plus a "forecast" column with predicted values.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Example 1
|
|
81
|
+
|
|
82
|
+
Sample dataset from GitHub (Food and Beverages demand forecasting):
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import pandas as pd
|
|
86
|
+
from datfid import DATFIDClient
|
|
87
|
+
|
|
88
|
+
# Initialize the client with your DATFID token
|
|
89
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
90
|
+
|
|
91
|
+
# Load dataset for model fitting
|
|
92
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages.xlsx"
|
|
93
|
+
df = pd.read_excel(url_fit)
|
|
94
|
+
|
|
95
|
+
# Fit the model
|
|
96
|
+
result = client.fit_model(df=df,
|
|
97
|
+
id_col="Product",
|
|
98
|
+
time_col="Time",
|
|
99
|
+
y="Revenue",
|
|
100
|
+
current_features='all',
|
|
101
|
+
filter_by_significance=True
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Load dataset for forecasting
|
|
105
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages_forecast.xlsx"
|
|
106
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
107
|
+
|
|
108
|
+
# Forecast revenue using the fitted model
|
|
109
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Example 2
|
|
113
|
+
|
|
114
|
+
Slightly larger sample dataset from GitHub (Banking sector, forecasting loan probability):
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import pandas as pd
|
|
118
|
+
from datfid import DATFIDClient
|
|
119
|
+
|
|
120
|
+
# Initialize the client with your DATFID token
|
|
121
|
+
client = DATFIDClient(token="your_DATFID_token")
|
|
122
|
+
|
|
123
|
+
# Load dataset for model fitting
|
|
124
|
+
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended.xlsx"
|
|
125
|
+
df = pd.read_excel(url_fit)
|
|
126
|
+
|
|
127
|
+
# Fit the model
|
|
128
|
+
result = client.fit_model(df=df,
|
|
129
|
+
id_col="Individual",
|
|
130
|
+
time_col="Time",
|
|
131
|
+
y="Loan Probability",
|
|
132
|
+
lag_y="1:3",
|
|
133
|
+
lagged_features={"Income Level": "1:3"},
|
|
134
|
+
filter_by_significance=True)
|
|
135
|
+
|
|
136
|
+
# Load dataset for forecasting
|
|
137
|
+
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended_forecast.xlsx"
|
|
138
|
+
df_forecast = pd.read_excel(url_forecast)
|
|
139
|
+
|
|
140
|
+
# Forecast loan probability using the fitted model
|
|
141
|
+
forecast = client.forecast_model(df_forecast=df_forecast)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## API Reference
|
|
145
|
+
|
|
146
|
+
### DATFIDClient
|
|
147
|
+
|
|
148
|
+
#### `client = DATFIDClient(token: str)`
|
|
149
|
+
Initialize the client with your DATFID token.
|
|
150
|
+
|
|
151
|
+
#### `client.fit_model(df: pd.DataFrame, id_col: str, time_col: str, y: str, lag_y: Optional[Union[int, str, list[int]]] = None, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> SimpleNamespace`
|
|
152
|
+
Fit a model using the provided dataset.
|
|
153
|
+
|
|
154
|
+
#### `client.forecast_model(df_forecast: pd.DataFrame) -> pd.DataFrame`
|
|
155
|
+
Generate forecasts using the fitted model.
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
# to build:
|
|
4
4
|
# 1) open this file at level of datfid-sdk folder
|
|
5
|
-
# 2) change version in this file
|
|
5
|
+
# 2) change version in this file and save it
|
|
6
6
|
# 3) delete folder datfid.egg-info
|
|
7
7
|
# 4) delete older files from dist folder
|
|
8
8
|
# 5) in terminal: python setup.py sdist bdist_wheel
|
|
@@ -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.14",
|
|
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!
|
datfid-0.1.12/PKG-INFO
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: datfid
|
|
3
|
-
Version: 0.1.12
|
|
4
|
-
Summary: SDK to access the DATFID API hosted on Hugging Face Spaces
|
|
5
|
-
Author: DATFID
|
|
6
|
-
Author-email: igor.schapiro@datfid.com
|
|
7
|
-
License: MIT
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Requires-Python: >=3.7
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE
|
|
13
|
-
Requires-Dist: requests>=2.31.0
|
|
14
|
-
Requires-Dist: pandas>=1.0.1
|
|
15
|
-
Requires-Dist: numpy<2.1,>=1.22
|
|
16
|
-
Dynamic: author
|
|
17
|
-
Dynamic: author-email
|
|
18
|
-
Dynamic: classifier
|
|
19
|
-
Dynamic: description
|
|
20
|
-
Dynamic: description-content-type
|
|
21
|
-
Dynamic: license
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
Dynamic: requires-dist
|
|
24
|
-
Dynamic: requires-python
|
|
25
|
-
Dynamic: summary
|
|
26
|
-
|
|
27
|
-
# DATFID SDK
|
|
28
|
-
|
|
29
|
-
A Python SDK to access the DATFID API running on Hugging Face Spaces.
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pip install datfid
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
from datfid import DATFIDClient
|
|
41
|
-
|
|
42
|
-
# Initialize the client with your Hugging Face token
|
|
43
|
-
client = DATFIDClient(token="your_huggingface_token")
|
|
44
|
-
|
|
45
|
-
# Fit a model
|
|
46
|
-
fit_result = client.fit_model(
|
|
47
|
-
file_path="path/to/your/data.xlsx",
|
|
48
|
-
id_col="Individual",
|
|
49
|
-
time_col="Time",
|
|
50
|
-
y="Loan Probability",
|
|
51
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
52
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
53
|
-
filter_by_significance=True,
|
|
54
|
-
meanvar_test=False
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
# Generate forecasts
|
|
58
|
-
forecast_df = client.generate_forecast(
|
|
59
|
-
file_path="path/to/your/forecast_data.xlsx",
|
|
60
|
-
id_col="Individual",
|
|
61
|
-
time_col="Time",
|
|
62
|
-
y="Loan Probability",
|
|
63
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
64
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
65
|
-
filter_by_significance=True,
|
|
66
|
-
meanvar_test=False
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
# The forecast DataFrame includes the original data plus forecast columns:
|
|
70
|
-
# - forecast: The predicted values
|
|
71
|
-
# - forecast_lower: Lower bound of the prediction interval
|
|
72
|
-
# - forecast_upper: Upper bound of the prediction interval
|
|
73
|
-
# - forecast_error: Standard error of the forecast
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## API Reference
|
|
77
|
-
|
|
78
|
-
### DATFIDClient
|
|
79
|
-
|
|
80
|
-
#### `__init__(token: str)`
|
|
81
|
-
Initialize the client with your Hugging Face token.
|
|
82
|
-
|
|
83
|
-
#### `fit_model(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> Dict[str, Any]`
|
|
84
|
-
Fit a model using the provided data.
|
|
85
|
-
|
|
86
|
-
#### `generate_forecast(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> pd.DataFrame`
|
|
87
|
-
Generate forecasts using the fitted model.
|
datfid-0.1.12/README.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# DATFID SDK
|
|
2
|
-
|
|
3
|
-
A Python SDK to access the DATFID API running on Hugging Face Spaces.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install datfid
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```python
|
|
14
|
-
from datfid import DATFIDClient
|
|
15
|
-
|
|
16
|
-
# Initialize the client with your Hugging Face token
|
|
17
|
-
client = DATFIDClient(token="your_huggingface_token")
|
|
18
|
-
|
|
19
|
-
# Fit a model
|
|
20
|
-
fit_result = client.fit_model(
|
|
21
|
-
file_path="path/to/your/data.xlsx",
|
|
22
|
-
id_col="Individual",
|
|
23
|
-
time_col="Time",
|
|
24
|
-
y="Loan Probability",
|
|
25
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
26
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
27
|
-
filter_by_significance=True,
|
|
28
|
-
meanvar_test=False
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
# Generate forecasts
|
|
32
|
-
forecast_df = client.generate_forecast(
|
|
33
|
-
file_path="path/to/your/forecast_data.xlsx",
|
|
34
|
-
id_col="Individual",
|
|
35
|
-
time_col="Time",
|
|
36
|
-
y="Loan Probability",
|
|
37
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
38
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
39
|
-
filter_by_significance=True,
|
|
40
|
-
meanvar_test=False
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
# The forecast DataFrame includes the original data plus forecast columns:
|
|
44
|
-
# - forecast: The predicted values
|
|
45
|
-
# - forecast_lower: Lower bound of the prediction interval
|
|
46
|
-
# - forecast_upper: Upper bound of the prediction interval
|
|
47
|
-
# - forecast_error: Standard error of the forecast
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## API Reference
|
|
51
|
-
|
|
52
|
-
### DATFIDClient
|
|
53
|
-
|
|
54
|
-
#### `__init__(token: str)`
|
|
55
|
-
Initialize the client with your Hugging Face token.
|
|
56
|
-
|
|
57
|
-
#### `fit_model(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> Dict[str, Any]`
|
|
58
|
-
Fit a model using the provided data.
|
|
59
|
-
|
|
60
|
-
#### `generate_forecast(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> pd.DataFrame`
|
|
61
|
-
Generate forecasts using the fitted model.
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: datfid
|
|
3
|
-
Version: 0.1.12
|
|
4
|
-
Summary: SDK to access the DATFID API hosted on Hugging Face Spaces
|
|
5
|
-
Author: DATFID
|
|
6
|
-
Author-email: igor.schapiro@datfid.com
|
|
7
|
-
License: MIT
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Requires-Python: >=3.7
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE
|
|
13
|
-
Requires-Dist: requests>=2.31.0
|
|
14
|
-
Requires-Dist: pandas>=1.0.1
|
|
15
|
-
Requires-Dist: numpy<2.1,>=1.22
|
|
16
|
-
Dynamic: author
|
|
17
|
-
Dynamic: author-email
|
|
18
|
-
Dynamic: classifier
|
|
19
|
-
Dynamic: description
|
|
20
|
-
Dynamic: description-content-type
|
|
21
|
-
Dynamic: license
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
Dynamic: requires-dist
|
|
24
|
-
Dynamic: requires-python
|
|
25
|
-
Dynamic: summary
|
|
26
|
-
|
|
27
|
-
# DATFID SDK
|
|
28
|
-
|
|
29
|
-
A Python SDK to access the DATFID API running on Hugging Face Spaces.
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pip install datfid
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
from datfid import DATFIDClient
|
|
41
|
-
|
|
42
|
-
# Initialize the client with your Hugging Face token
|
|
43
|
-
client = DATFIDClient(token="your_huggingface_token")
|
|
44
|
-
|
|
45
|
-
# Fit a model
|
|
46
|
-
fit_result = client.fit_model(
|
|
47
|
-
file_path="path/to/your/data.xlsx",
|
|
48
|
-
id_col="Individual",
|
|
49
|
-
time_col="Time",
|
|
50
|
-
y="Loan Probability",
|
|
51
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
52
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
53
|
-
filter_by_significance=True,
|
|
54
|
-
meanvar_test=False
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
# Generate forecasts
|
|
58
|
-
forecast_df = client.generate_forecast(
|
|
59
|
-
file_path="path/to/your/forecast_data.xlsx",
|
|
60
|
-
id_col="Individual",
|
|
61
|
-
time_col="Time",
|
|
62
|
-
y="Loan Probability",
|
|
63
|
-
lagged_features={"Repayment Amount": 1, "Missed Payments": 2},
|
|
64
|
-
current_features=["Credit Score", "Unemployment Rate"],
|
|
65
|
-
filter_by_significance=True,
|
|
66
|
-
meanvar_test=False
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
# The forecast DataFrame includes the original data plus forecast columns:
|
|
70
|
-
# - forecast: The predicted values
|
|
71
|
-
# - forecast_lower: Lower bound of the prediction interval
|
|
72
|
-
# - forecast_upper: Upper bound of the prediction interval
|
|
73
|
-
# - forecast_error: Standard error of the forecast
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## API Reference
|
|
77
|
-
|
|
78
|
-
### DATFIDClient
|
|
79
|
-
|
|
80
|
-
#### `__init__(token: str)`
|
|
81
|
-
Initialize the client with your Hugging Face token.
|
|
82
|
-
|
|
83
|
-
#### `fit_model(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> Dict[str, Any]`
|
|
84
|
-
Fit a model using the provided data.
|
|
85
|
-
|
|
86
|
-
#### `generate_forecast(file_path: str, id_col: str, time_col: str, y: str, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> pd.DataFrame`
|
|
87
|
-
Generate forecasts using the fitted model.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|