1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00
Files
sql-server-samples/samples/features/machine-learning-services/python/getting-started/rental-prediction
Umachandar Jayachandran 95a6346266 Merge pull request #268 from NelGson/master
Updates to ski rental python sample for SQL Server 2017 RC2.
2017-08-14 12:07:41 -07:00
..
2017-04-21 00:09:04 -07:00
2017-04-21 17:01:12 -07:00

Build a predictive model with Python using SQL Server 2017 Machine Learning Services

This sample shows how to create a predictive model in Python and operationalize it with SQL Server 2017

Contents

About this sample
Before you begin
Sample details

About this sample

Predictive modeling is a powerful way to add intelligence to your application. It enables applications to predict outcomes against new data. The act of incorporating predictive analytics into your applications involves two major phases: model training and model operationalization.

In this sample, you will learn how to create a predictive model in python and operationalize it with SQL Server vNext.

  • Applies to: SQL Server 2017 CTP2.0 or higher
  • Key features: SQL Server Machine Learning Services
  • Workload: SQL Server Machine Learning Services
  • Programming Language: T-SQL, Python
  • Authors: Nellie Gustafsson
  • Update history: Getting started tutorial for SQL Server ML Services - Python

Before you begin

To run this sample, you need the following prerequisites:
Download this DB backup file and restore it using Setup.sql.

Software prerequisites:

  1. SQL Server 2017 CTP2.0 (or higher) with Machine Learning Services (Python) installed
  2. SQL Server Management Studio
  3. Python Tools for Visual Studio or another Python IDE

Run this sample

  1. From SQL Server Management Studio, or SQL Server Data Tools, connect to your SQL Server 2017 database and execute setup.sql to restore the sample DB you have downloaded
  2. From SQL Server Management Studio or SQL Server Data Tools, open the rental_prediction.sql script
    This script sets up:
    Necessary tables
    Creates stored procedure to train a model
    Creates a stored procedure to predict using that model
    Saves the predicted results to a DB table
  3. You can also try the Python script on its own, connecting to SQL Server and getting data using RevoScalePy Rx functions. Just remember to point the Python environment to the corresponding path "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES" if you run in-db Python Server, or "C:\Program Files\Microsoft SQL Server\140\PYTHON_SERVER" if you have the standalone Machine Learning Server installed.

Sample details

This sample shows how to create a predictive model with Python and generate predictions using the model and deploy that in SQL Server with SQL Server Machine Learning Services.

rental_prediction.py

The Python script that generates a predictive model and uses it to predict rental counts

rental_prediction.sql

Takes the Python code in rental_prediction.py and deploys it inside SQL Server. Creating stored procedures and tables for training, storing models and creating stored procedures for prediction.

setup.sql

Restores the sample DB (Make sure to update the path to the .bak file)