how to get prediction probability when call restapi with “resp =, input_data, headers=headers)” RRS feed

  • Question

  • Dears,

    As I know, the result of, input_data, headers=headers) only include prediction result, but no probability,so how can i calculate AUC value?

    Monday, September 16, 2019 2:01 AM

All replies

  • Hi,

    You can use predict_proba() and roc_auc_score () functions respectively to calculate the predicted probabilities and AUC scores as shown below.

    # import necessary functions from modules
    from sklearn.model_selection import cross_val_score
    from sklearn.metrics import roc_auc_score
    # X_test represents test sample
    # y_test represents true labels for X_test
    # calculate predicted probabilities
    y_pred_prob = trainedmodel.predict_proba(X_test)[:,1]
    # calculate and print AUC score
    print("AUC score: {}".format(roc_auc_score(y_test, y_pred_prob)))
    # calculate and print cross-validated AUC scores
    print("AUC scores computed using 5-fold cross-validation: {}".format(cross_val_score(trainedmodel, X, y, cv=5, scoring='roc_auc')))

    Feel free to review the following references: DataCamp auc computation, Scikit Learn roc_auc_score, Scikit learn metrics.auc, Scikit learn Logistic regression classifier for more information. Please let me know if know if you have further questions. Thanks.


    Azure CXP Community.

    If a post helps to resolve your issue, please click "Mark as Answer" and/or "Vote as helpful". By marking a post as Answered and/or Helpful, you help others find the answer faster.  Thanks.

    Wednesday, September 18, 2019 3:20 PM