尝试SQL Server 2017 安装Python 机器学习

       最近有时间,尝试按微软的指导文档进行SQL Server 2017 安装Python 机器学习,见https://docs.microsoft.com/zh-cn/sql/machine-learning/install/sql-machine-learning-services-windows-install?view=sql-server-2017。

      我是在原有已安装sql2017开发版的基础上安装的,总结此过程遇到的坑:

       增加功能时,在功能选择页面上一定要把“R”和“Python”都选上,如果只选“Python”到后面安装预先定型的机器学习模型时可能会出现“INFO: no SQL Server instances identified for model installation”之类的错误提示。在“同意安装 Microsoft R Open”页上,要选择“接受”,然后选择“下一步” ,直到安装完成。

       安装完了之后重启电脑,有可能不能启动SQL Server服务,弹出“Windows不能在本地计算机启动sql server .........错误代码10013”的对话框,可以在SQL Server网络配置中先将“Named Pipes”和“TCP/IP”协议禁用,可以启动SQL Server服务。具体原因仍待查明。

       安装预先定型的机器学习模型,单击 https://aka.ms/mlm4sql 下载文件 Install-MLModels.ps1。以管理员身份打开PowerShell,运行下载的文件,过程中可能会出错或退出等,可以通过https://go.microsoft.com/fwlink/?LinkId=852262&clcid=1033离线下载MLM_9.2.0.24_1033.cab数据包,解压后有

  • AlexNet_Updated.model
  • ImageNet1K_mean.xml
  • pretrained.model
  • ResNet_101_Updated.model
  • ResNet_18_Updated.model
  • ResNet_50_Updated.model

将所有文件复制到C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\Lib\site-packages\microsoftml\mxLibs文件夹里面。

      可以用Python验证安装了,启动 C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES 处的 Python.exe。

>>> import numpy
>>> import pandas
>>> from microsoftml import rx_logistic_regression, rx_featurize, rx_predict, get_sentiment

Express Edition will continue to be enforced.
>>> customer_reviews = pandas.DataFrame(data=dict(review=["I really did not like the taste of it", "It was surprisingly quite good!", "I will never ever ever go to that place again!!"]))
>>> sentiment_scores = rx_featurize( data=customer_reviews, ml_transforms=[get_sentiment(cols=dict(scores="review"))])
Beginning processing data.
Rows Read: 3, Read Time: 0.088, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:07.8370188
Finished writing 3 rows.
Writing completed.
>>> sentiment_scores["eval"] = sentiment_scores.scores.apply(  lambda score: "AWESOMENESS" if score > 0.6 else "BLAH")
>>> print(sentiment_scores)
                                            review    scores         eval
0            I really did not like the taste of it  0.461790         BLAH
1                  It was surprisingly quite good!  0.960192  AWESOMENESS
2  I will never ever ever go to that place again!!  0.310344         BLAH
>>>

安装成功。

 

你可能感兴趣的:(SQL,Server,Python)