Machine Learning Services in SQL Server, brings AI directly to your data: https://aka.ms/SQLMLOverview.
No more need to move data around or work on samples. You can operationalize your R and Python machine learning models directly within your enterprise grade database server. SQL Machine Learning Services enables you to work with any open source packages and additionally provides algorithms which enable multi-threaded, parallel processing for industry leading scale and performance.
If you don’t have Machine Learning Services in SQL Server installed or enabled, check out these other related how-to videos:
How to Install Machine Learning Services in SQL Server: https://aka.ms/InstallMLServices
How to Enable R/Python Code Execution in SQL Server: https://aka.ms/EnableMLServices
Visit our documentation to learn more advanced techniques like how to remotely execute R/Python in SQL Server from your own IDE like Jupyter Notebooks, PyCharm, RStudio, etc.
Advanced Execution Documentation: https://aka.ms/ExecuteSQLMLDocs
Here is code from the video for quick copy/paste:
Basic:
EXEC sp_execute_external_script @language = N’Python’, @script = N’print(3+4)’
Input parameter:
EXEC sp_execute_external_script @language =N’Python’,
@script=N’
OutputDataSet = InputDataSet;
‘,
@input_data_1 =N’SELECT 1 AS Col1′;
Input/Output name:
EXEC sp_execute_external_script @language =N’Python’,
@script=N’
MyOutput = MyInput;
‘,
@input_data_1_name = N’MyInput’,
@input_data_1 =N’SELECT 1 AS foo’,
@output_data_1_name =N’MyOutput’;
Result Column Name:
EXEC sp_execute_external_script @language =N’Python’,
@script=N’
MyOutput = MyInput;
‘,
@input_data_1_name = N’MyInput’,
@input_data_1 =N’
SELECT 1 AS foo,
2 AS bar
‘,
@output_data_1_name =N’MyOutput’
WITH RESULT SETS ((MyColName int, MyColName2 int));
Pandas Dataframe conversion:
EXEC sp_execute_external_script @language =N’Python’,
@script=N’
import pandas as pd
c = 1/2
d = 1*2
s = pd.Series([c,d])
df = pd.DataFrame(s)
OutputDataSet = df
‘
Pandas Dataframe conversion 2:
EXEC sp_execute_external_script @language =N’Python’,
@script=N’
import pandas as pd
s = {“col1”: [1, 2], “col2”: [3, 4]}
df = pd.DataFrame(s)
OutputDataSet = df
‘