Book Image

Data Science with SQL Server Quick Start Guide

By : Dejan Sarka
Book Image

Data Science with SQL Server Quick Start Guide

By: Dejan Sarka

Overview of this book

SQL Server only started to fully support data science with its two most recent editions. If you are a professional from both worlds, SQL Server and data science, and interested in using SQL Server and Machine Learning (ML) Services for your projects, then this is the ideal book for you. This book is the ideal introduction to data science with Microsoft SQL Server and In-Database ML Services. It covers all stages of a data science project, from businessand data understanding,through data overview, data preparation, modeling and using algorithms, model evaluation, and deployment. You will learn to use the engines and languages that come with SQL Server, including ML Services with R and Python languages and Transact-SQL. You will also learn how to choose which algorithm to use for which task, and learn the working of each algorithm.
Table of Contents (15 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Handling missing values


Let me start by creating and populating a small table with a couple of missing values in some cells, denoted by the reserved word NULL in SQL Server:

USE AdventureWorksDW2017;
GO
DROP TABLE IF EXISTS dbo.NULLTest;
GO
CREATE TABLE dbo.NULLTest
(
 c1 INT NULL,
 c2 INT NULL,
 c3 INT NULL
);
GO
INSERT INTO dbo.NULLTest VALUES
(1, NULL, 3),
(4, 5, 6),
(NULL, 8, 9),
(10, 11, 12),
(13, NULL, NULL);
GO

The content of the table is as follows:

c1          c2          c3
----------- ----------- -----------
1           NULL        3
4           5           6
NULL        8           9
10          11          12
13          NULL        NULL

In T-SQL, you can use the ISNULL() and COALESCE() functions to work with NULLs. The first one has only two parameters and returns the value of the first parameter, if it is not NULL, and the values of the second parameter otherwise. The second function, just mentioned, accepts multiple parameters and returns the first one that is not NULL. You can...