aplr 10.18.0__cp310-cp310-win_amd64.whl → 10.18.1__cp310-cp310-win_amd64.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.
Potentially problematic release.
This version of aplr might be problematic. Click here for more details.
- aplr/aplr.py +40 -5
- {aplr-10.18.0.dist-info → aplr-10.18.1.dist-info}/METADATA +1 -1
- aplr-10.18.1.dist-info/RECORD +8 -0
- aplr_cpp.cp310-win_amd64.pyd +0 -0
- aplr-10.18.0.dist-info/RECORD +0 -8
- {aplr-10.18.0.dist-info → aplr-10.18.1.dist-info}/WHEEL +0 -0
- {aplr-10.18.0.dist-info → aplr-10.18.1.dist-info}/licenses/LICENSE +0 -0
- {aplr-10.18.0.dist-info → aplr-10.18.1.dist-info}/top_level.txt +0 -0
aplr/aplr.py
CHANGED
|
@@ -22,6 +22,9 @@ class BaseAPLR:
|
|
|
22
22
|
"""Common preprocessing for fit and predict."""
|
|
23
23
|
is_dataframe_input = isinstance(X, pd.DataFrame)
|
|
24
24
|
|
|
25
|
+
if X_names is not None:
|
|
26
|
+
X_names = list(X_names)
|
|
27
|
+
|
|
25
28
|
if not is_dataframe_input:
|
|
26
29
|
try:
|
|
27
30
|
X_numeric = np.array(X, dtype=np.float64)
|
|
@@ -35,11 +38,11 @@ class BaseAPLR:
|
|
|
35
38
|
X.columns = X_names
|
|
36
39
|
else:
|
|
37
40
|
X.columns = [f"X{i}" for i in range(X.shape[1])]
|
|
38
|
-
elif
|
|
41
|
+
elif self.X_names_ and len(self.X_names_) == X.shape[1]:
|
|
39
42
|
X.columns = self.X_names_
|
|
40
43
|
else: # X is already a DataFrame
|
|
41
44
|
X = X.copy() # Always copy to avoid modifying original
|
|
42
|
-
if not is_fitting and
|
|
45
|
+
if not is_fitting and self.X_names_:
|
|
43
46
|
# Check if input columns for prediction match training columns (before OHE)
|
|
44
47
|
if set(X.columns) != set(self.X_names_):
|
|
45
48
|
raise ValueError(
|
|
@@ -52,11 +55,18 @@ class BaseAPLR:
|
|
|
52
55
|
self.categorical_features_ = list(
|
|
53
56
|
X.select_dtypes(include=["category", "object"]).columns
|
|
54
57
|
)
|
|
58
|
+
# Ensure it's an empty list if no categorical features, not None
|
|
59
|
+
if not self.categorical_features_:
|
|
60
|
+
self.categorical_features_ = []
|
|
55
61
|
|
|
62
|
+
# Apply OHE if categorical_features_ were found during fitting.
|
|
56
63
|
if self.categorical_features_:
|
|
57
64
|
X = pd.get_dummies(X, columns=self.categorical_features_, dummy_na=False)
|
|
58
65
|
if is_fitting:
|
|
59
66
|
self.ohe_columns_ = list(X.columns)
|
|
67
|
+
# Ensure it's an empty list if no OHE columns, not None
|
|
68
|
+
if not self.ohe_columns_:
|
|
69
|
+
self.ohe_columns_ = []
|
|
60
70
|
else:
|
|
61
71
|
missing_cols = set(self.ohe_columns_) - set(X.columns)
|
|
62
72
|
for c in missing_cols:
|
|
@@ -65,13 +75,17 @@ class BaseAPLR:
|
|
|
65
75
|
|
|
66
76
|
if is_fitting:
|
|
67
77
|
self.na_imputed_cols_ = [col for col in X.columns if X[col].isnull().any()]
|
|
78
|
+
# Ensure it's an empty list if no NA imputed columns, not None
|
|
79
|
+
if not self.na_imputed_cols_:
|
|
80
|
+
self.na_imputed_cols_ = []
|
|
68
81
|
|
|
82
|
+
# Apply NA indicator if na_imputed_cols_ were found during fitting.
|
|
69
83
|
if self.na_imputed_cols_:
|
|
70
84
|
for col in self.na_imputed_cols_:
|
|
71
85
|
X[col + "_missing"] = X[col].isnull().astype(int)
|
|
72
86
|
|
|
73
|
-
if not is_fitting:
|
|
74
|
-
for col in self.median_values_:
|
|
87
|
+
if not is_fitting and self.median_values_:
|
|
88
|
+
for col in self.median_values_: # Iterate over keys if it's a dict
|
|
75
89
|
if col in X.columns:
|
|
76
90
|
X[col] = X[col].fillna(self.median_values_[col])
|
|
77
91
|
|
|
@@ -131,11 +145,30 @@ class BaseAPLR:
|
|
|
131
145
|
def _preprocess_X_predict(self, X):
|
|
132
146
|
X = self._common_X_preprocessing(X, is_fitting=False)
|
|
133
147
|
|
|
134
|
-
if
|
|
148
|
+
# Enforce column order from training if it was set.
|
|
149
|
+
if self.final_training_columns_:
|
|
135
150
|
X = X[self.final_training_columns_]
|
|
136
151
|
|
|
137
152
|
return X.values.astype(np.float64)
|
|
138
153
|
|
|
154
|
+
def __setstate__(self, state):
|
|
155
|
+
"""Handles unpickling for backward compatibility."""
|
|
156
|
+
self.__dict__.update(state)
|
|
157
|
+
|
|
158
|
+
# For backward compatibility, initialize new attributes to None if they don't exist,
|
|
159
|
+
# indicating the model was trained before these features were introduced.
|
|
160
|
+
new_attributes = [
|
|
161
|
+
"X_names_",
|
|
162
|
+
"categorical_features_",
|
|
163
|
+
"ohe_columns_",
|
|
164
|
+
"na_imputed_cols_",
|
|
165
|
+
"median_values_",
|
|
166
|
+
"final_training_columns_",
|
|
167
|
+
]
|
|
168
|
+
for attr in new_attributes:
|
|
169
|
+
if not hasattr(self, attr):
|
|
170
|
+
setattr(self, attr, None)
|
|
171
|
+
|
|
139
172
|
|
|
140
173
|
class APLRRegressor(BaseAPLR):
|
|
141
174
|
def __init__(
|
|
@@ -261,6 +294,7 @@ class APLRRegressor(BaseAPLR):
|
|
|
261
294
|
self.ohe_columns_ = []
|
|
262
295
|
self.na_imputed_cols_ = []
|
|
263
296
|
self.X_names_ = []
|
|
297
|
+
self.final_training_columns_ = []
|
|
264
298
|
|
|
265
299
|
# Creating aplr_cpp and setting parameters
|
|
266
300
|
self.APLRRegressor = aplr_cpp.APLRRegressor()
|
|
@@ -702,6 +736,7 @@ class APLRClassifier(BaseAPLR):
|
|
|
702
736
|
self.ohe_columns_ = []
|
|
703
737
|
self.na_imputed_cols_ = []
|
|
704
738
|
self.X_names_ = []
|
|
739
|
+
self.final_training_columns_ = []
|
|
705
740
|
|
|
706
741
|
# Creating aplr_cpp and setting parameters
|
|
707
742
|
self.APLRClassifier = aplr_cpp.APLRClassifier()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
aplr_cpp.cp310-win_amd64.pyd,sha256=GGCKNu8nv8d1pxOy3vLXsS95z2nDcTf6oDdiCM2EkKk,655872
|
|
2
|
+
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
+
aplr/aplr.py,sha256=YOXF2a5CpC6kYoLGaDOaYIXMSRrWtSwvrbxpjYzPyA0,42653
|
|
4
|
+
aplr-10.18.1.dist-info/licenses/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
+
aplr-10.18.1.dist-info/METADATA,sha256=lj9HjkVuCgcD7cKxWOpRMXrocW4r-Zzpa4HQm3UkdkA,1048
|
|
6
|
+
aplr-10.18.1.dist-info/WHEEL,sha256=KUuBC6lxAbHCKilKua8R9W_TM71_-9Sg5uEP3uDWcoU,101
|
|
7
|
+
aplr-10.18.1.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
+
aplr-10.18.1.dist-info/RECORD,,
|
aplr_cpp.cp310-win_amd64.pyd
CHANGED
|
Binary file
|
aplr-10.18.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
aplr_cpp.cp310-win_amd64.pyd,sha256=BI5uFuY-f4vFqh_O1gX6-cOZVQ4nHViNjQHVvp1espg,655872
|
|
2
|
-
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
-
aplr/aplr.py,sha256=cEI63m6-5U1VVou-CfKIQ85ys0DL8rqi9ghWFBK3BxY,41090
|
|
4
|
-
aplr-10.18.0.dist-info/licenses/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
-
aplr-10.18.0.dist-info/METADATA,sha256=Wsrqg1LzAYOKTuAcjW8s3YXmJUsjvHx1k2AWTlNntiY,1048
|
|
6
|
-
aplr-10.18.0.dist-info/WHEEL,sha256=KUuBC6lxAbHCKilKua8R9W_TM71_-9Sg5uEP3uDWcoU,101
|
|
7
|
-
aplr-10.18.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
-
aplr-10.18.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|