Skip to content

Commit 5fc57ea

Browse files
committed
updated T-SQL topics from LiveFyre comments on ML features
1 parent 2badebe commit 5fc57ea

3 files changed

Lines changed: 86 additions & 64 deletions

File tree

docs/t-sql/queries/predict-transact-sql.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
22
title: "PREDICT (Transact-SQL) | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "07/17/2017"
4+
ms.date: "02/25/2018"
55
ms.prod: "sql-non-specified"
66
ms.prod_service: "sql-database"
77
ms.service: ""
88
ms.component: "t-sql|queries"
99
ms.reviewer: ""
1010
ms.suite: "sql"
1111
ms.technology:
12-
1312
ms.tgt_pltfrm: ""
1413
ms.topic: "language-reference"
1514
f1_keywords:
@@ -67,32 +66,34 @@ The DATA parameter is used to specify the data used for scoring or prediction. D
6766

6867
The PARAMETERS parameter is used to specify optional user-defined parameters used for scoring or prediction.
6968

70-
The name of each parameter is specific to the model type. For example, the rxPredict function in RevoScaleR supports the parameter _@computeResiduals bit_ to support computation of residuals when scoring a logistic regression model. YOu could pass that parameter name and it value to the `PREDICT` function.
69+
The name of each parameter is specific to the model type. For example, the [rxPredict](https://docs.microsoft.com/machine-learning-server/r-reference/revoscaler/rxpredict) function in RevoScaleR supports the parameter `@computeResiduals`, which indicates whether residuals should be computed when scoring a logistic regression model. If you are calling a compatible model, you could pass that parameter name and a TRUE or FALSE value to the `PREDICT` function.
7170

7271
> [NOTE]
73-
> This option is not supported in the pre-release of SQL Server 2017 and is included for forward-compatibility purposes only.
72+
> This option does not work in pre-release versions of SQL Server 2017.
7473
75-
**WITH ( \<result_set_definition> )**
74+
**WITH ( <result_set_definition> )**
7675

7776
The WITH clause is used to specify the schema of the output returned by the `PREDICT` function.
7877

7978
In addition to the columns returned by the `PREDICT` function itself, all the columns that are part of the data input are available for use in the query.
8079

8180
### Return values
8281

83-
No predefined schema is available; SQL Server does not validate the contents of the model and does not validate the returned column values.
84-
- The `PREDICT` function passes through columns as input
85-
- The `PREDICT` function also generates new columns, but the number of columns and their data types depends on the type of model that was used for prediction.
82+
No predefined schema is available; SQL Server does not validate the contents of the model and does not validate the returned column values.
8683

87-
Any error messages related to the data, the model, or the column format are returned by the underlying prediction function associated with the model.
88-
- For RevoScaleR, the equivalent function is [rxPredict](https://docs.microsoft.com/r-server/r-reference/revoscaler/rxpredict)
89-
- For MicrosoftML, the equivalent function is [rxPredict.mlModel](https://docs.microsoft.com/r-server/r-reference/microsoftml/rxpredict)
84+
- The `PREDICT` function passes through columns as input.
85+
- The `PREDICT` function also generates new columns, but the number of columns and their data types depends on the type of model that was used for prediction.
86+
87+
Any error messages related to the data, the model, or the column format are returned by the underlying prediction function associated with the model.
88+
89+
- For RevoScaleR, the equivalent function is [rxPredict](https://docs.microsoft.com/machine-learning-server/r-reference/revoscaler/rxpredict)
90+
- For MicrosoftML, the equivalent function is [rxPredict.mlModel](https://docs.microsoft.com/machine-learning-server/r-reference/microsoftml/rxpredict)
9091

9192
It is not possible to view the internal model structure using `PREDICT`. If you want to understand the contents of the model itself, you must load the model object, deserialize it, and use appropriate R code to parse the model.
9293

9394
## Remarks
9495

95-
The `PREDICT` function is supported in all editions of SQL Server, including Linux.
96+
The `PREDICT` function is supported in all editions of SQL Server, including Linux, and in Azure SQL Database, regardless of whether other machine learning features are enabled. However, SQL Server 2017 or later is required.
9697

9798
It is not necessary that R, Python, or another machine learning language be installed on the server to use the `PREDICT` function. You can train the model in another environment and save it to a SQL Server table for use with `PREDICT`, or call the model from another instance of SQL Server that has the saved model.
9899

@@ -113,7 +114,7 @@ The following examples demonstrate the syntax for calling `PREDICT`.
113114
This example calls an existing logistic regression model stored in table [models_table]. It gets the latest trained model, using a SELECT statement, and then passes the binary model to the PREDICT function. The input values represent features; the output represents the classification assigned by the model.
114115

115116
```sql
116-
DECLARE @logit_model varbinary(max) = "SELECT TOP 1 @model from [models_table]";
117+
DECLARE @logit_model varbinary(max) = "SELECT TOP 1 [model_binary] from [models_table] ORDER BY [trained_date] DESC";
117118
DECLARE @input_qry = "SELECT ID, [Gender], [Income] from NewCustomers";
118119

119120
SELECT PREDICT [class]
@@ -131,7 +132,7 @@ FROM PREDICT(MODEL = @logit_model,
131132
DATA = dbo.mytable AS d) WITH (Score float) AS p;
132133
```
133134

134-
The alias **d** specified for table source in the _DATA_ parameter is used to reference the columns belonging to dbo.mytable. The alias **p** specified for the **PREDICT** function is used to reference the columns returned by the PREDICT function.
135+
The alias **d** specified for table source in the `DATA` parameter is used to reference the columns belonging to dbo.mytable. The alias **p** specified for the **PREDICT** function is used to reference the columns returned by the PREDICT function.
135136

136137
### Combining PREDICT with an INSERT statement
137138

@@ -180,7 +181,7 @@ logitObj <- rxLogit(Kyphosis ~ Age + Start + Number, data = kyphosis, covCoef =
180181

181182
If you store the model in SQL Server in binary format, you can use the PREDICT function to generate not just predictions, but additional information supported by the model type, such as error or confidence intervals.
182183

183-
The following code shows the equivalent call from R to rxPredict:
184+
The following code shows the equivalent call from R to [rxPredict](https://docs.microsoft.com/machine-learning-server/r-reference/revoscaler/rxpredict):
184185

185186
```R
186187
rxPredict(logitObj, data = new_kyphosis_data, computeStdErr = TRUE, interval = "confidence")
@@ -195,5 +196,3 @@ FROM PREDICT( MODEL = @logitObj, DATA = new_kyphosis_data AS d,
195196
computeStdErr = 1, interval = 'confidence')
196197
WITH (pred float, stdErr float, pred_lower float, pred_higher float) AS p;
197198
```
198-
199-

docs/t-sql/statements/alter-external-library-transact-sql.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
22
title: "ALTER EXTERNAL LIBRARY (Transact-SQL) | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "10/05/2017"
4+
ms.date: "02/25/2018"
55
ms.prod: "sql-non-specified"
66
ms.prod_service: "database-engine"
77
ms.service: ""
88
ms.component: "t-sql|statements"
99
ms.reviewer: ""
1010
ms.suite: "sql"
1111
ms.technology:
12-
1312
ms.tgt_pltfrm: ""
1413
ms.topic: "language-reference"
1514
f1_keywords:
@@ -31,7 +30,7 @@ Modifies the content of an existing external package library.
3130

3231
## Syntax
3332

34-
```
33+
```text
3534
ALTER EXTERNAL LIBRARY library_name
3635
[ AUTHORIZATION owner_name ]
3736
SET <file_spec>
@@ -59,6 +58,8 @@ WITH ( LANGUAGE = 'R' )
5958

6059
Specifies the name of an existing package library. Libraries are scoped to the user. That is, library names are considered unique within the context of a specific user or owner.
6160

61+
The library name cannot be arbitrarily assigned. That is, you must use the name that the calling runtime expects when it loads the package.
62+
6263
**owner_name**
6364

6465
Specifies the name of the user or role that owns the external library.
@@ -80,7 +81,11 @@ Specifies the name of the external data source that contains the location of the
8081
8182
**library_bits**
8283

83-
Specifies the content of the package as a hex literal, similar to assemblies. This option allows users to create a library to alter the library if they have the required permission, but do not have file path access to any folder the server can access.
84+
Specifies the content of the package as a hex literal, similar to assemblies.
85+
86+
This option is useful if you have the required permission to alter a library, but file access on the server is restricted and you cannot save the contents to a path the server can access.
87+
88+
Instead, you can pass the package contents as a variable in binary format.
8489

8590
**PLATFORM = WINDOWS**
8691

@@ -90,39 +95,34 @@ Specifies the platform for the content of the library. This value is required wh
9095

9196
For the R language, packages must be prepared in the form of zipped archive files with the .ZIP extension for Windows. Currently, only the Windows platform is supported.
9297

93-
The `ALTER EXTERNAL LIBRARY` statement only uploads the library bits to the database. The modified library is not actually installed until a user runs an external script afterwards, by executing [sp_execute_external_script (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-execute-external-script-transact-sql.md).
98+
The `ALTER EXTERNAL LIBRARY` statement only uploads the library bits to the database. The modified library is installed when a user runs code in [sp_execute_external_script (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-execute-external-script-transact-sql.md) that calls the library.
9499

95100
## Permissions
96101

97102
Requires the `ALTER ANY EXTERNAL LIBRARY` permission. Users who created an external library, can alter that external library.
98103

99104
## Examples
100105

101-
The following examples modifies an external library called customPackage.
106+
The following examples modifies an external library called `customPackage`.
102107

103108
### A. Replace the contents of a library using a file
104109

105-
The following example modifies an external library called customPackage, using a zipped file containing the updated bits.
110+
The following example modifies an external library called `customPackage`, using a zipped file containing the updated bits.
106111

107112
```sql
108113
ALTER EXTERNAL LIBRARY customPackage
109114
SET
110115
(CONTENT = 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\customPackage.zip')
111116
WITH (LANGUAGE = 'R');
112-
```
117+
```
113118

114119
To install the updated library, execute the stored procedure `sp_execute_external_script`.
115120

116-
```sql
121+
```sql
117122
EXEC sp_execute_external_script
118123
@language =N'R',
119-
@script=N'
120-
# load customPackage
121-
library(customPackage)
122-
# call customPackageFunc
123-
OutputDataSet <- customPackageFunc()
124-
'
125-
WITH RESULT SETS (([result] int));
124+
@script=N'library(customPackage)'
125+
;
126126
```
127127

128128
### B. Alter an existing library using a byte stream
@@ -133,9 +133,11 @@ The following example alters the existing library by passing the new bits as a h
133133
ALTER EXTERNAL LIBRARY customLibrary FROM (CONTENT = 0xabc123) WITH (LANGUAGE = 'R');
134134
```
135135

136-
## See also
136+
In this code sample, the variable contents are truncated for readability.
137+
138+
## See also
137139

138140
[CREATE EXTERNAL LIBRARY (Transact-SQL)](create-external-library-transact-sql.md)
139141
[DROP EXTERNAL LIBRARY (Transact-SQL)](drop-external-library-transact-sql.md)
140142
[sys.external_library_files](../../relational-databases/system-catalog-views/sys-external-library-files-transact-sql.md)
141-
[sys.external_libraries](../../relational-databases/system-catalog-views/sys-external-libraries-transact-sql.md)
143+
[sys.external_libraries](../../relational-databases/system-catalog-views/sys-external-libraries-transact-sql.md)

0 commit comments

Comments
 (0)