完全新手: windows64 bit 安装python2.7.11 和 scikit-learn
2016-04-15 12:54
831 查看
完全新手 windows 7 64位 安装python2.7.11和 scikit-learnpython包。如果你能顺利的连上python官网,那么不需要再看了。python2.7.11已经自带了包管理工具pip,直接更新和安装需要的包就好了。如果 使用pip直接安装总是显示超时,则自己动手:
下载python-2.7.11.amd64.msi,假设安装到 D:\python
D:\python 和D:\python\Scripts 添加到系统环境变量 PATH 中,以便能在命令行使用 python 和 pip
下载 pip-8.1.1.tar.gz。安装过程中可能会提示你更新pip,所以可以先装个新版本的pip,需要8.1.1的可以在此下载http://download.csdn.net/detail/u011736505/9492080点击打开链接。先将该文件解压,在cmd中进入该文件夹,输入python setup.py install
在http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载所需的包,分别是 numpy+mkl,scipy,scikit-learn和matplot 。下载的时候注意选择win_amd64 和 cp27 以对应安装的python版本2.7.*和对应的64位平台,否则会出现错误:is not a supported wheel 。假设将这些包都放在D:\pythonlib 文件夹中
在cmd中进入D:\pythonlib
先安装numpy+mkl 输入 pip isntall numpy-1.11.0+mkl-cp27-cp27m-win_amd64.whl
再安装scipy 输入 pip install scipy-0.17.0-cp27-none-win_amd64.whl
安装scikit-learn 输入 pip install scikit_learn-0.17.1-cp27-cp27m-win_amd64.whl
可选:安装matplot 输入 pip install matplotlib-1.5.1-cp27-none-win_amd64.whl,该文件同样可以在4中的网址下载到。
验证安装是否成功:在python 的shell中输入如下片段,能够输出鸢尾花的数据
试试画图功能:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201604/550c60b345fe9e650ca9e2f389c36171)
下载python-2.7.11.amd64.msi,假设安装到 D:\python
D:\python 和D:\python\Scripts 添加到系统环境变量 PATH 中,以便能在命令行使用 python 和 pip
下载 pip-8.1.1.tar.gz。安装过程中可能会提示你更新pip,所以可以先装个新版本的pip,需要8.1.1的可以在此下载http://download.csdn.net/detail/u011736505/9492080点击打开链接。先将该文件解压,在cmd中进入该文件夹,输入python setup.py install
在http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载所需的包,分别是 numpy+mkl,scipy,scikit-learn和matplot 。下载的时候注意选择win_amd64 和 cp27 以对应安装的python版本2.7.*和对应的64位平台,否则会出现错误:is not a supported wheel 。假设将这些包都放在D:\pythonlib 文件夹中
在cmd中进入D:\pythonlib
先安装numpy+mkl 输入 pip isntall numpy-1.11.0+mkl-cp27-cp27m-win_amd64.whl
再安装scipy 输入 pip install scipy-0.17.0-cp27-none-win_amd64.whl
安装scikit-learn 输入 pip install scikit_learn-0.17.1-cp27-cp27m-win_amd64.whl
可选:安装matplot 输入 pip install matplotlib-1.5.1-cp27-none-win_amd64.whl,该文件同样可以在4中的网址下载到。
验证安装是否成功:在python 的shell中输入如下片段,能够输出鸢尾花的数据
试试画图功能:
#测试数据导入:鸢尾花
from sklearn import datasets iris = datasets.load_iris() iris.data.shape iris.target.shape import numpy as np np.unique(iris.target) print(iris.data)
#测试plot功能,代码来源于网络,一个 Elastic Net 模型
<pre name="code" class="python">import sklearn.datasets import sklearn.linear_model import numpy.random import numpy.linalg import matplotlib.pyplot if __name__ == "__main__": # Load boston dataset boston = sklearn.datasets.load_boston() # Split the dataset with sampleRatio sampleRatio = 0.5 n_samples = len(boston.target) sampleBoundary = int(n_samples * sampleRatio) # Shuffle the whole data shuffleIdx = range(n_samples) numpy.random.shuffle(shuffleIdx) # Make the training data train_features = boston.data[shuffleIdx[:sampleBoundary]] train_targets = boston.target[shuffleIdx [:sampleBoundary]] # Make the testing data test_features = boston.data[shuffleIdx[sampleBoundary:]] test_targets = boston.target[shuffleIdx[sampleBoundary:]] # Train elasticNet = sklearn.linear_model.ElasticNetCV(alphas=[0.01, 0.05, 0.1, 0.5, 1.0, 10.0], l1_ratio=[0.1,0.3,0.5,0.7,0.9]) elasticNet.fit(train_features, train_targets) print "Alpha = ", elasticNet.alpha_ print "L1 Ratio = ", elasticNet.l1_ratio_ # Predict predict_targets = elasticNet.predict(test_features) # Evaluation n_test_samples = len(test_targets) X = range(n_test_samples) error = numpy.linalg.norm(predict_targets - test_targets, ord = 1) / n_test_samples print "Elastic Net (Boston) Error: %.2f" %(error) # Draw matplotlib.pyplot.plot(X, predict_targets, 'r--', label = 'Predict Price') matplotlib.pyplot.plot(X, test_targets, 'g:', label='True Price') legend = matplotlib.pyplot.legend() matplotlib.pyplot.title("Elastic Net (Boston)") matplotlib.pyplot.ylabel("Price (1000 U.S.D)") matplotlib.pyplot.savefig("Elastic Net (Boston).png", format='png') matplotlib.pyplot.show()#如果成功的话,将看到下图。
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法