Pipeline
framework3.base.base_pipelines
¶
__all__ = ['BasePipeline', 'SequentialPipeline', 'ParallelPipeline']
module-attribute
¶
BasePipeline
¶
Bases: BaseFilter
Base class for pipeline structures in the framework.
This abstract class extends BaseFilter and defines the interface for pipeline operations. It provides a structure for implementing complex data flows and combinations of filters.
Key Features
- Abstract methods for starting pipeline processing and evaluation
- Support for verbose output control
- Methods for initializing filters, getting filter types, and applying optimizers and splitters
- Access to inner filters of the pipeline
Usage
To create a new pipeline type, inherit from this class and implement the required methods. For example:
class MyCustomPipeline(BasePipeline):
def __init__(self, filters: List[BaseFilter]):
super().__init__(filters=filters)
def start(self, x: XYData, y: Optional[XYData], X_: Optional[XYData]) -> Optional[XYData]:
# Implement pipeline start logic
pass
def evaluate(self, x_data: XYData, y_true: XYData | None, y_pred: XYData) -> Dict[str, Any]:
# Implement evaluation logic
pass
Attributes:
Name | Type | Description |
---|---|---|
filters |
List[BaseFilter]
|
List of filters in the pipeline. |
Methods:
Name | Description |
---|---|
start |
XYData, y: Optional[XYData], X_: Optional[XYData]) -> Optional[XYData]: Abstract method to start the pipeline processing. |
evaluate |
XYData, y_true: XYData | None, y_pred: XYData) -> Dict[str, Any]: Abstract method to evaluate the pipeline's performance. |
verbose |
bool) -> None: Sets the verbosity level for the pipeline and its filters. |
init |
Initializes the pipeline and its filters. |
get_types |
Returns the types of filters in the pipeline. |
optimizer |
BaseOptimizer) -> BaseOptimizer: Applies an optimizer to the pipeline. |
splitter |
BaseSplitter) -> BaseSplitter: Applies a splitter to the pipeline. |
inner |
Returns the inner filters of the pipeline. |
Note
This is an abstract base class. Concrete implementations should override the start and evaluate methods to provide specific pipeline functionality.
Source code in framework3/base/base_pipelines.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
evaluate(x_data, y_true, y_pred)
abstractmethod
¶
Evaluate the pipeline's performance.
This abstract method should be implemented by subclasses to define the specific logic for evaluating the pipeline's output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
XYData
|
The input data used for prediction. |
required |
y_true
|
XYData | None
|
The ground truth or actual values. |
required |
y_pred
|
XYData
|
The predicted values. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing evaluation metrics. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not implement this method. |
Source code in framework3/base/base_pipelines.py
get_types()
¶
Get the types of filters in the pipeline.
This method returns a list of the types of all filters contained in the pipeline.
Returns:
Type | Description |
---|---|
List[Type[BaseFilter]]
|
List[Type[BaseFilter]]: A list of filter types in the pipeline. |
Source code in framework3/base/base_pipelines.py
init(*args, **kwargs)
¶
Initialize the pipeline and its filters.
This method initializes both the pipeline itself and all its constituent filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
List[Any]
|
Variable length argument list. |
()
|
**kwargs
|
Dict[str, Any]
|
Arbitrary keyword arguments. |
{}
|
Source code in framework3/base/base_pipelines.py
inner()
¶
Get the inner filters of the pipeline.
This method returns the list of filters contained within the pipeline.
Returns:
Type | Description |
---|---|
BaseFilter | List[BaseFilter] | None
|
BaseFilter | List[BaseFilter] | None: The inner filters of the pipeline. |
Source code in framework3/base/base_pipelines.py
optimizer(optimizer)
¶
Apply an optimizer to the pipeline.
This method allows an optimizer to be applied to the entire pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer
|
BaseOptimizer
|
The optimizer to apply to the pipeline. |
required |
Returns:
Name | Type | Description |
---|---|---|
BaseOptimizer |
BaseOptimizer
|
The optimizer after optimization. |
Source code in framework3/base/base_pipelines.py
splitter(splitter)
¶
Apply a splitter to the pipeline.
This method allows a splitter to be applied to the entire pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splitter
|
BaseSplitter
|
The splitter to apply to the pipeline. |
required |
Returns:
Name | Type | Description |
---|---|---|
BaseSplitter |
BaseSplitter
|
The splitter after splitting. |
Source code in framework3/base/base_pipelines.py
start(x, y, X_)
abstractmethod
¶
Start the pipeline processing.
This abstract method should be implemented by subclasses to define the specific logic for initiating the pipeline's data processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
XYData
|
The primary input data. |
required |
y
|
Optional[XYData]
|
Optional target data. |
required |
X_
|
Optional[XYData]
|
Optional additional input data. |
required |
Returns:
Type | Description |
---|---|
Optional[XYData]
|
Optional[XYData]: The processed data, if any. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not implement this method. |
Source code in framework3/base/base_pipelines.py
verbose(value)
¶
Set the verbosity of the pipeline and its filters.
This method controls the verbosity of both the pipeline itself and all its constituent filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
bool
|
If True, enables verbose output; if False, disables it. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in framework3/base/base_pipelines.py
ParallelPipeline
¶
Bases: BasePipeline
A pipeline that processes filters in parallel.
This class implements a pipeline where filters can be applied concurrently, potentially improving performance for certain types of operations.
Note
The implementation details for this class are not provided in the given code snippet. It is expected that concrete implementations will define the specific behavior for parallel processing of filters.
Source code in framework3/base/base_pipelines.py
SequentialPipeline
¶
Bases: BasePipeline
A pipeline that processes filters sequentially.
This class implements a pipeline where each filter is applied in sequence, with the output of one filter becoming the input of the next.
Key Features
- Sequential processing of filters
- Implements start method for initiating the pipeline
- Supports both fit and predict operations
Usage
from framework3.base import SequentialPipeline, XYData
from framework3.plugins.filters import StandardScaler, PCA, LogisticRegression
pipeline = SequentialPipeline([
StandardScaler(),
PCA(n_components=5),
LogisticRegression()
])
X_train = XYData.mock(np.random.rand(100, 10))
y_train = XYData.mock(np.random.randint(0, 2, 100))
pipeline.fit(X_train, y_train)
predictions = pipeline.predict(X_train)
Methods:
Name | Description |
---|---|
start |
XYData, y: Optional[XYData], X_: Optional[XYData]) -> Optional[XYData]: Starts the sequential processing of filters in the pipeline. |
_pre_fit |
XYData, y: Optional[XYData]) -> Tuple[str, str, str]: Prepares the pipeline for fitting by initializing model attributes and pre-fitting filters. |
_pre_predict |
XYData) -> XYData: Prepares the pipeline for prediction by applying pre-predict operations on all filters. |
Note
This class extends BasePipeline and provides a concrete implementation for sequential processing of filters.
Source code in framework3/base/base_pipelines.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|