Skip to content

Instantly share code, notes, and snippets.

@ramnov
Last active September 29, 2016 06:06
Show Gist options
  • Save ramnov/4eaa0d8a30e2796efeac41691f5b0bdd to your computer and use it in GitHub Desktop.
Save ramnov/4eaa0d8a30e2796efeac41691f5b0bdd to your computer and use it in GitHub Desktop.
Stored Procedure to split the data into train(75%) and test(25%)
CREATE PROCEDURE [dbo].[SplitLoans]
AS
BEGIN
SET NOCOUNT ON;
-- 75% Training data
DROP TABLE IF EXISTS [dbo].[LoanStatsTrain]
SELECT * INTO [dbo].[LoanStatsTrain] FROM (SELECT * FROM [dbo].[LoanStats] WHERE (ABS(CAST((BINARY_CHECKSUM(id, NEWID())) as int)) % 100) < 75)a
-- 25% Test data
DROP TABLE IF EXISTS [dbo].[LoanStatsTest]
SELECT * INTO [dbo].[LoanStatsTest] FROM (SELECT * FROM [dbo].[LoanStats] WHERE [id] NOT IN (SELECT [id] FROM [dbo].[LoanStatsTrain]))a
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment