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

Organizing the data


I want to start this section by showing you some of Python's analytical and graphic capabilities. I am explaining the code just briefly here; you will learn more about Python data structures very quickly. Let's start coding! First, I need to import the necessary libraries:

import numpy as np
import pandas as pd
import pyodbc
import matplotlib.pyplot as plt

For the data I will analyze, I am using the data from the AdventureWorksDW2017 demo database, selecting from the dbo.vTargetMail view, like I did in Chapter 2, Introducing R, when I introduced the R language. I am also using ODBC to connect to SQL Server, with the same data source name and SQL Server login as I did then:

con = pyodbc.connect('DSN=AWDW;UID=RUser;PWD=Pa$$w0rd')
query = """SELECT CustomerKey, 
             Age, YearlyIncome, 
             CommuteDistance, BikeBuyer
           FROM dbo.vTargetMail;"""
TM = pd.read_sql(query, con)

You can get quick info about the data with the following code, which shows the...