autofuzzts 0.1.1__py3-none-any.whl → 0.1.3__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.
- autofuzzts/config.py +17 -17
- autofuzzts/data/data_loader.py +7 -7
- autofuzzts/data_validation/validate.py +41 -41
- autofuzzts/models/fuzzy_classifier.py +82 -82
- autofuzzts/models/mlp_nas.py +90 -90
- autofuzzts/partition/{fuzzy_clust_fun.py → fuzzy_part_fun.py} +107 -107
- autofuzzts/partition/partition.py +109 -109
- autofuzzts/partition/visualize_partition.py +32 -32
- autofuzzts/pipeline.py +469 -469
- autofuzzts/preprocess/prep_for_model.py +70 -70
- autofuzzts/preprocess/preprocess.py +62 -62
- {autofuzzts-0.1.1.dist-info → autofuzzts-0.1.3.dist-info}/METADATA +161 -146
- autofuzzts-0.1.3.dist-info/RECORD +23 -0
- {autofuzzts-0.1.1.dist-info → autofuzzts-0.1.3.dist-info}/WHEEL +1 -1
- {autofuzzts-0.1.1.dist-info → autofuzzts-0.1.3.dist-info}/licenses/LICENSE +21 -21
- autofuzzts/partition/fuzzy_clust_fun_orig.py +0 -129
- autofuzzts/utils.py +0 -1
- autofuzzts-0.1.1.dist-info/RECORD +0 -25
- {autofuzzts-0.1.1.dist-info → autofuzzts-0.1.3.dist-info}/top_level.txt +0 -0
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import pandas as pd
|
|
2
|
-
import warnings
|
|
3
|
-
from sklearn.preprocessing import LabelEncoder
|
|
4
|
-
|
|
5
|
-
def prepare_for_model(df: pd.DataFrame, number_of_lags: int):
|
|
6
|
-
"""
|
|
7
|
-
Prepare
|
|
8
|
-
|
|
9
|
-
Parameters:
|
|
10
|
-
- df (pd.DataFrame): The input DataFrame containing
|
|
11
|
-
- number_of_lags (int): The number of lag features to create.
|
|
12
|
-
|
|
13
|
-
Returns:
|
|
14
|
-
- X_train (pd.DataFrame): Features for training the model.
|
|
15
|
-
- y_train (np.ndarray): Target variable for training the model.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
# Prepare the '
|
|
19
|
-
df.loc[:, "
|
|
20
|
-
|
|
21
|
-
# Create lagged features
|
|
22
|
-
for i in range(1, number_of_lags + 1):
|
|
23
|
-
df.loc[:, "
|
|
24
|
-
df.loc[:, "membership_value_lag" + str(i)] = df["membership_value"].shift(i).copy()
|
|
25
|
-
df.loc[:, "left_lag" + str(i)] = df["left"].shift(i).copy()
|
|
26
|
-
|
|
27
|
-
# Reset warning filter
|
|
28
|
-
warnings.filterwarnings("default", category=pd.errors.SettingWithCopyWarning)
|
|
29
|
-
|
|
30
|
-
# Prepare the model DataFrame
|
|
31
|
-
df_model = df.copy()
|
|
32
|
-
df_model.drop(columns=["membership_value", "left"], inplace=True)
|
|
33
|
-
df_model.rename(columns={"X_value": "Y"}, inplace=True)
|
|
34
|
-
|
|
35
|
-
numeric_cols = df_model.select_dtypes(include=['float64', 'int64']).columns
|
|
36
|
-
df_model[numeric_cols] = df_model[numeric_cols].fillna(0)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# Separate target and features
|
|
40
|
-
y_train = df_model["
|
|
41
|
-
X_train = df_model.drop(columns=["Y", "
|
|
42
|
-
|
|
43
|
-
# Encode categorical columns
|
|
44
|
-
label_encoder = LabelEncoder()
|
|
45
|
-
encoded_cols = []
|
|
46
|
-
|
|
47
|
-
# Loop through columns and encode if they start with '
|
|
48
|
-
for col in X_train.columns:
|
|
49
|
-
if col.startswith("
|
|
50
|
-
X_train[col] = label_encoder.fit_transform(X_train[col])
|
|
51
|
-
encoded_cols.append(col)
|
|
52
|
-
|
|
53
|
-
# Label encode y_train
|
|
54
|
-
y_train = label_encoder.fit_transform(y_train)
|
|
55
|
-
|
|
56
|
-
return X_train, y_train
|
|
57
|
-
|
|
58
|
-
def prepare_for_model_val_set(df_val_fp: pd.DataFrame, df_train_fp: pd.DataFrame, n_lags: pd.DataFrame):
|
|
59
|
-
'''
|
|
60
|
-
Prepare validation set. Attach to the begginning of val set rows from the end of the train set (based on numbef of lags). In the end remove the attached rows.
|
|
61
|
-
'''
|
|
62
|
-
df_concat = pd.concat([df_train_fp.tail(n_lags), df_val_fp], axis=0).reset_index(drop=True)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
X_val, y_val = prepare_for_model(df=df_concat, number_of_lags=n_lags)
|
|
66
|
-
|
|
67
|
-
X_val = X_val.iloc[n_lags:]
|
|
68
|
-
y_val = y_val[n_lags:]
|
|
69
|
-
|
|
70
|
-
return X_val, y_val
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import warnings
|
|
3
|
+
from sklearn.preprocessing import LabelEncoder
|
|
4
|
+
|
|
5
|
+
def prepare_for_model(df: pd.DataFrame, number_of_lags: int):
|
|
6
|
+
"""
|
|
7
|
+
Prepare fuzzy partitioned data for modeling.
|
|
8
|
+
|
|
9
|
+
Parameters:
|
|
10
|
+
- df (pd.DataFrame): The input DataFrame containing fuzzy partitioned data.
|
|
11
|
+
- number_of_lags (int): The number of lag features to create.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
- X_train (pd.DataFrame): Features for training the model.
|
|
15
|
+
- y_train (np.ndarray): Target variable for training the model.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
# Prepare the 'fuzzy_set' column
|
|
19
|
+
df.loc[:, "fuzzy_set"] = df["fuzzy_set"].str.replace("set_", "").astype(int).copy()
|
|
20
|
+
|
|
21
|
+
# Create lagged features
|
|
22
|
+
for i in range(1, number_of_lags + 1):
|
|
23
|
+
df.loc[:, "fuzzy_set_lag" + str(i)] = df["fuzzy_set"].shift(i).copy()
|
|
24
|
+
df.loc[:, "membership_value_lag" + str(i)] = df["membership_value"].shift(i).copy()
|
|
25
|
+
df.loc[:, "left_lag" + str(i)] = df["left"].shift(i).copy()
|
|
26
|
+
|
|
27
|
+
# Reset warning filter
|
|
28
|
+
warnings.filterwarnings("default", category=pd.errors.SettingWithCopyWarning)
|
|
29
|
+
|
|
30
|
+
# Prepare the model DataFrame
|
|
31
|
+
df_model = df.copy()
|
|
32
|
+
df_model.drop(columns=["membership_value", "left"], inplace=True)
|
|
33
|
+
df_model.rename(columns={"X_value": "Y"}, inplace=True)
|
|
34
|
+
|
|
35
|
+
numeric_cols = df_model.select_dtypes(include=['float64', 'int64']).columns
|
|
36
|
+
df_model[numeric_cols] = df_model[numeric_cols].fillna(0)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Separate target and features
|
|
40
|
+
y_train = df_model["fuzzy_set"]
|
|
41
|
+
X_train = df_model.drop(columns=["Y", "fuzzy_set"])
|
|
42
|
+
|
|
43
|
+
# Encode categorical columns
|
|
44
|
+
label_encoder = LabelEncoder()
|
|
45
|
+
encoded_cols = []
|
|
46
|
+
|
|
47
|
+
# Loop through columns and encode if they start with 'fuzzy_set_'
|
|
48
|
+
for col in X_train.columns:
|
|
49
|
+
if col.startswith("fuzzy_set_"):
|
|
50
|
+
X_train[col] = label_encoder.fit_transform(X_train[col])
|
|
51
|
+
encoded_cols.append(col)
|
|
52
|
+
|
|
53
|
+
# Label encode y_train
|
|
54
|
+
y_train = label_encoder.fit_transform(y_train)
|
|
55
|
+
|
|
56
|
+
return X_train, y_train
|
|
57
|
+
|
|
58
|
+
def prepare_for_model_val_set(df_val_fp: pd.DataFrame, df_train_fp: pd.DataFrame, n_lags: pd.DataFrame):
|
|
59
|
+
'''
|
|
60
|
+
Prepare validation set. Attach to the begginning of val set rows from the end of the train set (based on numbef of lags). In the end remove the attached rows.
|
|
61
|
+
'''
|
|
62
|
+
df_concat = pd.concat([df_train_fp.tail(n_lags), df_val_fp], axis=0).reset_index(drop=True)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
X_val, y_val = prepare_for_model(df=df_concat, number_of_lags=n_lags)
|
|
66
|
+
|
|
67
|
+
X_val = X_val.iloc[n_lags:]
|
|
68
|
+
y_val = y_val[n_lags:]
|
|
69
|
+
|
|
70
|
+
return X_val, y_val
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import pandas as pd
|
|
2
|
-
import numpy as np
|
|
3
|
-
from sklearn.preprocessing import MinMaxScaler
|
|
4
|
-
from typing import Literal
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def preprocess_data(df: pd.DataFrame, diff_type: Literal['perc', 'abs'] = 'perc', scaler: MinMaxScaler = None) -> pd.DataFrame:
|
|
8
|
-
"""
|
|
9
|
-
Prepares time series data by calculating differences, scaling, and selecting rows.
|
|
10
|
-
|
|
11
|
-
Parameters:
|
|
12
|
-
df (pd.DataFrame): Input DataFrame with a single column named 'Y' containing the time series data.
|
|
13
|
-
diff_type (str): Type of difference to calculate ('perc' for percentage, 'abs' for absolute). Default is 'perc'.
|
|
14
|
-
n_rows (int): Number of rows to retain from the end. If -1, use all rows.
|
|
15
|
-
|
|
16
|
-
Returns:
|
|
17
|
-
np.ndarray: The preprocessed data, scaled and ready for further processing.
|
|
18
|
-
MinMaxScaler: The scaler used for scaling, useful for inverse transformation.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
# Step 1: Calculate the difference based on user choice
|
|
22
|
-
if diff_type == 'perc':
|
|
23
|
-
df['diff'] = df['Y'].pct_change() # Percentage difference
|
|
24
|
-
elif diff_type == 'abs':
|
|
25
|
-
df['diff'] = df['Y'].diff() # Absolute difference
|
|
26
|
-
else:
|
|
27
|
-
raise ValueError("Invalid diff_type. Choose 'perc' for percentage or 'abs' for absolute.")
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Replace infinite values with 1 or -1
|
|
31
|
-
df['diff'] = np.where(df['diff'] == np.inf, 1, df['diff'])
|
|
32
|
-
df['diff'] = np.where(df['diff'] == -np.inf, -1, df['diff'])
|
|
33
|
-
|
|
34
|
-
## If diff is bellow 0.01 quantile or 0.99 quantile, replace with 0.01 or 0.99 quantile
|
|
35
|
-
df['diff'] = np.where(df['diff'] < df['diff'].quantile(0.01), df['diff'].quantile(0.01), df['diff'])
|
|
36
|
-
df['diff'] = np.where(df['diff'] > df['diff'].quantile(0.99), df['diff'].quantile(0.99), df['diff'])
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
## Relace NaNs with 0
|
|
40
|
-
df['diff'] = df['diff'].fillna(0) # Replace NaNs with 0, or adjust as needed
|
|
41
|
-
|
|
42
|
-
# Step 2: Scale only the 'diff' column
|
|
43
|
-
if scaler is None: # If no scaler is provided, create a new one (otherwise use the existing one)
|
|
44
|
-
scaler = MinMaxScaler()
|
|
45
|
-
|
|
46
|
-
df_scaled = df.copy()
|
|
47
|
-
df_scaled['diff_scaled'] = scaler.fit_transform(df[['diff']]) # Scale 'diff' column only
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return df_scaled, scaler # Return scaled data and scaler for possible inverse transform
|
|
53
|
-
|
|
54
|
-
def preprocess_data_val(df: pd.DataFrame,df_train: pd.DataFrame, diff_type: Literal['perc', 'abs'] = 'perc', scaler: MinMaxScaler = None):
|
|
55
|
-
'''
|
|
56
|
-
Attach last row of train set to the beginnig of the val set and preprocess the data. In the end remove the attached row.
|
|
57
|
-
'''
|
|
58
|
-
df_concat = pd.concat([df_train.tail(1), df], axis=0)
|
|
59
|
-
df_preprocessed, scaler = preprocess_data(df=df_concat, diff_type=diff_type, scaler=scaler)
|
|
60
|
-
df_preprocessed = df_preprocessed.iloc[1:]
|
|
61
|
-
return df_preprocessed
|
|
62
|
-
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
from sklearn.preprocessing import MinMaxScaler
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def preprocess_data(df: pd.DataFrame, diff_type: Literal['perc', 'abs'] = 'perc', scaler: MinMaxScaler = None) -> pd.DataFrame:
|
|
8
|
+
"""
|
|
9
|
+
Prepares time series data by calculating differences, scaling, and selecting rows.
|
|
10
|
+
|
|
11
|
+
Parameters:
|
|
12
|
+
df (pd.DataFrame): Input DataFrame with a single column named 'Y' containing the time series data.
|
|
13
|
+
diff_type (str): Type of difference to calculate ('perc' for percentage, 'abs' for absolute). Default is 'perc'.
|
|
14
|
+
n_rows (int): Number of rows to retain from the end. If -1, use all rows.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
np.ndarray: The preprocessed data, scaled and ready for further processing.
|
|
18
|
+
MinMaxScaler: The scaler used for scaling, useful for inverse transformation.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# Step 1: Calculate the difference based on user choice
|
|
22
|
+
if diff_type == 'perc':
|
|
23
|
+
df['diff'] = df['Y'].pct_change() # Percentage difference
|
|
24
|
+
elif diff_type == 'abs':
|
|
25
|
+
df['diff'] = df['Y'].diff() # Absolute difference
|
|
26
|
+
else:
|
|
27
|
+
raise ValueError("Invalid diff_type. Choose 'perc' for percentage or 'abs' for absolute.")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Replace infinite values with 1 or -1
|
|
31
|
+
df['diff'] = np.where(df['diff'] == np.inf, 1, df['diff'])
|
|
32
|
+
df['diff'] = np.where(df['diff'] == -np.inf, -1, df['diff'])
|
|
33
|
+
|
|
34
|
+
## If diff is bellow 0.01 quantile or 0.99 quantile, replace with 0.01 or 0.99 quantile
|
|
35
|
+
df['diff'] = np.where(df['diff'] < df['diff'].quantile(0.01), df['diff'].quantile(0.01), df['diff'])
|
|
36
|
+
df['diff'] = np.where(df['diff'] > df['diff'].quantile(0.99), df['diff'].quantile(0.99), df['diff'])
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Relace NaNs with 0
|
|
40
|
+
df['diff'] = df['diff'].fillna(0) # Replace NaNs with 0, or adjust as needed
|
|
41
|
+
|
|
42
|
+
# Step 2: Scale only the 'diff' column
|
|
43
|
+
if scaler is None: # If no scaler is provided, create a new one (otherwise use the existing one)
|
|
44
|
+
scaler = MinMaxScaler()
|
|
45
|
+
|
|
46
|
+
df_scaled = df.copy()
|
|
47
|
+
df_scaled['diff_scaled'] = scaler.fit_transform(df[['diff']]) # Scale 'diff' column only
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
return df_scaled, scaler # Return scaled data and scaler for possible inverse transform
|
|
53
|
+
|
|
54
|
+
def preprocess_data_val(df: pd.DataFrame,df_train: pd.DataFrame, diff_type: Literal['perc', 'abs'] = 'perc', scaler: MinMaxScaler = None):
|
|
55
|
+
'''
|
|
56
|
+
Attach last row of train set to the beginnig of the val set and preprocess the data. In the end remove the attached row.
|
|
57
|
+
'''
|
|
58
|
+
df_concat = pd.concat([df_train.tail(1), df], axis=0)
|
|
59
|
+
df_preprocessed, scaler = preprocess_data(df=df_concat, diff_type=diff_type, scaler=scaler)
|
|
60
|
+
df_preprocessed = df_preprocessed.iloc[1:]
|
|
61
|
+
return df_preprocessed
|
|
62
|
+
|
|
63
63
|
|
|
@@ -1,146 +1,161 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: autofuzzts
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: 'Time series forecasting using fuzzy logic and AutoML'
|
|
5
|
-
Author-email: Jan Timko <jantimko16@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/
|
|
8
|
-
Project-URL: Repository, https://github.com/
|
|
9
|
-
Requires-Python: >=3.11
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
Requires-Dist: numpy>=1.26.0
|
|
13
|
-
Requires-Dist: pandas>=2.2.0
|
|
14
|
-
Requires-Dist: scikit-learn>=1.5.0
|
|
15
|
-
Requires-Dist: scipy>=1.15.0
|
|
16
|
-
Requires-Dist: xgboost>=3.0.0
|
|
17
|
-
Requires-Dist: lightgbm>=4.6.0
|
|
18
|
-
Requires-Dist: tpot>=1.0.0
|
|
19
|
-
Requires-Dist: optuna>=4.3.0
|
|
20
|
-
Requires-Dist: matplotlib>=3.10.0
|
|
21
|
-
Requires-Dist: seaborn>=0.13.0
|
|
22
|
-
Requires-Dist: requests>=2.32.0
|
|
23
|
-
Requires-Dist: PyYAML>=6.0.0
|
|
24
|
-
Requires-Dist: joblib>=1.4.0
|
|
25
|
-
Requires-Dist: tqdm>=4.67.0
|
|
26
|
-
Dynamic: license-file
|
|
27
|
-
|
|
28
|
-
# AutoFuzzTS
|
|
29
|
-
|
|
30
|
-
Time series forecasting library using fuzzy logic and automated machine learning.
|
|
31
|
-
Build and evaluate time series models automatically using fuzzy logic and AutoML techniques.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Best configuration: {
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: autofuzzts
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: 'Time series forecasting using fuzzy logic and AutoML'
|
|
5
|
+
Author-email: Jan Timko <jantimko16@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jtimko16/AutoFuzzTS
|
|
8
|
+
Project-URL: Repository, https://github.com/jtimko16/AutoFuzzTS
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: numpy>=1.26.0
|
|
13
|
+
Requires-Dist: pandas>=2.2.0
|
|
14
|
+
Requires-Dist: scikit-learn>=1.5.0
|
|
15
|
+
Requires-Dist: scipy>=1.15.0
|
|
16
|
+
Requires-Dist: xgboost>=3.0.0
|
|
17
|
+
Requires-Dist: lightgbm>=4.6.0
|
|
18
|
+
Requires-Dist: tpot>=1.0.0
|
|
19
|
+
Requires-Dist: optuna>=4.3.0
|
|
20
|
+
Requires-Dist: matplotlib>=3.10.0
|
|
21
|
+
Requires-Dist: seaborn>=0.13.0
|
|
22
|
+
Requires-Dist: requests>=2.32.0
|
|
23
|
+
Requires-Dist: PyYAML>=6.0.0
|
|
24
|
+
Requires-Dist: joblib>=1.4.0
|
|
25
|
+
Requires-Dist: tqdm>=4.67.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# AutoFuzzTS
|
|
29
|
+
|
|
30
|
+
Time series forecasting library using fuzzy logic and automated machine learning.
|
|
31
|
+
Build and evaluate time series models automatically using fuzzy logic and AutoML techniques.
|
|
32
|
+
|
|
33
|
+
The package is designed for academic benchmarking and controlled experimentation in one-step-ahead time-series forecasting. It assumes a fixed train/validation/test split and focuses on reproducible model comparison rather than real-time deployment.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install autofuzzts
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 🚀 Quick Start
|
|
42
|
+
|
|
43
|
+
### Load and prepare your time series data
|
|
44
|
+
```python
|
|
45
|
+
import pandas as pd
|
|
46
|
+
|
|
47
|
+
# Load dataset into a pandas DataFrame
|
|
48
|
+
data = pd.read_csv('../../data/sample_datasets/NYSE.csv')
|
|
49
|
+
data.head(10)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Select the target column to forecast
|
|
54
|
+
data_column_name = "Close"
|
|
55
|
+
df = data[[data_column_name]].copy()
|
|
56
|
+
|
|
57
|
+
# Split into train, validation, and test sets
|
|
58
|
+
test_len = len(df) // 5
|
|
59
|
+
val_len = len(df) // 5
|
|
60
|
+
train_len = len(df) - test_len - val_len
|
|
61
|
+
|
|
62
|
+
df_train = df[:train_len]
|
|
63
|
+
df_val = df[train_len:(train_len + val_len)]
|
|
64
|
+
df_test = df[(train_len + val_len):]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Tune hyperparameters using Bayesian search
|
|
70
|
+
```python
|
|
71
|
+
from autofuzzts import pipeline
|
|
72
|
+
|
|
73
|
+
# Run Bayesian optimization for fuzzy pipeline configuration
|
|
74
|
+
best_config, best_rmse = pipeline.tune_hyperparameters_bayes(
|
|
75
|
+
train_set=df_train,
|
|
76
|
+
val_set=df_val,
|
|
77
|
+
n_trials=20,
|
|
78
|
+
metric="rmse"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
print(f"Best configuration: {best_config}")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Example output:**
|
|
85
|
+
```
|
|
86
|
+
Best configuration: {'n_fuzzy_sets': 13, 'number_of_lags': 6, 'fuzzy_part_func': 'Cosine'}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### Train, calibrate, and predict
|
|
92
|
+
```python
|
|
93
|
+
from autofuzzts import fit_calibrate_predict
|
|
94
|
+
|
|
95
|
+
# Train model, calibrate, and make one-step-ahead predictions
|
|
96
|
+
pred_set, pred_center_points, pred_test = fit_calibrate_predict(
|
|
97
|
+
train_set=df_train,
|
|
98
|
+
test_set=df_test,
|
|
99
|
+
config=best_config,
|
|
100
|
+
model_type="xgb"
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This returns:
|
|
105
|
+
- `pred_set`: predicted fuzzy sets
|
|
106
|
+
- `pred_center_points`: corresponding fuzzy center values
|
|
107
|
+
- `pred_test`: crisp numeric predictions (one-step-ahead forecast)
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Function Overview
|
|
112
|
+
|
|
113
|
+
### `fit_calibrate_predict()`
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
fit_calibrate_predict(
|
|
117
|
+
train_set: pd.DataFrame,
|
|
118
|
+
test_set: pd.DataFrame,
|
|
119
|
+
config: dict,
|
|
120
|
+
model_type: Literal['xgb', 'mlp', 'tpot'] = 'xgb',
|
|
121
|
+
number_cv_calib: int = 5,
|
|
122
|
+
diff_type: Literal['perc', 'abs'] = 'perc',
|
|
123
|
+
covariates: list[str] | None = None,
|
|
124
|
+
exclude_bool: bool = False
|
|
125
|
+
) -> float
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Trains and calibrates a fuzzy time series model on the training set using
|
|
129
|
+
cross-validation, then predicts on the test set and returns performance metrics.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Description
|
|
134
|
+
|
|
135
|
+
AutoFuzzTS automates the process of fuzzy time series modeling by:
|
|
136
|
+
- building and testing multiple fuzzy pipelines,
|
|
137
|
+
- tuning hyperparameters using Bayesian optimization, and
|
|
138
|
+
- integrating tuned classification models - **XGBoost**, **MLP**, or **TPOT**.
|
|
139
|
+
|
|
140
|
+
This allows for rapid experimentation and selection of optimal configurations
|
|
141
|
+
for forecasting tasks.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
## 📄 Reference
|
|
145
|
+
|
|
146
|
+
This code is based on the research:
|
|
147
|
+
|
|
148
|
+
**Optimizing stock price forecasting: a hybrid approach using fuzziness and automated machine learning**
|
|
149
|
+
*Jan Timko, Radwa El Shawi, Stefania Tomasiello*
|
|
150
|
+
*Expert Systems with Applications*, Volume 259, 2025, 128844
|
|
151
|
+
|
|
152
|
+
[Read on ScienceDirect](https://www.sciencedirect.com/science/article/pii/S0957417425024613)
|
|
153
|
+
|
|
154
|
+
If you use this code in your research or projects, please cite the paper.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 📄 License
|
|
159
|
+
|
|
160
|
+
This project is licensed under the MIT License.
|
|
161
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
autofuzzts/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
2
|
+
autofuzzts/config.py,sha256=IheqZ8IH2Y7n2KZT_kYs9hVNJAWyY0zZo039TgXoFko,377
|
|
3
|
+
autofuzzts/pipeline.py,sha256=Y6AqYpPNuOLqfTO6Mt7NOvwXnZ_VY1pKPcIfWcD5kgg,15772
|
|
4
|
+
autofuzzts/data/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
5
|
+
autofuzzts/data/data_loader.py,sha256=UxpIyeerMGDeFlblWVSdfVdzQc_rv7IHh1M4BqwzxHk,259
|
|
6
|
+
autofuzzts/data_validation/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
7
|
+
autofuzzts/data_validation/validate.py,sha256=Z1YPGr_muFFfyLv3DG32a74Am7IBIeMrwjglxJKN1vg,1412
|
|
8
|
+
autofuzzts/evaluation/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
9
|
+
autofuzzts/models/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
10
|
+
autofuzzts/models/fuzzy_classifier.py,sha256=0b_EG1y90gn4ped1Zm4QMeJzRuQnxabB865vVW0lCZk,3289
|
|
11
|
+
autofuzzts/models/mlp_nas.py,sha256=-N550H7nNtZJL9d72MPVTLpFGWq7DH4QmKkh7gJMDxw,2958
|
|
12
|
+
autofuzzts/partition/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
13
|
+
autofuzzts/partition/fuzzy_part_fun.py,sha256=t3uZba9-QiKwMb9kfU-7fLJqfKT9aKmPZ7cqpqvt_lE,2992
|
|
14
|
+
autofuzzts/partition/partition.py,sha256=ih-3ulRz24JoHlpGCbTxJrmL2DdylSXWMnlzTO6zTpY,4334
|
|
15
|
+
autofuzzts/partition/visualize_partition.py,sha256=vCEefgyPuP4Jr6uL9VfrdWE80Q0StGGaPyiIrs-vUt8,879
|
|
16
|
+
autofuzzts/preprocess/__init__.py,sha256=2k_ZeqU7FvqZMFqGm-EYRiV98uxUxmiy5wXygvIobPU,13
|
|
17
|
+
autofuzzts/preprocess/prep_for_model.py,sha256=8U3VxVLi0eIOHaNQGcGVweq2V0g497cCHm4dVFX2PdE,2527
|
|
18
|
+
autofuzzts/preprocess/preprocess.py,sha256=hC_Y84JKB030dCsnTKhJVaZLy7ARlqwxpKdT7ioyET4,2724
|
|
19
|
+
autofuzzts-0.1.3.dist-info/licenses/LICENSE,sha256=0YpXiCONotJkGz-eE74pd-R3hInmIyMJ-buT7NwiLxI,1066
|
|
20
|
+
autofuzzts-0.1.3.dist-info/METADATA,sha256=ajA7jHEbk-BMM_iqe1hQXVdlcGHmfpjfk8J-R6yTStg,4321
|
|
21
|
+
autofuzzts-0.1.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
22
|
+
autofuzzts-0.1.3.dist-info/top_level.txt,sha256=YHgbVRUPg-x2WX7FKyJMUAeI9o46c8XFiR_eYKtXIxc,11
|
|
23
|
+
autofuzzts-0.1.3.dist-info/RECORD,,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Jan Timko
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jan Timko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|