Coder Social home page Coder Social logo

catboost-udf's Introduction

Snowflake Catboost UDF

Catboost is a high-performance open source library for gradient boosting on decision trees.

It supports exporting models as Python code with some important caveats:

  • Multiclassification models are not supported
  • The output returned is equivalent to 'RawFormulaVal' prediction_type

For CatBoostClassifier models, the RawFormulaVal will be negative for the 0 class and positive for the 1 class.

This repository contains example code for creating a CatBoostClassifier and using the exported Python to create a Snowpark User Defined Function.

Setup

For Python and it's dependencies, we use Anaconda to setup an environment.

conda env create -f environment.yml

Put your Snowflake connection settings into config.py, using the following template. The account property is a Snowflake Account Locator. It's passed

#!/usr/bin/env python3

snowflake_conn_prop = {
   "account": "ORG-account",
   "user": "USERNAME",
   "password": "PASSWORD"
   "role": "SYSADMIN",
   "database": "CATBOOST",
   "schema": "PUBLIC",
   "warehouse": "COMPUTE_WH",
}

Or via web browser authentication like so:

#!/usr/bin/env python3

snowflake_conn_prop = {
   "account": "ORG-account",
   "authenticator": "externalbrowser",
   "role": "SYSADMIN",
   "database": "CATBOOST",
   "schema": "PUBLIC",
   "warehouse": "COMPUTE_WH",
}

Run the following SQL in your Snowflake account to create a Database and a Stage for the user defined function.

USE ROLE SYSADMIN;
CREATE DATABASE CATBOOST COMMENT = 'Database for CatBoost UDF, Stage and Test Data';
CREATE STAGE "CATBOOST"."PUBLIC".CATBOOST COMMENT = 'Stage for UDF objects';

Usage

Create the model and UDF:

conda activate catboost_snowpark
python cb.py

Verify in Snowflake:

SELECT LABEL, NATIVE_MODEL, PYTHON_EXPORT_MODEL, CB_APPLY("I0","I1","I2","I3","I4") AS UDF_MODEL FROM CATBOOST_TEST;

SELECT NATIVE_MODEL, PYTHON_EXPORT_MODEL>0 FROM CATBOOST_TEST;

Primary Maintainers

  • Duncan Turnbull (@sfc-gh-dturnbull)

This is a community-developed package, not an official Snowflake offering. It comes with no support or warranty. However, feel free to raise a github issue if you find a bug or would like a new feature

License

Copyright 2022 Snowflake Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

If you are interested in contributing to this project, get started here

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.