Comments (7)
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.
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.
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.
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.
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.
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.
Great to hear!
from what-if-tool.
Related Issues (20)
- Does what-if-tool support lightgbm or xgboost or scikit learning models? HOT 1
- Replacing model with predictions data HOT 1
- GOOGLE APPLICATION CREDENTIALS HOT 3
- Can this work just on data without any model input? HOT 1
- Can the dashboard be changed according to our need? HOT 1
- what if tool for ranking model? HOT 1
- how to install what if in managed notebook of vertex ai? HOT 3
- what-if tool unable to return predictions - InactiveRpcError
- Enabling Persistence with what-if tensorboard plugin
- Data loading issue at scale with tensorboard what-if plugin
- Error when trying to reproduce example notebook locally HOT 6
- Custom Sprite Thumbnail Dimensions HOT 1
- Unable to import Witwidget
- Cant use fairness solution for regression so In that case How to mitigate the bias for the regression model? HOT 1
- ERROR: An error occurred during the fetch of repository 'zlib': HOT 1
- Uncaught (in promise) Error: Tensorflow Op is not supported: _FusedConv2D HOT 5
- Failed to load view class 'WITView' from module 'wit-widget'
- Predict in Datapoint-Editor leads to non-deterministic behavior HOT 1
- What If tool returning error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from what-if-tool.