Loan Classification using SQL Server 2016 R Services

Published Mar 23 2019 02:47 PM 403 Views
Microsoft
First published on MSDN on Sep 27, 2016
R Services (In-database) provides a platform for developing and deploying intelligent applications that uncover new insights. You can use the rich and powerful R language and the many packages from the community to create models and generate predictions using your SQL Server data. Because R Services (In-database) integrates the R language with SQL Server, you can keep analytics close to the data and eliminate the costs and security risks associated with data movement.

In this post, we will see how we can leverage SQL Server 2016 as a Scoring Engine to predict "bad" loans. Loans that indicate good repayment behavior are considered "good" and loans that indicate less than perfect repayment behavior are considered "bad".

The Azure Data Science VM comes pre-installed with SQL Server 2016 Developer edition and can be used readily for our scoring experiment. We will use the publicly available dataset of Lending Club loan performance .

This experiment consists of 6 steps. We shall define stored procedures in SQL for each of these steps and execute them in order.






DATA PREPARATION




Create a DB, say ‘lendingclub’ in SQL Server
CREATE DATABASE [lendingclub]
Download the loan data into a folder (say C:\lendingclub)

There are 6 csv files: LoanStats3a.csv, LoanStats3b.csv, LoanStats3c.csv, LoanStats3d.csv, LoanStats_2016Q1.csv, LoanStats_2016Q2.csv. Use the following clean-up steps for the csv files :
1. Remove this line at the beginning of file : “Notes offered by Prospectus (https://www.lendingclub.com/info/prospectus.action)”
2. Remove these lines at the end of file : “Total amount funded in policy code 1: Total amount funded in policy code 2: ”
3. Remove the line “Loans that do not meet the credit policy” in LoanStats3a.csv at line number 39788, 39789, 39790.

Now, let us import the data from these 6 csv files to a single table [dbo].[LoanStats] in lendingclub DB. There are many ways to import csv data into SQL (using bcp, powershell etc) but we are going to use something quick and easy – sp_execute_external_script !



Executing the above stored procedure creates a table [dbo].[LoanStats] with loan data :
EXEC [dbo].[LoadData]
Once the data is loaded, let us do some cleaning using SQL and also identify good/bad loans based on the value of the column [loan_status] :




FEATURE SELECTION




Before we run feature-selection, let’s install the required R packages by following this guide :

Right Click C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\R_SERVICES\bin\x64\Rgui.exe and Run as Administrator. Run the following R code to install the packages:
install.packages(c("reshape2","ggplot2","ROCR","plyr","Rcpp","stringr","stringi","magrittr","digest","gtable",
"proto","scales","munsell","colorspace","labeling","gplots","gtools","gdata","caTools","bitops"),
lib = "C:\\Program Files\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER\\R_SERVICES\\library")
There are many ways to perform feature selection/variable selection. A quick and easy way is to use ggplot to plot the distribution of is_bad variable for each numeric variable. From this plot, we can identify variables which have significant differences in the is_bad=0(good) and is_bad=1(bad) population.
Stored procedure to plot distribution .



Executing the above stored procedure creates a JPEG image in C:\temp\plots
EXEC [dbo].[PlotDistribution]




Good predictors have significant differences in the distribution lines factor(is_bad)=0 (Red) and factor(is_bad)=1 (Blue), for example : int_rate. ID variables like id, member_id will also be plotted in the above image (since they are numeric as well), but they cannot be used as predictor variables - hence ignore such variables. Let us choose some predictors variables by quickly analyzing the above image and use them in our Random Forest Model. (NOTE: This is not the final/best list of predictors, you may choose other methods to find predictors as well)
revol_util, int_rate, mths_since_last_record, annual_inc_joint, dti_joint, total_rec_prncp, all_util

DATA PARTITION




We shall use SQL to split the Loan Data into Training Data 75% ([dbo].[LoanStatsTrain]) and Test Data 25% ([dbo].[LoanStatsTest]). Training data will be used to build the model and the built model shall be applied on test data for evaluation.
Stored procedure to split the data



Executing the above stored procedure creates 2 tables [dbo].[LoanStatsTrain] and [dbo].[LoanStatsTest]
EXEC [dbo].[SplitLoans]

MODELLING




Build a Random Forest Model using the variables we identified in Feature Selection and store the model in a table [dbo].[models] to be used later for scoring.



Executing the above stored procedure builds a random forest model and stores it in [dbo].[models]
EXEC [dbo].[BuildModel]
SELECT * FROM [dbo].[models]



SCORING




Stored Procedure to use the model in [dbo].[models] and score test data [dbo].[LoanStatsTest]



Executing the above stored procedure creates a table [dbo].[LoanStatsPredictions] which contains the predictions in is_bad_Pred column
EXEC [dbo].[ScoreLoans]
SELECT TOP 10 * FROM [dbo].[LoanStatsPredictions]



MODEL EVALUATION




Now let us plot a ROC curve to evaluate the model. We will also calculate the Area under ROC Curve



Executing the above stored procedure will save the ROC curve in C:\temp\plots as well as output the Area Under The Curve measure (AUC)
EXEC [dbo].[PlotROCCurve]




NOTE : We can improve scoring performance (number of predictions per second) using In-Memory Tables, Columnstore Indexes and Resource Governor Configurations. These steps are detailed with github code in this blog post : A walkthrough of Loan Classification using SQL Server 2016 R Services

REFERENCES




Lending Club Statistics

Machine Learning for Predicting Bad Loans

Variable Importance Plot and Variable Selection

Machine Learning Templates with SQL Server 2016 R Services

SQL Server R Services Tutorials

Provision the Microsoft Data Science Virtual Machine

sp_execute_external_script (Transact-SQL)

Explore and Visualize the Data (In-Database Advanced Analytics Tutorial)

Selecting Rows Randomly from a Large Table

Receiver operating characteristic

Area under the curve

The Area Under an ROC Curve

%3CLINGO-SUB%20id%3D%22lingo-sub-384812%22%20slang%3D%22en-US%22%3ELoan%20Classification%20using%20SQL%20Server%202016%20R%20Services%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-384812%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Sep%2027%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20R%20Services%20(In-database)%20provides%20a%20platform%20for%20developing%20and%20deploying%20intelligent%20applications%20that%20uncover%20new%20insights.%20You%20can%20use%20the%20rich%20and%20powerful%20R%20language%20and%20the%20many%20packages%20from%20the%20community%20to%20create%20models%20and%20generate%20predictions%20using%20your%20SQL%20Server%20data.%20Because%20R%20Services%20(In-database)%20integrates%20the%20R%20language%20with%20SQL%20Server%2C%20you%20can%20keep%20analytics%20close%20to%20the%20data%20and%20eliminate%20the%20costs%20and%20security%20risks%20associated%20with%20data%20movement.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20this%20post%2C%20we%20will%20see%20how%20we%20can%20leverage%20SQL%20Server%202016%20as%20a%20Scoring%20Engine%20to%20predict%20%22bad%22%20loans.%20Loans%20that%26nbsp%3Bindicate%20good%20repayment%20behavior%20are%20considered%20%22good%22%20and%20loans%26nbsp%3Bthat%20indicate%20less%20than%20perfect%20repayment%20behavior%20are%20considered%20%22bad%22.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fmachine-learning-data-science-provision-vm%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Azure%20Data%20Science%20VM%20%3C%2FA%3E%20comes%20pre-installed%20with%20SQL%20Server%202016%20Developer%20edition%20and%20can%20be%20used%20readily%20for%20our%20scoring%20experiment.%20We%20will%20use%20the%20publicly%20available%20dataset%20of%20%3CA%20href%3D%22https%3A%2F%2Fwww.lendingclub.com%2Finfo%2Fdownload-data.action%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Lending%20Club%20loan%20performance%20%3C%2FA%3E%20.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20This%20experiment%20consists%20of%206%20steps.%20We%20shall%20define%20stored%20procedures%20in%20SQL%20for%20each%20of%20these%20steps%20and%20execute%20them%20in%20order.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98065i90D8783758CD61E1%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1680725354%22%20id%3D%22toc-hId--325783118%22%3E%3CSTRONG%3E%20DATA%20PREPARATION%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Create%20a%20DB%2C%20say%20%E2%80%98lendingclub%E2%80%99%20in%20SQL%20Server%20%3CBR%20%2F%3E%20CREATE%20DATABASE%20%5Blendingclub%5D%20%3CBR%20%2F%3E%20Download%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.lendingclub.com%2Finfo%2Fdownload-data.action%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20loan%20data%20%3C%2FA%3E%20into%20a%20folder%20(say%20C%3A%5Clendingclub)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20There%20are%206%20csv%20files%3A%20LoanStats3a.csv%2C%20LoanStats3b.csv%2C%20LoanStats3c.csv%2C%20LoanStats3d.csv%2C%20LoanStats_2016Q1.csv%2C%20LoanStats_2016Q2.csv.%20Use%20the%20following%20clean-up%20steps%20for%20the%20csv%20files%20%3A%20%3CBR%20%2F%3E%201.%20Remove%20this%20line%20at%20the%20beginning%20of%20file%20%3A%20%E2%80%9CNotes%20offered%20by%20Prospectus%20(%3CA%20href%3D%22https%3A%2F%2Fwww.lendingclub.com%2Finfo%2Fprospectus.action)%E2%80%9D%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.lendingclub.com%2Finfo%2Fprospectus.action)%E2%80%9D%3C%2FA%3E%20%3CBR%20%2F%3E%202.%20Remove%20these%20lines%20at%20the%20end%20of%20file%20%3A%20%E2%80%9CTotal%20amount%20funded%20in%20policy%20code%201%3A%20Total%20amount%20funded%20in%20policy%20code%202%3A%20%E2%80%9D%20%3CBR%20%2F%3E%203.%20Remove%20the%20line%20%E2%80%9CLoans%20that%20do%20not%20meet%20the%20credit%20policy%E2%80%9D%20in%20LoanStats3a.csv%20at%20line%20number%2039788%2C%2039789%2C%2039790.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Now%2C%20let%20us%20import%20the%20data%20from%20these%206%20csv%20files%20to%20a%20single%20table%20%5Bdbo%5D.%5BLoanStats%5D%20in%20lendingclub%20DB.%20There%20are%20many%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fheyscriptingguy%2F2011%2F11%2F28%2Ffour-easy-ways-to-import-csv-files-to-sql-server-with-powershell%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20ways%20%3C%2FA%3E%20to%20import%20csv%20data%20into%20SQL%20(using%20bcp%2C%20powershell%20etc)%20but%20we%20are%20going%20to%20use%20something%20quick%20and%20easy%20%E2%80%93%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt604368.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20sp_execute_external_script%20%3C%2FA%3E%20!%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20creates%20a%20table%20%5Bdbo%5D.%5BLoanStats%5D%20with%20loan%20data%20%3A%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BLoadData%5D%20%3CBR%20%2F%3E%20Once%20the%20data%20is%20loaded%2C%20let%20us%20do%20some%20cleaning%20using%20SQL%20and%20also%20identify%20good%2Fbad%20loans%20based%20on%20the%20value%20of%20the%20column%20%5Bloan_status%5D%20%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--871431607%22%20id%3D%22toc-hId--2133237581%22%3E%3CSTRONG%3E%20FEATURE%20SELECTION%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Before%20we%20run%20feature-selection%2C%20let%E2%80%99s%20install%20the%20required%20R%20packages%20by%20following%20this%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt591989.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20guide%20%3C%2FA%3E%20%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Right%20Click%20C%3A%5CProgram%20Files%5CMicrosoft%20SQL%20Server%5CMSSQL13.MSSQLSERVER%5CR_SERVICES%5Cbin%5Cx64%5CRgui.exe%20and%20Run%20as%20Administrator.%20Run%20the%20following%20R%20code%20to%20install%20the%20packages%3A%20%3CBR%20%2F%3E%20install.packages(c(%22reshape2%22%2C%22ggplot2%22%2C%22ROCR%22%2C%22plyr%22%2C%22Rcpp%22%2C%22stringr%22%2C%22stringi%22%2C%22magrittr%22%2C%22digest%22%2C%22gtable%22%2C%20%3CBR%20%2F%3E%20%22proto%22%2C%22scales%22%2C%22munsell%22%2C%22colorspace%22%2C%22labeling%22%2C%22gplots%22%2C%22gtools%22%2C%22gdata%22%2C%22caTools%22%2C%22bitops%22)%2C%20%3CBR%20%2F%3E%20lib%20%3D%20%22C%3A%5C%5CProgram%20Files%5C%5CMicrosoft%20SQL%20Server%5C%5CMSSQL13.MSSQLSERVER%5C%5CR_SERVICES%5C%5Clibrary%22)%20%3CBR%20%2F%3E%20There%20are%20many%20%3CA%20href%3D%22https%3A%2F%2Fwww.r-bloggers.com%2Fvariable-importance-plot-and-variable-selection%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20ways%20%3C%2FA%3E%20to%20perform%20feature%20selection%2Fvariable%20selection.%20A%20quick%20and%20easy%20way%20is%20to%20use%20%3CA%20href%3D%22http%3A%2F%2Fggplot.yhathq.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20ggplot%20%3C%2FA%3E%20to%20plot%20the%20distribution%20of%20is_bad%20variable%20for%20each%20numeric%20variable.%20From%20this%20plot%2C%20we%20can%20identify%20variables%20which%20have%20significant%20differences%20in%20the%20is_bad%3D0(good)%20and%20is_bad%3D1(bad)%20population.%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt683486.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Stored%20procedure%20to%20plot%20distribution%20%3C%2FA%3E%20.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20creates%20a%20JPEG%20image%20in%26nbsp%3BC%3A%5Ctemp%5Cplots%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BPlotDistribution%5D%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98066i50BC81F74732EDF8%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Good%20predictors%20have%20significant%20differences%20in%20the%20distribution%20lines%20factor(is_bad)%3D0%20(Red)%20and%20factor(is_bad)%3D1%20(Blue)%2C%20for%20example%20%3A%20int_rate.%26nbsp%3BID%20variables%20like%20id%2C%20member_id%20will%20also%20be%20plotted%20in%20the%20above%20image%20(since%20they%20are%20numeric%20as%20well)%2C%20but%20they%20cannot%20be%20used%20as%20predictor%20variables%20-%20hence%20ignore%20such%20variables.%20Let%20us%20choose%20some%20predictors%20variables%20by%20quickly%20analyzing%20the%20above%20image%20and%20use%20them%20in%20our%20Random%20Forest%20Model.%20(NOTE%3A%20This%20is%20not%20the%20final%2Fbest%20list%20of%20predictors%2C%20you%20may%20choose%20other%20methods%20to%20find%20predictors%20as%20well)%20%3CBR%20%2F%3E%20revol_util%2C%20int_rate%2C%20mths_since_last_record%2C%20annual_inc_joint%2C%20dti_joint%2C%20total_rec_prncp%2C%20all_util%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-871378728%22%20id%3D%22toc-hId-354275252%22%3E%3CSTRONG%3E%20DATA%20PARTITION%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20We%20shall%20use%20SQL%20to%20split%20the%20Loan%20Data%20into%20Training%20Data%2075%25%20(%5Bdbo%5D.%5BLoanStatsTrain%5D)%20and%20Test%20Data%2025%25%20(%5Bdbo%5D.%5BLoanStatsTest%5D).%20Training%20data%20will%20be%20used%20to%20build%20the%20model%20and%20the%20built%20model%20shall%20be%20applied%20on%20test%20data%20for%20evaluation.%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fcc441928.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Stored%20procedure%20to%20split%20the%20data%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20creates%202%20tables%20%5Bdbo%5D.%5BLoanStatsTrain%5D%20and%20%5Bdbo%5D.%5BLoanStatsTest%5D%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BSplitLoans%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1680778233%22%20id%3D%22toc-hId--1453179211%22%3E%3CSTRONG%3E%20MODELLING%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Build%20a%20Random%20Forest%20Model%20using%20the%20variables%20we%20identified%20in%20Feature%20Selection%20and%20store%20the%20model%20in%20a%20table%20%5Bdbo%5D.%5Bmodels%5D%20to%20be%20used%20later%20for%20scoring.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20builds%20a%20random%20forest%20model%20and%20stores%20it%20in%20%5Bdbo%5D.%5Bmodels%5D%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BBuildModel%5D%20%3CBR%20%2F%3E%20SELECT%20*%20FROM%20%5Bdbo%5D.%5Bmodels%5D%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98067iA7EEBC719F5C15CF%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-62032102%22%20id%3D%22toc-hId-1034333622%22%3E%3CSTRONG%3E%20SCORING%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Stored%20Procedure%20to%20use%20the%20model%20in%20%5Bdbo%5D.%5Bmodels%5D%20and%20score%20test%20data%20%5Bdbo%5D.%5BLoanStatsTest%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20creates%20a%20table%20%5Bdbo%5D.%5BLoanStatsPredictions%5D%20which%20contains%20the%20predictions%20in%20is_bad_Pred%20column%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BScoreLoans%5D%20%3CBR%20%2F%3E%20SELECT%20TOP%2010%20*%20FROM%20%5Bdbo%5D.%5BLoanStatsPredictions%5D%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98068i45C6588955947D17%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1804842437%22%20id%3D%22toc-hId--773120841%22%3E%3CSTRONG%3E%20MODEL%20EVALUATION%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Now%20let%20us%20plot%20a%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FReceiver_operating_characteristic%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20ROC%20%3C%2FA%3E%20curve%20to%20evaluate%20the%20model.%20We%20will%20also%20calculate%20the%20%3CA%20href%3D%22http%3A%2F%2Fgim.unmc.edu%2Fdxtests%2Froc3.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Area%20under%20ROC%20Curve%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Executing%20the%20above%20stored%20procedure%20will%20save%20the%20ROC%20curve%20in%20C%3A%5Ctemp%5Cplots%20as%20well%20as%20output%20the%20Area%20Under%20The%20Curve%20measure%20(AUC)%20%3CBR%20%2F%3E%20EXEC%20%5Bdbo%5D.%5BPlotROCCurve%5D%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98069iAD4F1990425B0D74%22%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F98070iA7F8FD2F4B4315C6%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20NOTE%20%3A%20%3C%2FSTRONG%3E%20We%20can%20improve%20scoring%20performance%20(number%20of%20predictions%20per%20second)%20using%20In-Memory%20Tables%2C%20Columnstore%20Indexes%20and%20Resource%20Governor%20Configurations.%20These%20steps%20are%20detailed%20with%20github%20code%20in%20this%20blog%20post%20%3A%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fsql_server_team%2Fa-walkthrough-of-loan-classification-using-sql-server-2016-r-services%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20A%20walkthrough%20of%20Loan%20Classification%20using%20SQL%20Server%202016%20R%20Services%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--747314524%22%20id%3D%22toc-hId-1714391992%22%3E%3CSTRONG%3E%20REFERENCES%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fwww.lendingclub.com%2Finfo%2Fdownload-data.action%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Lending%20Club%20Statistics%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2Fblog.yhat.com%2Fposts%2Fmachine-learning-for-predicting-bad-loans.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Machine%20Learning%20for%20Predicting%20Bad%20Loans%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fwww.r-bloggers.com%2Fvariable-importance-plot-and-variable-selection%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Variable%20Importance%20Plot%20and%20Variable%20Selection%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2FSQL-Server-R-Services-Samples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Machine%20Learning%20Templates%20with%20SQL%20Server%202016%20R%20Services%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt591993.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20SQL%20Server%20R%20Services%20Tutorials%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fmachine-learning-data-science-provision-vm%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Provision%20the%20Microsoft%20Data%20Science%20Virtual%20Machine%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt604368.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20sp_execute_external_script%20(Transact-SQL)%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt683486.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Explore%20and%20Visualize%20the%20Data%20(In-Database%20Advanced%20Analytics%20Tutorial)%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fcc441928.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Selecting%20Rows%20Randomly%20from%20a%20Large%20Table%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FReceiver_operating_characteristic%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Receiver%20operating%20characteristic%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FReceiver_operating_characteristic%23Area_under_the_curve%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Area%20under%20the%20curve%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2Fgim.unmc.edu%2Fdxtests%2Froc3.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20The%20Area%20Under%20an%20ROC%20Curve%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-384812%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Sep%2027%2C%202016%20R%20Services%20(In-database)%20provides%20a%20platform%20for%20developing%20and%20deploying%20intelligent%20applications%20that%20uncover%20new%20insights.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-384812%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerMachineLearning%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 23 2019 02:47 PM
Updated by: