本次示例在windows 8 64位环境下,python为2.7版本 首先安装numpy和scipy两个包,我开始试验了pip install numpy之类的安装方式,后来发现安装会出现依赖包不符合等问题,因此改成了直接下载whl文件来安装。 下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy ,其中有大量的python库。 下载后发现用pip install somexxx.whl方式提示is not a supported wheel file的提示,百度了下,发现有大神说直接将whl改成zip文件后缀,解压后放到python2.7\lib\site-package目录下就可以了。果然如此。 接着安装pip install sklearn(还是Scikit-learn ?) ,pip install matplotlib等成功。 示例代码如果出现图形则一切成功(注意,在virtualenv环境下使用matplotlib画图总是出现tcl错误,果断放弃) #! -*- coding:utf-8 -*- from sklearn import datasets from sklearn.cross_validation import cross_val_predict from sklearn import linear_model import matplotlib.pyplot as plt lr = linear_model.LinearRegression() boston = datasets.load_boston() y = boston.target # cross_val_predict returns an array of the same size as `y` where each entry # is a prediction obtained by cross validated: predicted = cross_val_predict(lr, boston.data, y, cv=10) print predicted fig, ax = plt.subplots() ax.scatter(y, predicted) ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4) ax.set_xlabel('Measured') ax.set_ylabel('Predicted') plt.show() |
版权声明:本文为CSDN博主「weixin_34019929」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_34019929/article/details/92014602