Creating your own transformer
As the complexity and type of dataset changes, you might find that you can't find an existing feature extraction transformer that fits your needs. We will see an example of this in Chapter 7, Follow Recommendations Using Graph Mining, where we create new features from graphs.
A transformer is akin to a converting function. It takes data of one form as input and returns data of another form as output. Transformers can be trained using some training dataset, and these trained parameters can be used to convert testing data.
The transformer API is quite simple. It takes data of a specific format as input and returns data of another format (either the same as the input or different) as output. Not much else is required of the programmer.
The transformer API
Transformers have two key functions:
fit():
This takes a training set of data as input and sets internal parameterstransform():
This performs the transformation itself. This can take either the training dataset, or...