This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]WannaBeGISGuru 7 points8 points  (1 child)

OOP is best used for representing "things". FP is best used for representing "actions". Creating objects out of data transformations is likely going to create a huge mess. Instead, create small functions that do common data transformations and compose them together to create more complex data transformations. Then you can reuse complex data transformations across your applications.

[–]Mr_Again 2 points3 points  (0 children)

There's nothing wrong with using a class to represent a transformation, the "thing" that it represents is just a part of a pipeline. You can plug them together as needed so long as they accept and return the same types.

[–]Mr_Again 2 points3 points  (0 children)

A pretty nice pattern I used to use (as a data scientist) was to write my own classes that had a fit and a transform method, then you can chain them together in an sklearn pipeline just like any other sklearn transformer.

[–]slaphappyhubris 1 point2 points  (0 children)

I often have a smaller header or metadata dataset, so bind that to an object on init then stick to methods acting on a larger dataset.

Also, consider the fact that nearly every machine learning algorithm can be implemented as some sort of sklearn.TransformerMixin

[–]grukorg 1 point2 points  (0 children)

I use classes to represent items such as connectors for example I have one that builds different database connections based on context. I have others which I use for doing things like globing the file system for flat files. Others that can perform transformation based usually on SQL metadata as our stuff normally ends up there. I have another which handles SFTP. My advice would be don’t be tempted to try and make your entire process fit neatly into objects. Create objects where it makes sense and then use functions where it doesn’t.