GithubHelp home page GithubHelp logo

Inheritance is a pain about basic-ml-oop HOT 6 OPEN

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024
Inheritance is a pain

from basic-ml-oop.

Comments (6)

imbilltucker avatar imbilltucker commented on July 21, 2024

Have you tried using default arguments in the init? That seems the easiest

One option is to make the defaults class variables and then overwrite them in the init, or some other function.

Another option is to make a config class, and pass that in to configure something. Then there's a structure.

There's also multiple inheritance you can use... (Bwahahahaah!) This can get confusing because not many people do this a lot, but these can be interesting options, especially if you want to consume several different sets of defaults.

The dictionary update function can also be useful. Have the defaults set in a dictionary, have the user over-ride them with another passed in dictionary via params.update(defaults); params.update(passed_in_dict)

Can you write down some examples of three different config cases you imagine for a particular function? There's lots of ways to skin the cat here.

from basic-ml-oop.

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024

That makes a lot of sense, I think I'll avoid the multiple inheritance for a few more seasons :)

Greg just sent over a PR to help me out with some of these issues. I really like the idea of having a dictionary though, seems to make a lot of sense. I'll create the examples soon.

from basic-ml-oop.

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024

It would be awesome to be able to write something like (and not specify a seed but have it default to, let's say 555)

notice that seed=123 is missing from below (so it throws an error)

pre_process_data = PreProcessData(
    predictor_vars=np.array([[0., 1., 2.], [4., 5., 6.]]),
    response_var=np.array([1., 2.]),
    scale_type="normalize",
    train_split=0.8
)

from basic-ml-oop.

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024

Another case would be when using PCA. Since you almost always normalize variables, it would be great to have it be default only in that case...

Notice that scale_type='normalize' is missing, so it throws an error

from models.dimensionizers import PrincipalComponentAnalysis
from sklearn.datasets import load_iris
iris = load_iris()

data_x = iris['data']
data_y = iris['target']

pca = PrincipalComponentAnalysis(
    predictor_vars=data_x,
    response_var=data_y,
    train_split=0.7,
    seed=123,
    variance_explained_cutoff=0.95
)

from basic-ml-oop.

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024

The correct results for those are shown in the readme.

from basic-ml-oop.

stoltzmaniac avatar stoltzmaniac commented on July 21, 2024

This keeps going on and on, learning_rate should have a default within LinearRegression and so forth. One thing I just discussed with Greg was that the super()__init__ method issues... they are ordered only, not keyword arguments, so I have to keep a consistent order every single time I inherit within the next class. That isn't a great experience, especially to debug

from basic-ml-oop.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.