opengood.py-ml-plot 2.2.0__tar.gz → 2.3.0__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: opengood.py_ml_plot
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Modules containing reusable functions for machine learning visualization plotting
5
5
  Author-email: OpenGood <ai@opengood.ai>
6
6
  License: MIT License
@@ -119,6 +119,10 @@ setup_classification_plot(
119
119
  title="Logistic Regression",
120
120
  x_label="Age",
121
121
  y_label="Estimated Salary",
122
+ meshgrid={
123
+ 0: {"min": 10, "max": 10, "step": 0.25},
124
+ 1: {"min": 1000, "max": 1000, "step": 0.25},
125
+ },
122
126
  feature_scale=lambda x_set, y_set: (
123
127
  sc.inverse_transform(x_set), y_set
124
128
  ),
@@ -188,7 +192,8 @@ as follows:
188
192
  * If the `feature_scale` lambda is not defined, `x_set` and `y_set` are
189
193
  assigned the values of `x` and `y`, respectively
190
194
  * `meshgrid` function from the NumPy library returns a tuple of coordinate
191
- matrices from coordinate vectors
195
+ matrices from coordinate vectors (the ranges for each axis are controlled by
196
+ the `meshgrid` dict parameter passed to `setup_classification_plot`).
192
197
  * Two sets of matrices (`x1` and `x2`) are returned with coordinate vectors
193
198
  * `x1`
194
199
  * `arange` function is called with a defined start and stop interval
@@ -78,6 +78,10 @@ setup_classification_plot(
78
78
  title="Logistic Regression",
79
79
  x_label="Age",
80
80
  y_label="Estimated Salary",
81
+ meshgrid={
82
+ 0: {"min": 10, "max": 10, "step": 0.25},
83
+ 1: {"min": 1000, "max": 1000, "step": 0.25},
84
+ },
81
85
  feature_scale=lambda x_set, y_set: (
82
86
  sc.inverse_transform(x_set), y_set
83
87
  ),
@@ -147,7 +151,8 @@ as follows:
147
151
  * If the `feature_scale` lambda is not defined, `x_set` and `y_set` are
148
152
  assigned the values of `x` and `y`, respectively
149
153
  * `meshgrid` function from the NumPy library returns a tuple of coordinate
150
- matrices from coordinate vectors
154
+ matrices from coordinate vectors (the ranges for each axis are controlled by
155
+ the `meshgrid` dict parameter passed to `setup_classification_plot`).
151
156
  * Two sets of matrices (`x1` and `x2`) are returned with coordinate vectors
152
157
  * `x1`
153
158
  * `arange` function is called with a defined start and stop interval
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "opengood.py_ml_plot"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "Modules containing reusable functions for machine learning visualization plotting"
9
9
  authors = [
10
10
  { name = "OpenGood", email = "ai@opengood.ai" }
@@ -10,8 +10,9 @@ def setup_classification_plot(
10
10
  title,
11
11
  x_label,
12
12
  y_label,
13
- feature_scale: lambda x1, y1: (),
14
- predict: lambda x1, x2: (),
13
+ meshgrid=None,
14
+ feature_scale=None,
15
+ predict=None,
15
16
  ):
16
17
  """
17
18
  Sets up a classification plot with decision boundaries and classified regions.
@@ -27,6 +28,13 @@ def setup_classification_plot(
27
28
  title (str): Title for the plot.
28
29
  x_label (str): Label for the x-axis.
29
30
  y_label (str): Label for the y-axis.
31
+ meshgrid (dict[int, dict[str, float]]): Controls the np.meshgrid arange parameters for each axis.
32
+ Provide a dict with two entries indexed by 0 and 1 (x-axis and y-axis respectively),
33
+ where each entry is a dict with keys:
34
+ - "min": float padding to subtract from the min value for the start of the range
35
+ - "max": float padding to add to the max value for the end of the range
36
+ - "step": float step size between values in the range
37
+ Example: {0: {"min": 10, "max": 10, "step": 0.25}, 1: {"min": 1000, "max": 1000, "step": 0.25}}
30
38
  feature_scale (callable): Function to transform the feature data for visualization.
31
39
  Should take x and y as input and return the transformed x and y.
32
40
  If None, no transformation is applied.
@@ -44,18 +52,30 @@ def setup_classification_plot(
44
52
  ... title="Logistic Regression",
45
53
  ... x_label="Feature 1",
46
54
  ... y_label="Feature 2",
55
+ ... meshgrid={0: {"min": 10, "max": 10, "step": 0.25}, 1: {"min": 1000, "max": 1000, "step": 0.25}},
47
56
  ... feature_scale=lambda x_set, y_set: (x_set, y_set),
48
57
  ... predict=lambda x1, x2: classifier.predict(np.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape)
49
58
  ... )
50
59
  """
60
+ if meshgrid is None:
61
+ meshgrid = {
62
+ 0: {"min": 10, "max": 10, "step": 0.25},
63
+ 1: {"min": 1000, "max": 1000, "step": 0.25},
64
+ }
51
65
  if feature_scale is not None:
52
66
  x_set, y_set = feature_scale(x, y)
53
67
  else:
54
68
  x_set, y_set = x, y
55
69
  x1, x2 = np.meshgrid(
56
- np.arange(start=x_set[:, 0].min() - 10, stop=x_set[:, 0].max() + 10, step=0.25),
57
70
  np.arange(
58
- start=x_set[:, 1].min() - 1000, stop=x_set[:, 1].max() + 1000, step=0.25
71
+ start=x_set[:, 0].min() - meshgrid[0]["min"],
72
+ stop=x_set[:, 0].max() + meshgrid[0]["max"],
73
+ step=meshgrid[0]["step"],
74
+ ),
75
+ np.arange(
76
+ start=x_set[:, 1].min() - meshgrid[1]["min"],
77
+ stop=x_set[:, 1].max() + meshgrid[1]["max"],
78
+ step=meshgrid[1]["step"],
59
79
  ),
60
80
  )
61
81
  y_pred = predict(x1, x2)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengood.py_ml_plot
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Modules containing reusable functions for machine learning visualization plotting
5
5
  Author-email: OpenGood <ai@opengood.ai>
6
6
  License: MIT License
@@ -119,6 +119,10 @@ setup_classification_plot(
119
119
  title="Logistic Regression",
120
120
  x_label="Age",
121
121
  y_label="Estimated Salary",
122
+ meshgrid={
123
+ 0: {"min": 10, "max": 10, "step": 0.25},
124
+ 1: {"min": 1000, "max": 1000, "step": 0.25},
125
+ },
122
126
  feature_scale=lambda x_set, y_set: (
123
127
  sc.inverse_transform(x_set), y_set
124
128
  ),
@@ -188,7 +192,8 @@ as follows:
188
192
  * If the `feature_scale` lambda is not defined, `x_set` and `y_set` are
189
193
  assigned the values of `x` and `y`, respectively
190
194
  * `meshgrid` function from the NumPy library returns a tuple of coordinate
191
- matrices from coordinate vectors
195
+ matrices from coordinate vectors (the ranges for each axis are controlled by
196
+ the `meshgrid` dict parameter passed to `setup_classification_plot`).
192
197
  * Two sets of matrices (`x1` and `x2`) are returned with coordinate vectors
193
198
  * `x1`
194
199
  * `arange` function is called with a defined start and stop interval