@@ -27,23 +27,24 @@ BEGIN
2727 @language = N ' Python'
2828 , @script = N'
2929
30+ from sklearn import linear_model
31+
32+ import pickle
33+
34+
3035df = rental_train_data
3136
3237# Get all the columns from the dataframe.
3338columns = df.columns.tolist()
3439
35-
3640# Store the variable well be predicting on.
3741target = "RentalCount"
3842
39- from sklearn.linear_model import LinearRegression
40-
4143# Initialize the model class.
42- lin_model = LinearRegression()
44+ lin_model = linear_model. LinearRegression()
4345# Fit the model to the training data.
4446lin_model.fit(df[columns], df[target])
4547
46- import pickle
4748#Before saving the model to the DB table, we need to convert it to a binary object
4849trained_model = pickle.dumps(lin_model)
4950'
7576BEGIN
7677 DECLARE @py_model varbinary (max ) = (select model from rental_py_models where model_name = @model);
7778
78- EXEC sp_execute_external_script
79+ EXEC sp_execute_external_script
7980 @language = N ' Python'
8081 , @script = N'
8182
8283
8384import pickle
8485rental_model = pickle.loads(py_model)
8586
86-
87+
8788df = rental_score_data
8889#print(df)
8990
@@ -106,15 +107,15 @@ lin_mse = mean_squared_error(linpredictions, df[target])
106107#print(lin_mse)
107108
108109import pandas as pd
109- predictions_df = pd.DataFrame(lin_predictions)
110+ predictions_df = pd.DataFrame(lin_predictions)
110111OutputDataSet = pd.concat([predictions_df, df["RentalCount"], df["Month"], df["Day"], df["WeekDay"], df["Snow"], df["Holiday"], df["Year"]], axis=1)
111112'
112113 , @input_data_1 = N ' Select "RentalCount", "Year" ,"Month", "Day", "WeekDay", "Snow", "Holiday" from rental_data where Year = 2015'
113114 , @input_data_1_name = N ' rental_score_data'
114115 , @params = N ' @py_model varbinary(max)'
115116 , @py_model = @py_model
116117 with result sets ((" RentalCount_Predicted" float , " RentalCount" float , " Month" float ," Day" float ," WeekDay" float ," Snow" float ," Holiday" float , " Year" float ));
117-
118+
118119END ;
119120GO
120121
0 commit comments