An Incremental Strategy for Partitioning
Learn about the incremental strategy for partitioning along with the abstract and concrete methods in Python.
We'll cover the following
Overview
We have an alternative to splitting a single list after it’s been built. Instead of extending the list class to provide two sub-lists, we can reframe the problem slightly. Let’s define a subclass of SamplePartition
that makes a random choice between testing and training on each SampleDict
object that is presented via initialization, or the append()
or extend()
methods.
Abstract methods
Here’s an abstraction that summarizes our thinking on this. We’ll have three methods for building a list, and two properties that will provide the training and testing sets, as below.
We don’t inherit from list
because we’re not providing any other list-like features, not even __len__()
. The class has only five methods, as shown:
Get hands-on with 1400+ tech skills courses.