scikit-extensions 0.2.4__tar.gz → 0.2.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scikit-extensions
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: A collection of Scikit-learn-compatible transformers for feature engineering, preprocessing, and pipeline utilities.
5
5
  Keywords: scikit-learn,transformers,preprocessing,pipeline
6
6
  Author: sh99
@@ -95,6 +95,15 @@ mlb = MultiLabelBinarizerTransformer(sparse_output=False)
95
95
  transformed = mlb.fit_transform(data)
96
96
  ```
97
97
 
98
+ Each column can contain label iterables or delimiter-separated strings. String
99
+ values are split on commas by default; pass `delimiter` to use another separator.
100
+
101
+ ```python
102
+ data = pd.DataFrame({'tags': ['python|ml', 'python', 'ml|deep-learning']})
103
+ mlb = MultiLabelBinarizerTransformer(delimiter='|')
104
+ transformed = mlb.fit_transform(data)
105
+ ```
106
+
98
107
  ## Development
99
108
 
100
109
  1. Clone the repository:
@@ -76,6 +76,15 @@ mlb = MultiLabelBinarizerTransformer(sparse_output=False)
76
76
  transformed = mlb.fit_transform(data)
77
77
  ```
78
78
 
79
+ Each column can contain label iterables or delimiter-separated strings. String
80
+ values are split on commas by default; pass `delimiter` to use another separator.
81
+
82
+ ```python
83
+ data = pd.DataFrame({'tags': ['python|ml', 'python', 'ml|deep-learning']})
84
+ mlb = MultiLabelBinarizerTransformer(delimiter='|')
85
+ transformed = mlb.fit_transform(data)
86
+ ```
87
+
79
88
  ## Development
80
89
 
81
90
  1. Clone the repository:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scikit-extensions"
3
- version = "0.2.4"
3
+ version = "0.2.5"
4
4
  description = "A collection of Scikit-learn-compatible transformers for feature engineering, preprocessing, and pipeline utilities."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scikit-extensions"
3
- version = "0.2.4"
3
+ version = "0.2.5"
4
4
  description = "A collection of Scikit-learn-compatible transformers for feature engineering, preprocessing, and pipeline utilities."
5
5
  authors = [{ name = "sh99", email = "shriramh99@gmail.com" }]
6
6
  readme = "README.md"
@@ -9,23 +9,27 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
9
9
  """
10
10
  A custom transformer that wraps sklearn's MultiLabelBinarizer to integrate seamlessly into scikit-learn pipelines.
11
11
 
12
- This transformer converts a collection of label sets (iterables of iterables) into a binary indicator matrix.
13
- It is particularly useful for multi-label classification tasks where each sample can belong to multiple classes.
12
+ This transformer converts columns containing label iterables or delimiter-separated
13
+ strings into a binary indicator matrix. String values are split using ``delimiter``.
14
+ It is particularly useful for multi-label classification tasks where each sample
15
+ can belong to multiple classes.
14
16
 
15
17
  Parameters
16
18
  ----------
17
19
  sparse_output : bool, default=False
18
20
  If True, the output will be a sparse matrix in Compressed Sparse Row (CSR) format. Otherwise, a dense NumPy array is returned.
21
+ delimiter : str, default=","
22
+ Delimiter used to split string values in input columns.
19
23
 
20
24
  Attributes
21
25
  ----------
22
- mlbs : dict
26
+ mlbs_ : dict
23
27
  A dictionary mapping column names to fitted MultiLabelBinarizer instances.
24
- feature_names_in_ : list
25
- List of input feature names (column names) during fitting.
28
+ feature_names_in_ : ndarray of shape (n_features_in_,)
29
+ Input feature names seen during fitting, when all column names are strings.
26
30
  """
27
31
 
28
- def __init__(self, sparse_output=False):
32
+ def __init__(self, sparse_output=False, delimiter=","):
29
33
  """
30
34
  Initializes the transformer with the specified parameters.
31
35
 
@@ -33,8 +37,18 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
33
37
  ----------
34
38
  sparse_output : bool, default=False
35
39
  If True, the output will be a sparse matrix in Compressed Sparse Row (CSR) format. Otherwise, a dense NumPy array is returned.
40
+ delimiter : str, default=","
41
+ Delimiter used to split string values in input columns.
36
42
  """
37
43
  self.sparse_output = sparse_output
44
+ self.delimiter = delimiter
45
+
46
+ def _prepare_column(self, values):
47
+ return values.map(
48
+ lambda value: [label.strip() for label in value.split(self.delimiter) if label.strip()]
49
+ if isinstance(value, str)
50
+ else value
51
+ )
38
52
 
39
53
  def fit(self, X, y=None):
40
54
  """
@@ -43,7 +57,8 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
43
57
  Parameters
44
58
  ----------
45
59
  X : pandas DataFrame of shape (n_samples, n_features)
46
- A collection of label sets, where each set contains the labels for a single sample.
60
+ Each column contains label iterables or delimiter-separated strings,
61
+ where each cell contains the labels for one sample.
47
62
 
48
63
  y : None
49
64
  Ignored. This parameter exists for compatibility with scikit-learn pipelines.
@@ -62,7 +77,9 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
62
77
  elif hasattr(self, "feature_names_in_"):
63
78
  del self.feature_names_in_
64
79
  self.mlbs_ = {
65
- col: MultiLabelBinarizer(sparse_output=self.sparse_output).fit(X[col])
80
+ col: MultiLabelBinarizer(sparse_output=self.sparse_output).fit(
81
+ self._prepare_column(X[col])
82
+ )
66
83
  for col in self.input_columns_
67
84
  }
68
85
  return self
@@ -74,7 +91,8 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
74
91
  Parameters
75
92
  ----------
76
93
  X : pandas DataFrame of shape (n_samples, n_features)
77
- A collection of label sets to transform.
94
+ Each column contains label iterables or delimiter-separated strings,
95
+ where each cell contains the labels for one sample.
78
96
 
79
97
  Returns
80
98
  -------
@@ -90,7 +108,7 @@ class MultiLabelBinarizerTransformer(BaseEstimator, TransformerMixin):
90
108
  transformed_parts = []
91
109
  for col in self.input_columns_:
92
110
  mlb = self.mlbs_[col]
93
- part = mlb.transform(X[col])
111
+ part = mlb.transform(self._prepare_column(X[col]))
94
112
  if not self.sparse_output:
95
113
  part = pd.DataFrame(
96
114
  part,