@@ -27,23 +27,24 @@ BEGIN
27
27
@language = N ' Python'
28
28
, @script = N'
29
29
30
+ from sklearn import linear_model
31
+
32
+ import pickle
33
+
34
+
30
35
df = rental_train_data
31
36
32
37
# Get all the columns from the dataframe.
33
38
columns = df.columns.tolist()
34
39
35
-
36
40
# Store the variable well be predicting on.
37
41
target = "RentalCount"
38
42
39
- from sklearn.linear_model import LinearRegression
40
-
41
43
# Initialize the model class.
42
- lin_model = LinearRegression()
44
+ lin_model = linear_model. LinearRegression()
43
45
# Fit the model to the training data.
44
46
lin_model.fit(df[columns], df[target])
45
47
46
- import pickle
47
48
#Before saving the model to the DB table, we need to convert it to a binary object
48
49
trained_model = pickle.dumps(lin_model)
49
50
'
75
76
BEGIN
76
77
DECLARE @py_model varbinary (max ) = (select model from rental_py_models where model_name = @model);
77
78
78
- EXEC sp_execute_external_script
79
+ EXEC sp_execute_external_script
79
80
@language = N ' Python'
80
81
, @script = N'
81
82
82
83
83
84
import pickle
84
85
rental_model = pickle.loads(py_model)
85
86
86
-
87
+
87
88
df = rental_score_data
88
89
#print(df)
89
90
@@ -106,15 +107,15 @@ lin_mse = mean_squared_error(linpredictions, df[target])
106
107
#print(lin_mse)
107
108
108
109
import pandas as pd
109
- predictions_df = pd.DataFrame(lin_predictions)
110
+ predictions_df = pd.DataFrame(lin_predictions)
110
111
OutputDataSet = pd.concat([predictions_df, df["RentalCount"], df["Month"], df["Day"], df["WeekDay"], df["Snow"], df["Holiday"], df["Year"]], axis=1)
111
112
'
112
113
, @input_data_1 = N ' Select "RentalCount", "Year" ,"Month", "Day", "WeekDay", "Snow", "Holiday" from rental_data where Year = 2015'
113
114
, @input_data_1_name = N ' rental_score_data'
114
115
, @params = N ' @py_model varbinary(max)'
115
116
, @py_model = @py_model
116
117
with result sets ((" RentalCount_Predicted" float , " RentalCount" float , " Month" float ," Day" float ," WeekDay" float ," Snow" float ," Holiday" float , " Year" float ));
117
-
118
+
118
119
END ;
119
120
GO
120
121
0 commit comments