Giter Club home page Giter Club logo

Comments (4)

jameswex avatar jameswex commented on June 8, 2024

You can use sklearn models through a custom predict function as you are trying. It just seems like there is a mismatch between the feature names expected by the sklearn model and the feature names in your data.columns.

What format does an input "x" have to be in for bst.predict(x) to return the correct result? It's possible in your case, it is expecting a dictionary with feature names like f1, f2, ...? Instead of what you are providing, which hav names like "purchase type" "lein status", and so on.

Once you know what format the data should be in for bst.predict(x) to work on its own, you can print what x is provided as inside your custom predict function and see where the mismatch is. Then, either add some code to adjust the example before calling bst.predict, or possibly adjust the data before it is provided to the WitConfigBuilder constructor.

from what-if-tool.

Pem14604 avatar Pem14604 commented on June 8, 2024

Thanks james!!!

I dont' understand what is difference b/w model which is deployed on AI platform and which m using directly as both are having same data...this is related to my custom_predict_fn for sure as you have mentioned as well. The thing is data which is being passed is not in shape as expected and also i don't know how to check the shape of the data which is going in adjustment function through config_builder.I tried to print "x" but it is givig list of values but don't have any ideas about cols.

just for your reference, below is the code, please help to resolve this.
https://github.com/Pem14604/whatiftool/blob/master/Whatif_xgboost.ipynb

I have tried many things like, please have a look.
x_test[1:2].columns.tolist() and data.columns.tolist() have same cols.

I dont know, what extaclty this line "config_builder = (WitConfigBuilder(test_examples.tolist(), data.columns.tolist() + ["mortgage_status"])" is doing....................seems like adding cols to my np array in which input feature and target variable stacked together using "np.hstack((x_test[:num_wit_examples].values,y_test[:num_wit_examples].reshape(-1,1)))
test_examples
"

I am not getting from where it is taking "f0,f1,f2..........cols" during prediction actually i don't know how to check what is the shape of data which we are passing in custom_predict_fn.

just for your reference, below is the code, please help to resolve this.
https://github.com/Pem14604/whatiftool/blob/master/Whatif_xgboost.ipynb

image

from what-if-tool.

jameswex avatar jameswex commented on June 8, 2024

Thanks for the notebook with the repro of the issue.

The config builder line you asked about is passing the examples to the What-If Tool as a 2D list of examples, where each row is a single example, as a list of feature values. The second argument is the list of names of the columns, which are the names of the input features (from data.columns), along with the name of the column we are trying to predict. That list of strings is provided in order to give the tool some feature names to display for the data being provided as flat lists. Alternatively, data can be provided to the tool as a list of json dictionaries (with keys as feature names and values as feature values), in which case that second argument of columns names wouldn't be necessary.

From playing with your notebook, it seems that the model is expecting a pandas data frame for the call to predict, and not just a simple 2D list of feature values for each datapoint. So, I adjusted your custom predict function to convert the data into a data frame (with the correct column names) before passing it to the model. That got past the error. The second change I made was that .predict only returns the predicted class and not the raw class scores for both classes. So I changed it to use .predict_proba.

Here is the final, working function:

def adjust_prediction(x):
x_df = pd.DataFrame(x, columns=data.columns.tolist())
return bst.predict_proba(x_df)

Feel free to reopen this issue if you have more questions.

from what-if-tool.

Pem14604 avatar Pem14604 commented on June 8, 2024

Thanks James...it is working fine!!!

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.