upgini 1.1.282__py3-none-any.whl → 1.1.282a3418.post2__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.

Potentially problematic release.


This version of upgini might be problematic. Click here for more details.

upgini/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.1.282"
1
+ __version__ = "1.1.282a3418-2"
@@ -1,7 +1,7 @@
1
1
  from typing import Dict
2
2
 
3
3
  from upgini.autofe.binary import Add, Divide, Max, Min, Multiply, Sim, Subtract
4
- from upgini.autofe.date import DateDiff, DateDiffType2, DateListDiff, DateListDiffBounded
4
+ from upgini.autofe.date import DateDiff, DateDiffType2, DateListDiff, DateListDiffBounded, DatePercentile
5
5
  from upgini.autofe.groupby import GroupByThenAgg, GroupByThenRank
6
6
  from upgini.autofe.operand import Operand
7
7
  from upgini.autofe.unary import Abs, Floor, Freq, Log, Residual, Sigmoid, Sqrt, Square
@@ -49,6 +49,7 @@ ALL_OPERANDS: Dict[str, Operand] = {
49
49
  DateListDiffBounded(diff_unit="Y", aggregation="count", lower_bound=30, upper_bound=45),
50
50
  DateListDiffBounded(diff_unit="Y", aggregation="count", lower_bound=45, upper_bound=60),
51
51
  DateListDiffBounded(diff_unit="Y", aggregation="count", lower_bound=60),
52
+ DatePercentile(),
52
53
  ]
53
54
  }
54
55
 
upgini/autofe/date.py CHANGED
@@ -1,9 +1,10 @@
1
- from typing import Any, Optional, Union
1
+ from datetime import date
2
+ from typing import Any, Dict, List, Optional, Union
2
3
 
3
4
  import numpy as np
4
5
  import pandas as pd
5
6
  from pandas.core.arrays.timedeltas import TimedeltaArray
6
- from pydantic import BaseModel
7
+ from pydantic import BaseModel, validator
7
8
 
8
9
  from upgini.autofe.operand import PandasOperand
9
10
 
@@ -27,6 +28,17 @@ class DateDiff(PandasOperand, DateDiffMixin):
27
28
  is_binary = True
28
29
  has_symmetry_importance = True
29
30
 
31
+ def get_params(self) -> Dict[str, Optional[str]]:
32
+ res = super().get_params()
33
+ res.update(
34
+ {
35
+ "diff_unit": self.diff_unit,
36
+ "left_unit": self.left_unit,
37
+ "right_unit": self.right_unit,
38
+ }
39
+ )
40
+ return res
41
+
30
42
  def calculate_binary(self, left: pd.Series, right: pd.Series) -> pd.Series:
31
43
  left = self._convert_to_date(left, self.left_unit)
32
44
  right = self._convert_to_date(right, self.right_unit)
@@ -42,6 +54,17 @@ class DateDiffType2(PandasOperand, DateDiffMixin):
42
54
  is_binary = True
43
55
  has_symmetry_importance = True
44
56
 
57
+ def get_params(self) -> Dict[str, Optional[str]]:
58
+ res = super().get_params()
59
+ res.update(
60
+ {
61
+ "diff_unit": self.diff_unit,
62
+ "left_unit": self.left_unit,
63
+ "right_unit": self.right_unit,
64
+ }
65
+ )
66
+ return res
67
+
45
68
  def calculate_binary(self, left: pd.Series, right: pd.Series) -> pd.Series:
46
69
  left = self._convert_to_date(left, self.left_unit)
47
70
  right = self._convert_to_date(right, self.right_unit)
@@ -64,6 +87,15 @@ class DateListDiff(PandasOperand, DateDiffMixin):
64
87
  has_symmetry_importance = True
65
88
  aggregation: str
66
89
 
90
+ def get_params(self) -> Dict[str, Optional[str]]:
91
+ res = super().get_params()
92
+ res.update(
93
+ {
94
+ "aggregation": self.aggregation,
95
+ }
96
+ )
97
+ return res
98
+
67
99
  def __init__(self, **data: Any) -> None:
68
100
  if "name" not in data:
69
101
  data["name"] = f"date_diff_{data.get('aggregation')}"
@@ -116,3 +148,55 @@ class DateListDiffBounded(DateListDiff):
116
148
  def _agg(self, x):
117
149
  x = x[(x >= (self.lower_bound or -np.inf)) & (x < (self.upper_bound or np.inf))]
118
150
  return super()._agg(x)
151
+
152
+
153
+ class DatePercentile(PandasOperand):
154
+ name = "date_per"
155
+ is_binary = True
156
+ output_type = "float"
157
+
158
+ date_unit: Optional[str] = None
159
+ zero_month: Optional[int]
160
+ zero_year: Optional[int]
161
+ zero_bounds: Optional[List[float]]
162
+ step: int = 30
163
+
164
+ def get_params(self) -> Dict[str, Optional[str]]:
165
+ res = super().get_params()
166
+ res.update(
167
+ {
168
+ "date_unit": self.date_unit,
169
+ "zero_month": self.zero_month,
170
+ "zero_year": self.zero_year,
171
+ "zero_bounds": self.zero_bounds,
172
+ "step": self.step,
173
+ }
174
+ )
175
+ return res
176
+
177
+ @validator("zero_bounds", pre=True)
178
+ def validate_bounds(cls, value):
179
+ if value is None or isinstance(value, list):
180
+ return value
181
+ elif isinstance(value, str):
182
+ return value[1:-1].split(", ")
183
+
184
+ def calculate_binary(self, left: pd.Series, right: pd.Series) -> pd.Series:
185
+ # Assuming that left is a date column, right is a feature column
186
+ left = pd.to_datetime(left, unit=self.date_unit)
187
+ months = left.dt.month
188
+ years = left.dt.year
189
+
190
+ month_diffs = 12 * (years - (self.zero_year or 0)) + (months - (self.zero_month or 0))
191
+ bounds = month_diffs.apply(
192
+ lambda d: np.array(self.zero_bounds if self.zero_bounds is not None else []) + d * 30
193
+ )
194
+
195
+ return right.index.to_series().apply(lambda i: self.__perc(right[i], bounds[i]))
196
+
197
+ def __perc(self, f, bounds):
198
+ hit = np.where(f >= bounds)[0]
199
+ if hit.size > 0:
200
+ return np.max(hit) * 10
201
+ else:
202
+ return np.nan
upgini/autofe/feature.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import hashlib
2
2
  import itertools
3
- from typing import Dict, List, Optional, Tuple, Union
3
+ from typing import Dict, List, Optional, Set, Tuple, Union
4
4
 
5
5
  import numpy as np
6
6
  import pandas as pd
@@ -16,6 +16,12 @@ class Column:
16
16
  self.data = data
17
17
  self.calculate_all = calculate_all
18
18
 
19
+ def get_display_name(self, cache: bool = True, shorten: bool = False, **kwargs) -> str:
20
+ return self.name
21
+
22
+ def set_op_params(self, params: Dict[str, str]) -> "Column":
23
+ return self
24
+
19
25
  def rename_columns(self, mapping: Dict[str, str]) -> "Column":
20
26
  self.name = self._unhash(mapping.get(self.name) or self.name)
21
27
  return self
@@ -69,19 +75,30 @@ class Feature:
69
75
  self.cached_display_name = cached_display_name
70
76
  self.alias = alias
71
77
 
72
- def set_op_params(self, params: Dict[str, str]) -> "Feature":
78
+ def set_op_params(self, params: Optional[Dict[str, str]]) -> "Feature":
79
+ obj_dict = self.op.dict().copy()
80
+ obj_dict.update(params or {})
81
+ self.op = self.op.__class__.parse_obj(obj_dict)
73
82
  self.op.set_params(params)
83
+
84
+ for child in self.children:
85
+ child.set_op_params(params)
74
86
  return self
75
87
 
76
88
  def get_hash(self) -> str:
77
- return hashlib.sha256("_".join([self.op.name] + [ch.name for ch in self.children]).encode("utf-8")).hexdigest()[
78
- :8
79
- ]
89
+ return hashlib.sha256(
90
+ "_".join([self.op.name] + [ch.get_display_name() for ch in self.children]).encode("utf-8")
91
+ ).hexdigest()[:8]
80
92
 
81
93
  def set_alias(self, alias: str) -> "Feature":
82
94
  self.alias = alias
83
95
  return self
84
96
 
97
+ def get_all_operand_names(self) -> Set[str]:
98
+ return {self.op.name}.union(
99
+ {n for f in self.children if isinstance(f, Feature) for n in f.get_all_operand_names()}
100
+ )
101
+
85
102
  def rename_columns(self, mapping: Dict[str, str]) -> "Feature":
86
103
  for child in self.children:
87
104
  child.rename_columns(mapping)
upgini/autofe/operand.py CHANGED
@@ -25,8 +25,10 @@ class Operand(BaseModel):
25
25
  self.params = params
26
26
  return self
27
27
 
28
- def get_params(self) -> Dict[str, str]:
29
- return self.params
28
+ def get_params(self) -> Dict[str, Optional[str]]:
29
+ res = {"alias": self.alias}
30
+ res.update(self.params or {})
31
+ return res
30
32
 
31
33
 
32
34
  MAIN_COLUMN = "main_column"
@@ -1442,15 +1442,12 @@ class FeaturesEnricher(TransformerMixin):
1442
1442
  if len(decimal_columns_to_fix) > 0:
1443
1443
  for col in decimal_columns_to_fix:
1444
1444
  fitting_eval_X[col] = (
1445
- fitting_eval_X[col]
1446
- .astype("string").str
1447
- .replace(",", ".", regex=False)
1448
- .astype(np.float64)
1445
+ fitting_eval_X[col].astype("string").str.replace(",", ".", regex=False).astype(np.float64)
1449
1446
  )
1450
1447
  fitting_enriched_eval_X[col] = (
1451
1448
  fitting_enriched_eval_X[col]
1452
- .astype("string").str
1453
- .replace(",", ".", regex=False)
1449
+ .astype("string")
1450
+ .str.replace(",", ".", regex=False)
1454
1451
  .astype(np.float64)
1455
1452
  )
1456
1453
 
@@ -3293,7 +3290,7 @@ class FeaturesEnricher(TransformerMixin):
3293
3290
  description[f"Feature {feature_idx}"] = bc.hashed_name
3294
3291
  feature_idx += 1
3295
3292
 
3296
- description["Function"] = autofe_feature.op.name
3293
+ description["Function"] = ",".join(sorted(autofe_feature.get_all_operand_names()))
3297
3294
 
3298
3295
  descriptions.append(description)
3299
3296
 
upgini/metrics.py CHANGED
@@ -298,7 +298,6 @@ class EstimatorWrapper:
298
298
  scorer = check_scoring(self.estimator, scoring=self.scorer)
299
299
 
300
300
  if baseline_score_column is not None and self.metric_name == "GINI":
301
- self.logger.info("Calculate baseline GINI on passed baseline_score_column and target")
302
301
  metric = roc_auc_score(y, x[baseline_score_column])
303
302
  else:
304
303
  cv_results = cross_validate(
@@ -17,7 +17,7 @@ from sklearn.base import clone, is_classifier
17
17
  from sklearn.exceptions import FitFailedWarning, NotFittedError
18
18
  from sklearn.metrics import check_scoring
19
19
  from sklearn.metrics._scorer import _MultimetricScorer
20
- from sklearn.model_selection import StratifiedKFold, check_cv
20
+ from sklearn.model_selection import check_cv
21
21
  from sklearn.utils.fixes import np_version, parse_version
22
22
  from sklearn.utils.validation import indexable
23
23
 
@@ -312,34 +312,25 @@ def cross_validate(
312
312
  ret[key] = train_scores_dict[name]
313
313
 
314
314
  return ret
315
- except ValueError as e:
315
+ except Exception:
316
316
  # logging.exception("Failed to execute overriden cross_validate. Fallback to original")
317
- if hasattr(e, "args") and len(e.args) > 0 and "Only one class present in y_true" in e.args[0]:
318
- # Try change CV to StratifiedKFold and retry
319
- if hasattr(cv, "shuffle"):
320
- shuffle = cv.shuffle
321
- else:
322
- shuffle = False
323
- if hasattr(cv, "random_state"):
324
- random_state = cv.random_state
325
- else:
326
- random_state = None
327
- return cross_validate(
328
- estimator,
329
- x,
330
- y,
331
- groups=groups,
332
- scoring=scoring,
333
- cv=StratifiedKFold(n_splits=cv.get_n_splits(), shuffle=shuffle, random_state=random_state),
334
- n_jobs=n_jobs,
335
- verbose=verbose,
336
- fit_params=fit_params,
337
- pre_dispatch=pre_dispatch,
338
- return_train_score=return_train_score,
339
- return_estimator=return_estimator,
340
- error_score=error_score,
341
- )
342
- raise e
317
+ raise
318
+ # fit_params["use_best_model"] = False
319
+ # return original_cross_validate(
320
+ # estimator,
321
+ # X,
322
+ # y,
323
+ # groups=groups,
324
+ # scoring=scoring,
325
+ # cv=cv,
326
+ # n_jobs=n_jobs,
327
+ # verbose=verbose,
328
+ # fit_params=fit_params,
329
+ # pre_dispatch=pre_dispatch,
330
+ # return_train_score=return_train_score,
331
+ # return_estimator=return_estimator,
332
+ # error_score=error_score,
333
+ # )
343
334
 
344
335
 
345
336
  def _fit_and_score(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: upgini
3
- Version: 1.1.282
3
+ Version: 1.1.282a3418.post2
4
4
  Summary: Intelligent data search & enrichment for Machine Learning
5
5
  Project-URL: Bug Reports, https://github.com/upgini/upgini/issues
6
6
  Project-URL: Homepage, https://upgini.com/
@@ -839,4 +839,4 @@ Some convenient ways to start contributing are:
839
839
  - [More perks for registered users](https://profile.upgini.com)
840
840
 
841
841
  <sup>😔 Found mistype or a bug in code snippet? Our bad! <a href="https://github.com/upgini/upgini/issues/new?assignees=&title=readme%2Fbug">
842
- Please report it here</a></sup>
842
+ Please report it here.</a></sup>
@@ -1,24 +1,24 @@
1
- upgini/__about__.py,sha256=30UsKi2T1u8S760-6ZTTqIlaw1c8DxzyxYb96KBjFr0,24
1
+ upgini/__about__.py,sha256=Enn127dFkXgCRELxuH2LQtSbMgcCcZZbvp1uqqge82o,31
2
2
  upgini/__init__.py,sha256=asENHgEVHQBIkV-e_0IhE_ZWqkCG6398U3ZLrNzAH6k,407
3
3
  upgini/ads.py,sha256=nvuRxRx5MHDMgPr9SiU-fsqRdFaBv8p4_v1oqiysKpc,2714
4
4
  upgini/dataset.py,sha256=7TLVVhGtjgx_9yaiaIUK3kZSe_R9wg5dY0d4F5qCGM4,45636
5
5
  upgini/errors.py,sha256=2b_Wbo0OYhLUbrZqdLIx5jBnAsiD1Mcenh-VjR4HCTw,950
6
- upgini/features_enricher.py,sha256=J1x1YMoJBWMFWhdvP-_h7X67qEoTcLqkRRMrz8I1XKQ,176885
6
+ upgini/features_enricher.py,sha256=2BFtU8TxIyP1cdyoct8q3ULSaStw534kwi-3syYMQ-Y,176844
7
7
  upgini/http.py,sha256=khrYSldpY-HbVLCcApfV1BjBFK6Uyuatb4colKybxgY,42301
8
8
  upgini/metadata.py,sha256=CFJekYGD7Ep7pRFH7wCEcsXS4bz83do33FNmtcCY9P4,9729
9
- upgini/metrics.py,sha256=kCRJ5vCEN76EbVtA1OpKpk6jrxwbfyRFBFtB2fBuq1Y,30227
9
+ upgini/metrics.py,sha256=tTXAgjEuoo_vDe4n-R0AFK95IIx_7kugIJJJv2Hr_1o,30128
10
10
  upgini/search_task.py,sha256=LtRJ9bCPjMo1gJ-sUDKERhDwGcWKImrzwVFHjkMSQHQ,17071
11
11
  upgini/spinner.py,sha256=4iMd-eIe_BnkqFEMIliULTbj6rNI2HkN_VJ4qYe0cUc,1118
12
12
  upgini/version_validator.py,sha256=RGg87VweujTNlibgsOuqPLIEiBgIOkuXNVTGuNCD234,1405
13
13
  upgini/ads_management/__init__.py,sha256=qzyisOToVRP-tquAJD1PblZhNtMrOB8FiyF9JvfkvgE,50
14
14
  upgini/ads_management/ads_manager.py,sha256=igVbN2jz80Umb2BUJixmJVj-zx8unoKpecVo-R-nGdw,2648
15
15
  upgini/autofe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- upgini/autofe/all_operands.py,sha256=SyKVU-xGMHgoRZvHrCmba2u2Ygc73c1mXFolNSWe8Uo,2357
16
+ upgini/autofe/all_operands.py,sha256=7UyvmmqGSqQu4kDgoFwQRKY__b9xKDk3Fpp2-H8A7AA,2399
17
17
  upgini/autofe/binary.py,sha256=441BRuqMsxlxuw4c8rMZB6h5EpRdVMk-bVa03U7T5Hg,3973
18
- upgini/autofe/date.py,sha256=Vy1I92fLLYLhuYKJmtuPBMI8cPxE4Uwk40hqE2F2e1A,4224
19
- upgini/autofe/feature.py,sha256=ChSuuIbRPGIWnPjKAgZbeAEi7Y_PjSVRyxxx41MyFp0,11845
18
+ upgini/autofe/date.py,sha256=XeTJIkPzauYXgI3n5E8h4353PhZRZ7LOpQGHA4DMPx4,6758
19
+ upgini/autofe/feature.py,sha256=_V9B74B3ue7eAYXSOt9JKhVC9klkAKks22MwnBRye_w,12487
20
20
  upgini/autofe/groupby.py,sha256=4WjDzQxqpZxB79Ih4ihMMI5GDxaFqiH6ZelfV82ClT4,3091
21
- upgini/autofe/operand.py,sha256=xgEIZuFCfckc6LpBqVu1OVK3JEabm1O-LHUsp83EHKA,2806
21
+ upgini/autofe/operand.py,sha256=JjEVT1U3kY9NDjUPMdoki7Oa8hMDG0-_h_NklVjIFyc,2882
22
22
  upgini/autofe/unary.py,sha256=v-l3aiE5hj6kurvh6adCQL8W3X9u9a7RVbS_WPR2qlw,3146
23
23
  upgini/autofe/vector.py,sha256=dLxfAstJs-gw_OQ1xxoxcM6pVzORlV0HVzdzt7cLXVQ,606
24
24
  upgini/data_source/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -52,11 +52,11 @@ upgini/utils/ip_utils.py,sha256=Zf3F2cnQmOCH09QLQHetpjMFu1PnD0cTmDymn0SnSy8,1672
52
52
  upgini/utils/phone_utils.py,sha256=JNSkF8G6mgsN8Czy11pamaJdsY6rBINEMpi7jbVt_RA,408
53
53
  upgini/utils/postal_code_utils.py,sha256=_8CR9tBqsPptQsmMUvnrCAmBaMIQSWH3JfJ4ly3x_zs,409
54
54
  upgini/utils/progress_bar.py,sha256=N-Sfdah2Hg8lXP_fV9EfUTXz_PyRt4lo9fAHoUDOoLc,1550
55
- upgini/utils/sklearn_ext.py,sha256=N-eJrfAJxYpDPc85sKQyMFcIeL9Ug2lwlqDyS4jFOdE,44499
55
+ upgini/utils/sklearn_ext.py,sha256=c23MGSUVfxLnaDWKAxavHgnOtm5dGKkF3YswdWQcFzs,43984
56
56
  upgini/utils/target_utils.py,sha256=Y96_PJ5cC-WsEbeqg20v9uqywDQobLoTb-xoP7S3o4E,7807
57
57
  upgini/utils/track_info.py,sha256=G5Lu1xxakg2_TQjKZk4b5SvrHsATTXNVV3NbvWtT8k8,5663
58
58
  upgini/utils/warning_counter.py,sha256=dIWBB4dI5XRRJZudvIlqlIYKEiwLLPcXarsZuYRt338,227
59
- upgini-1.1.282.dist-info/METADATA,sha256=8zARH7w4JgCbcnxAP3J61kr0Eiv6BSW5T0KBKQeHHq0,48117
60
- upgini-1.1.282.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
61
- upgini-1.1.282.dist-info/licenses/LICENSE,sha256=5RRzgvdJUu3BUDfv4bzVU6FqKgwHlIay63pPCSmSgzw,1514
62
- upgini-1.1.282.dist-info/RECORD,,
59
+ upgini-1.1.282a3418.post2.dist-info/METADATA,sha256=CDb5qhFVanj858fFyP7b96wf8UflZGzr38IeHoMiXD8,48129
60
+ upgini-1.1.282a3418.post2.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
61
+ upgini-1.1.282a3418.post2.dist-info/licenses/LICENSE,sha256=5RRzgvdJUu3BUDfv4bzVU6FqKgwHlIay63pPCSmSgzw,1514
62
+ upgini-1.1.282a3418.post2.dist-info/RECORD,,