SQL Server Machine Learning Tutorials

This article provides a comprehensive list of the tutorials, demos, and sample applications that use R or Python with SQL Server 2016 or SQL Server 2017. Start here to learn how to run R or Python from T-SQL, use remote and local compute contexts, and optimize your R and Python code for a SQL production environment.

Start Here

  • Samples are real-world scenarios for embedding machine learning in applications. All samples include code that you can download, modify, and use in production.

  • Solutions from the Microsoft Data Science team demonstrate end-to-end scenarios. Most are designed to run either in SQL Server or in a cloud environment such as Azure machine Learning.

For more information about requirements and how to get set up, see Prerequisites.

Prerequisites

To use these tutorials and samples, you must have installed one of the following server products:

  • SQL Server 2016 R Services (In-Database)

    Supports R. Be sure to install the machine learning features, and then enable external scripting.

  • SQL Server 2017 Machine Learning Services (In-Database)

    Supports either R or Python. You must select the machine learning feature and the language to install, and then enable external scripting.

For more information about setup, see Prerequisites.

Note

Support for Python is a new feature in SQL Server 2017 (CTP 2.0). Although the feature is in pre-release and not supported for production environments, we invite you to try it out and send feedback.

SQL Server Product Samples

These samples and demos provided by the SQL Server and R Server development team highlight ways that you can use embedded analytics in real-world applications.

Learn RevoScaleR

Wondering what RevoScaleR offers that R doesn't? See these tutorials:

Customizable End-to-End Solutions

The Microsoft Data Science Team has provided solution templates that can be used to jump-start solutions for common scenarios. All T-SQL and R code is provided, along with instructions on how to train and deploy a model for scoring using SQL Server stored procedures.

For more information, see Machine Learning Templates with SQL Server 2016 R Services.

Resources and Reading

  • Want to know the real story behind R Services? Read this article from the development and PM team: Why did we build it?

Prerequisites

To run these tutorials, you must download and install the SQL Server machine learning components, as described here:

With SQL Server 2017 CTP 2.0, you can install either R or Python, or both. Otherwise the overall setup process, architecture, and requirements are the same.

After running SQL Server setup, don't forget these important steps:

  • Enable the external script execution feature by running sp_configure 'enable external script', 1
  • Restart the server
  • Ensure that the service that calls the external runtime has necessary permissions
  • Ensure that your SQL login or Windows user account has necessary permissions to connect to the server, to read data, and to create any database objects required by the sample

If you run into trouble, see this article for some common issues: Upgrade and Installation of SQL Server R Services

Note

You cannot run these tutorials using just the standard R or Python tools. Both your development environment and the SQL Server computer with machine learning must have the R or Python libraries provided by Microsoft.