GithubHelp home page GithubHelp logo

databricks-industry-solutions / fraud-orchestration Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 6.0 156 KB

Preempt fraud with rule-based patterns and select ML algorithms for reliable fraud detection. Use anomaly detection and fraud prediction to respond to bad actors rapidly.

Home Page: https://www.databricks.com/solutions/accelerators/fraud-detection

License: Other

Python 100.00%
databricks-industry-solutions fsi

fraud-orchestration's People

Contributors

danielsparing avatar dbbnicole avatar rportilla-databricks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fraud-orchestration's Issues

Cannot serve the first and second models on Databricks V2 serving

First Part

First part of the SA contains a dff_model, this notebooks present a XGBWrapper, the best model that was registered.
While serving encountering an error:
BAD_REQUEST: Encountered an unexpected error while evaluating the model. Verify that the serialized input Dataframe is compatible with the model for inference. Error ''XGBModel' object has no attribute 'callbacks''

The code to serve model was the following:

import os
import requests
import numpy as np
import pandas as pd
import json

token = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().getOrElse(None)
os.environ["DATABRICKS_TOKEN"] = token

def create_tf_serving_json(data):
  return {'inputs': {name: data[name].tolist() for name in data.keys()} if isinstance(data, dict) else data.tolist()}

def score_model(dataset):
  url = 'https://e2-demo-field-eng.cloud.databricks.com/model-endpoint/fraud_xgb_model/137/invocations'
  headers = {'Authorization': f'Bearer {os.environ.get("DATABRICKS_TOKEN")}', 'Content-Type': 'application/json'}
  ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
  data_json = json.dumps(ds_dict, allow_nan=True)
  response = requests.request(method='POST', headers=headers, url=url, data=data_json)
  if response.status_code != 200:
    raise Exception(f'Request failed with status {response.status_code}, {response.text}')
  return response.json()

The input to serve was following:

{"dataframe_split":{"index": [0],
 "columns": ["ACCT_PROD_CD",
  "ACCT_AVL_CASH_BEFORE_AMT",
  "ACCT_AVL_MONEY_BEFORE_AMT",
  "ACCT_CL_AMT",
  "ACCT_CURR_BAL",
  "APPRD_AUTHZN_CNT",
  "APPRD_CASH_AUTHZN_CNT",
  "AUTHZN_AMT",
  "AUTHZN_OUTSTD_AMT",
  "AVG_DLY_AUTHZN_AMT",
  "AUTHZN_OUTSTD_CASH_AMT",
  "CDHLDR_PRES_CD",
  "HOTEL_STAY_CAR_RENTL_DUR",
  "LAST_ADR_CHNG_DUR",
  "HOME_PHN_NUM_CHNG_DUR",
  "PLSTC_ISU_DUR",
  "POS_COND_CD",
  "POS_ENTRY_MTHD_CD",
  "DISTANCE_FROM_HOME",
  "FRD_IND"],
 "data": [[6.815292252529644,
   100.0,
   4.897123473461607,
   10000.0,
   8.474660964404574,
   5.2516766208803585,
   2.131421679416424,
   30.0,
   4.169722613481124,
   25.0,
   40.0,
   0.0,
   1.099779462798646,
   301.0,
   5.632847254480254,
   9.010249880517254,
   9.538468313595006,
   1.4806417695062948,
   1000.0,
   2.404762786010208]]}}

I also tried with different input, but then another error was raised (which I believe is due to the bad input this time) :
BAD_REQUEST: Encountered an unexpected error while evaluating the model. Verify that the serialized input Dataframe is compatible with the model for inference. Error ‘only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices’
Input was the following one:
“inputs”: [[10.0, 11500.0, 20153.38, 23000.0, 2647.55, 2.0, 0.0, 10.33, 209.4, 51.0, 0.0, 0.0, 0.0, 779.0, 0.0, 18.0, 0.0, 90.0, 10.48], [12.0, 2500.0, 2639.33, 5000.0, 2200.72, 3.0, 0.0, 12.44, 172.39, 22.0, 0.0, 0.0, 0.0, 999.0, 577.0, 781.0, 0.0, 90.0, 0.0]]}

Second part

Second part of the SA dff_orchestrator contains model serving, but it seems some libraries cannot be installed on V2 serving option - would be great to add a fix into it.
The error says:

An error occured while loading the model. Model Registry features are not supported by the store with URI: 'file:///mlruns'. Stores with the following URI schemes are supported: ['databricks', 'http', 'https', 'postgresql', 'mysql', 'sqlite', 'mssql']..

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.