Giter Site home page Giter Site logo

mccepy's People

Contributors

andersloland avatar aredelmeier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mccepy's Issues

Loss of generality in postprocess-method for "higher_cardinality=True".

This problem was noticed while looking at examples/Examples_notebook_scratch.ipynb.

'postprocess' calls 'calculate_metrics', which later calls 'distance'. In the 'distance'-function, the data is inverse-transformed according to the 'inverse_transform'-function passed to the Dataset object, if the data is allowed higher cardinality than two levels per categorical feature. In the example, this object is constructed based on

class Dataset():
    def __init__(self, 
                 immutables, 
                 target,
                 categorical,
                 immutables_encoded,
                 continuous,
                 features,
                 encoder,
                 scaler,
                 inverse_transform,
                 ):
        
        self.immutables = immutables
        self.target = target
        self.feature_order = feature_order
        self.dtypes = dtypes
        self.categorical = categorical
        self.continuous = continuous
        self.features = self.categorical + self.continuous
        self.cols = self.features + [self.target]
        self.immutables_encoded = immutables_encoded
        self.encoder = encoder
        self.scaler = scaler
        self.inverse_transform = inverse_transform

where the inverse_transform function is defined as

def inverse_transform(df, 
                      scaler, 
                      encoder, 
                      continuous,
                      categorical,
                      categorical_encoded, 
                      ):

    df_categorical = pd.DataFrame(encoder.inverse_transform(df[categorical_encoded]), columns=categorical)
    df_continuous = pd.DataFrame(scaler.inverse_transform(df[continuous]), columns=continuous)

    return pd.concat([df_categorical, df_continuous], axis=1)

Now, the if-else statement in 'distance' fails if higher_card = True, i.e.

if higher_card:
        cf_inverse_transform = dataset.inverse_transform(cfs.copy())
        fact_inverse_transform = dataset.inverse_transform(fact.copy())

        cfs_categorical = cf_inverse_transform[categorical].sort_index().to_numpy()
        factual_categorical = fact_inverse_transform[categorical].sort_index().to_numpy()

    else:
        cfs_categorical = cfs[categorical_encoded].sort_index().to_numpy()
        factual_categorical = fact[categorical_encoded].sort_index().to_numpy()

because the inverse_transform-function misses four arguments. These can be passed quite easily however. Thus, I believe this problem can be fixed by changing the if-else statement above to

if higher_card:
        cf_inverse_transform = dataset.inverse_transform(cfs.copy(), dataset.scaler, dataset.encoder, continuous, categorical, categorical_encoded)
        fact_inverse_transform = dataset.inverse_transform(fact.copy(), dataset.scaler, dataset.encoder, continuous, categorical, categorical_encoded)

        cfs_categorical = cf_inverse_transform[categorical].sort_index().to_numpy()
        factual_categorical = fact_inverse_transform[categorical].sort_index().to_numpy()

    else:
        cfs_categorical = cfs[categorical_encoded].sort_index().to_numpy()
        factual_categorical = fact[categorical_encoded].sort_index().to_numpy()

I can send a PR later if this is interesting to repository owner.

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.