Sei sulla pagina 1di 26

BRK3298

Building machine learning applications


using R and Python in SQL Server 2017
Umachandar Jayachandran (UC)
Sumit Kumar
Program Managers
Agenda
Machine Learning Intro
SQL Server Machine Learning Services
Customer scenarios
What’s coming?
Bringing intelligence to where data lives

Application
Application +
Intelligence VS

Database Intelligence
+ Database

Regular Database + App Intelligence Database + App


Why Machine Learning in SQL Server?
R Python
Eliminate data movement integration integration
Leverage database security
Push ML compute to the database

Operationalize ML scripts and models Data Scientist


Interacts directly
Calling familiar T-SQL stored procedures with data
Model management in SQL Server
Analytics library

010010 010010

Enterprise grade performance and scale


100100
010101
100100
010101
010010
100100
010101

SQL Developer/
Scale your R and Python analytics with multi- SQL Transformations
DBA
threading and parallel processing Manage data and Relational data
SQL Server security, compliance, resource analytics together

governance, query performance, always on


secondaries
Customer Story - PROS

Segmentation Pricing Optimization

Expert
Target
Floor

Group customers, products & Apply optimization algorithms to


transactions into micro- target the pricing envelope
segments of similar ‘sweet spot’ in every segment
willingness-to-pay
Before After
Attribute SQL Server
Selection Tool
C++/R SQL
Server

Attribute Selection
sp_execute_external_s
Data cript
tables ‘R code’

Segmentation Segmentation
Store Data
Tool sp_execute_external_s tables
d Proc cript
C++/R
‘R code’

Scoring
sp_execute_external_s
cript
‘R code’
Customer stories ATTOM will be able to take
advantage of a host of new
capabilities, including
• ATTOM Data Solutions machine learning and
predictive analytics.
• Real estate property insights
• Acxiom
With R Services, Acxiom is
• Migrating from SAS building better, more
accurate models using
larger data sets, which
• Targeted marketing campaigns results in more precisely
targeted marketing for
• Heartland Bank customers.

• Migrating from SAS The bank has moved its credit


scorecard development, arrears
• Build financial models analysis, investment
forecasting, and analysis of
intermediary and broker
performance to the R Server
platform.
Hello Iris!
Demo
SQL Server Machine Learning Services
• SQL Server 2016
• R support (3.2.2 version)
• Microsoft R Server (under Modern Lifecycle Policy)
• SQL Server 2017
• Native scoring using PREDICT function (+Linux
support)
• EXTERNAL LIBRARY DDL for R package management
• Batch mode execution support for input data
• R support (3.3.3 version)

Azure SQL Database Machine Learning
Services
• Native scoring using PREDICT function
• R support preview (3.3.3 version)
• Available in West Central US Region
• Premium & Premium RS Service Tiers
• Base R packages & RevoscaleR package
• Training & Scoring of Models that fit in memory
• Trivial Parallelism & Streaming support
• One concurrent execution of R script
Machine Learning Server
 Multi-platform support
 Windows, Linux, Hadoop, SQL Server
 Microsoft R Server
 RevoScaleR, MicrosoftML, olapR, sqlrutils packages
 Web services operationalization
 Microsoft Machine Learning Server
 R & Python support
 revoscalepy, microsoftml python libraries
 rxExecBy
 Hadoop Licensing changes

Data Scientists - Data Exploration and Model Development

train <- RxSqlServerData(query,


connectionString, computeContext)
2 Execution
rxLogit(formula, train)

1 Script
Data Scientist SQL Server
Workstation 3 Results Machine Learning
Services
Any R/Python IDE
R/Python Runtime
Application Developer - Model Operationalization

2 Execution
1 Stored Proc call
The stored procedure
3 Results
SQL Server contains R or Python code
and executes in-database
Application Machine Learning
exec sp_execute_external_script
Services
@language = ‘Python’
, @script =
R/Python Runtime
-- Python code --
Hospital Length of Stay
HeaIthcare ISV
building
intelligence into
their application
Allow hospitals to
optimize resource
allocation Dashboard that shows
Predictions against actuals
Operationalize Length of Stay Predictions
• Predict accurately how long a newly
Problem
admitted patient will stay in the hospital

• Build a model using anonymized patient data


Solution • Operationalize model using T-SQL stored
procedures
Train Model • Anonymized Patient information
using
• Key variables are number of previous
Anonymized
data admissions, diagnostic codes, lab results
Operationaliz
e Model in • Deploy model to production database
Azure SQL • Use model to predict length of stay
Database
Predict patient length of stay
Demo
Realtime Predictions using Native Scoring
• PREDICT function
• No dependency on R or Python runtime
• Enabled on SQL Server in Windows & Linux
• Usage
• Single or small number of rows scoring
• Highly concurrent scoring scenarios
• Predict during INSERT, UPDATE, MERGE statements
• Requirements
• Models built using RevoScaleR or revoscalepy
• rxLinMod, rxLogit, rxBTrees, rxDTree, rxDForest
• Serialized using rxSerializeModel (R) or rx_serialize_model
PREDICT syntax
PREDICT ( MODEL = @model | model_literal,
DATA = object AS <table_alias> )
WITH ({ {column_definition } [,...n ] } )

INSERT INTO loan_applications


(c1, c2, c3, c4, risk_score)
SELECT d.c1, d.c2, d.c3, d.c4, p.score
FROM PREDICT(MODEL = @model, DATA = @input as d)
WITH(score float) as p;
Fraud Detection using PREDICT
• Detect potentially fraudulent transactions
Problem
with low latency

• Build a model to learn patterns of


Solution
fraudulent transactions
• Historical labelled credit transactions, risk
Train Model
factors for IP address/geographical data,
using Sample
transaction characteristics, account
data
information
Operationali • Use model to get probability of fraud for
ze scoring new transactions
using • Use PREDICT to score transactions during
PREDICT INSERT
Fraud detection using PREDICT
Demo
Deploy predictive analytics
Make your app/reports
intelligent by consuming
predictions
Deploy your ML
scripts with
Train models with sp_execute_external_
sp_execute_external script and predict
Develop, explore and _ using the models
experiment in your script and save the
favorite IDE models in database

Develop Train Deploy Consume


Roadmap
 Machine Learning Services in Azure SQL Database
 Configuration & Monitoring
 R support
 MicrosoftML Package
 Package installation / management using CREATE EXTERNAL LIBRARY
DDL
 SQL Compute Context support from client or R script executing on the
server
 Parallel execution for R Server models
 Python support
 Future release
 Machine Learning Services in SQL Server on Linux
Call to action
 Resources
 SQL Server Samples – R Services & ML Services
 SSMS Reports for ML Services
 SQL Server Machine Learning Services (aka.ms/mlsqldev)
 Getting started ML tutorials
 SQL Server Developer Tutorials (aka.ms/sqldev)
 Getting started SQL tutorials
 BRK3261
 Performance Patterns for SQL Server Machine Learning Servic
es
Please From
your

evaluate PC or tablet: visit MyIgnite


this session https://myignite.microsoft.com/evalu
ations
Phone: download and use the
Your input Microsoft Ignite mobile app
is https://aka.ms/ignite.mobileapp
important!
© Copyright Microsoft Corporation. All rights reserved.
What is Machine Learning?
• Uses data mining and learning techniques to train
models using historical data to predict future
outcomes
• Examples
• Predict store sales based on historical performance
• Predict default of a loan based on loan/transaction
history
• Predict sentiment of a new tweet or review or call
log

Potrebbero piacerti anche