forked from Azure-Samples/Azure-MachineLearning-DataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrainTipPredictionModel.sql
More file actions
45 lines (35 loc) · 1.31 KB
/
TrainTipPredictionModel.sql
File metadata and controls
45 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
USE [TaxiNYC_Sample]
GO
/****** Object: StoredProcedure [dbo].[TrainTipPredictionModel] Script Date: 10/29/2015 4:36:25 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'TrainTipPredictionModel')
DROP PROCEDURE TrainTipPredictionModel
GO
CREATE PROCEDURE [dbo].[TrainTipPredictionModel]
AS
BEGIN
DECLARE @inquery nvarchar(max) = N'
select tipped, fare_amount, passenger_count,trip_time_in_secs,trip_distance,
pickup_datetime, dropoff_datetime,
dbo.fnCalculateDistance(pickup_latitude, pickup_longitude, dropoff_latitude, dropoff_longitude) as direct_distance
from nyctaxi_joined_1_percent
tablesample (70 percent) repeatable (98052)
'
-- Insert the trained model into a database table
INSERT INTO nyc_taxi_models
EXEC sp_execute_external_script @language = N'R',
@script = N'
## Create model
logitObj <- rxLogit(tipped ~ passenger_count + trip_distance + trip_time_in_secs + direct_distance, data = InputDataSet)
summary(logitObj)
## Serialize model and put it in data frame
trained_model <- data.frame(model=as.raw(serialize(logitObj, NULL)));
',
@input_data_1 = @inquery,
@output_data_1_name = N'trained_model'
;
END
GO