Giter Club home page Giter Club logo

Comments (7)

jameswex avatar jameswex commented on September 25, 2024 1

Nice to see that the function works with your manual testing. Are you able to log the input to the custom predict fn when call from the UI to see how it differs from your manual testing?

from what-if-tool.

jameswex avatar jameswex commented on September 25, 2024 1

it may be the case that if you pass a single example through the ui (by pressing predict button after making an edit), then your custom predict fn is returning a raw values instead of a list of length 1 of the value to return?

from what-if-tool.

jameswex avatar jameswex commented on September 25, 2024

The issue is most likely in your custom prediction fn. Perhaps you can write your predict function with logging to see exactly what is passed in, if its in the format your model expects, or if you need to preprocess the data sent to the function before you pass it to your model.

from what-if-tool.

zabir-nabil avatar zabir-nabil commented on September 25, 2024

Thanks @jameswex for the input, really appreciate it. Now, I have written another custom_function which takes a train.Example and performs the predict, however I'm getting a new error TypeError("object of type 'float' has no len()")

My custom predict function:

def custom_predict_fn(examples):
  if type(examples) == list:
    feats_all = []
    for example in examples:
      feats = []
      for col in features:
        #print(col)
        p = example.features.feature[col].float_list.value
        #print(p)
        feats.append(p[0])
      feats_all.append(feats)
  else:
    feats = []
    for col in features:
      #print(col)
      p = examples.features.feature[col].float_list.value
      #print(p)
      feats.append(p[0])
    feats_all = [feats]
  return model.predict(np.array(feats_all)).tolist()

I have tested the function with a slice of train.Example

test_examples = df_to_examples(test_features[0:10])
custom_predict_fn(test_examples[2:5])
Out: [2.229121702878904e-05, 6.0774786297023536e-05, 1.2393046192705309e-05]

custom_predict_fn(test_examples[2])
[2.229121702878904e-05]

It works correctly. However on UI, I get the error: TypeError("object of type 'float' has no len()")

This is how my train.Example sample looks like

features {
  feature {
    key: "a1"
    value {
      float_list {
        value: 1.0
      }
    }
  }
  feature {
    key: "a2"
    value {
      float_list {
        value: 1.0
      }
    }
  }
  feature {
    key: "a3"
    value {
      float_list {
        value: 1.0
      }
    }
  }
  feature {
    key: "cj_val"
    value {
      float_list {
        value: -0.9179026484489441
      }
    }
  }
  feature {
    key: "cos"
    value {
      float_list {
        value: -0.561825692653656
      }
    }
  }
  feature {
    key: "hr"
    value {
      float_list {
        value: 35.0
      }
    }
  }
  feature {
    key: "iscore"
    value {
      float_list {
        value: 8.0
      }
    }
  }
  feature {
    key: "label"
    value {
      float_list {
        value: 0.0
      }
    }
  }
  feature {
    key: "max_pct_2"
    value {
      float_list {
        value: 48.029998779296875
      }
    }
  }
  feature {
    key: "max_pct"
    value {
      float_list {
        value: 0.4039580523967743
      }
    }
  }

from what-if-tool.

zabir-nabil avatar zabir-nabil commented on September 25, 2024

Okay, interesting. I have tested it with single example, it still returns a list, something like [0.4]. I even added a check just before the return value, it seems no error is taking place there; the error is taking place after the value is returned most probably. Is there any specific format that the UI expects internally? I seems it's trying to get a length of a float value, maybe a feature?

from what-if-tool.

zabir-nabil avatar zabir-nabil commented on September 25, 2024

Okay, it's working now. From the comments, I found out the prediction should have shape like (batch, num_classes) for classification, but my model was predicting a single score for a binary classification problem. Now, it's working as expected. Thanks @jameswex

from what-if-tool.

jameswex avatar jameswex commented on September 25, 2024

Great to hear!

from what-if-tool.

Related Issues (20)

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.