百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术教程 > 正文

python机器学习和智能运维,基础模块和环境搭建

csdh11 2025-02-09 11:57 8 浏览

本文搭建包括numpy、pandas、gensim、matplotlib、tensorflow、sklearn、jieba、NLTK常用机器学习库,打造一个基础和全面的机器学习环境。

人类一直试图让机器能够智能化,能有自主学习的能力,也就是人们常说的人工智能。

从上世纪50年代,人工智能就开始了“推理期”;到70年代,人工智能的发展进入“知识期”;直到现在,人工智能在越来越多的领域深入实践。

一,简介

那么什么是机器学习。机器学习是一类算法的总称,这些算法企图从大量历史数据中挖掘出其中隐含的规律,并用于预测或者分类,更具体说,机器学习可以看作是寻找一个函数,输入是样本数据,输出是期望的结果,只是这个函数过于复杂,以至于不太方便形式化表达。

那么我这篇文章,就来介绍和部署各种类的机器学习算法模块,尽可能地囊括现阶段Python常用的机器学习库,来搭建一套机器学习基础环境。

二,Python安装

这里拿python2.7来举例,仅仅是因为机器学习库,对python2相对兼容性更好一些。当然安装python3也是一样的操作方法。

1.linux安装python2.7,解压缩

tar –xvf Python-2.7.11.tar

2.进入解压缩后的文件夹

cd Python-2.7.11

3.在编译前先在/usr/local建一个文件夹python(作为python的安装路径,以免覆盖其他版本)

mkdir /usr/local/python

4.在解压缩后的目录下编译安装

./configure --prefix=/usr/local/python --enable-shared -enable-unicode=ucs4

make

make install

5.修改conf文件

vim /etc/ld.so.conf

添加一行数据:/usr/local/python01/lib

/sbin/ldconfig

/sbin/ldconfig -v

6.备份原来的Python:

mv  /usr/bin/python /usr/bin/python.bk 

7.再建立新版本python的链接

ln -s /usr/local/python/bin/python2.7 /usr/bin/python

这个时候输入

python

就会显示出python的新版本信息

Python 2.7.3 (default, Sep 29 2013, 11:05:02)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

4

>>>

三,机器学习模块安装

1.安装setuptools

解压setuptools-06c11.tar.gz

进入目录,cmd下执行python setup.py install


2.安装pip

解压pip-9.0.1.tar.gz

进入目录,cmd下执行python setup.py install

建立软链接 ln -s /usr/local/python/bin/pip /usr/bin/pip


3.安装numpy

NumPy是python的一个扩充程序库,支持高级大量的维度数组与矩阵运算,针对数组运算提供大量的数学函数库。NumPy内部接触了python的全局解释器锁,运算效率极高,是大量机器学习框架的基础库。

[root@ super pythonInstall]# unzip numpy-1.13.1.zip

[root@ super pythonInstall] # cd numpy-1.13.1

[root@super numpy- numpy-1.13.1]# python setup.py install

(需要GCC环境进行编译安装)


4.安装Pandas

Pandas是基于NumPy的一种工具,是python的一个数据分析包,为解决数据分析任务而创建。Pandas纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具。

[root@super pythonInstall]# pip install pytz-2018.5-py2.py3-none-any.whl

[root@super pythonInstall]# pip install six-1.11.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install python_dateutil-2.7.3-py2.py3-none-any.whl

[root@super pythonInstall]# pip install pandas-0.23.3-cp27-none-linux_x86_64.whl


5.安装 Gensim

Gensim是python的第三方工具包,用于从原始的非结构化文本中,无监督地学习到文本隐层的主题向量表达,支持包括TF-IDF、LSA、LDA和word2vec等多种主题模型算法,支持流式训练,并提供了诸如相似度计算,信息检索等一些常用任务的API接口,是自然语言处理的神器。

[root@super pythonInstall]# pip install bz2file-0.98-py2.py3-none-any.whl

[root@super pythonInstall]# pip install boto-2.48.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install idna-2.7-py2.py3-none-any.whl

[root@super pythonInstall]# pip install certifi-2018.4.16-py2.py3-none-any.whl

[root@super pythonInstall]# pip install chardet-3.0.4-py2.py3-none-any.whl

[root@super pythonInstall]# pip install urllib3-1.23-py2.py3-none-any.whl

[root@super pythonInstall]# pip install requests-2.19.1-py2.py3-none-any.whl

[root@super pythonInstall]# pip install jmespath-0.9.3-py2.py3-none-any.whl

[root@super pythonInstall]# pip install docutils-0.14-py2-none-any.whl

[root@super pythonInstall]# pip install botocore-1.10.31-py2.py3-none-any.whl

[root@super pythonInstall]# pip install requests-2.19.1-py2.py3-none-any.whl

[root@super pythonInstall]# pip install futures-3.2.0-py2-none-any.whl

[root@super pythonInstall]# pip install s3transfer-0.1.13-py2.py3-none-any.whl

[root@super pythonInstall]# pip install boto3-1.7.31-py2.py3-none-any.whl

[root@super pythonInstall]# pip install smart_open-1.6.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install scipy-1.1.0-cp27-none-linux_x86_64.whl

[root@super pythonInstall]# pip install gensim-3.5.0-cp27-none-linux_x86_64.whl


6.安装Matplotlib

Matplotlib是python的2D绘图库,它以各种硬拷贝格式和跨平台的交互环境生成出版质量级别的图形。支持方直图、功率谱、条形图、错误图、散点图等。

[root@super pythonInstall]# pip install cycler-0.10.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install backports.weakref-1.0rc1-py2-none-any.whl

[root@super pythonInstall]#pip install backports.functools_lru_cache-1.5-py2.py3-none-any.whl

[root@super pythonInstall]#pip install kiwisolver-1.0.1-cp27-none-linux_x86_64.whl [root@super pythonInstall]# pip install pyparsing-2.2.0-py2.py3-none-any.whl


[root@super pythonInstall]# tar –xvf zlib-1.2.8.tar

[root@super pythonInstall]# cd zlib-1.2.8

[root@super pythonInstall]# make clean

[root@super pythonInstall]# ./configure

[root@super pythonInstall]# make

[root@super pythonInstall]# make install

[root@super pythonInstall]# unzip libpng-libpng16.zip

[root@super pythonInstall]#cd libpng-libpng16

[root@super pythonInstall]# ./configure

[root@super pythonInstall]# ./make

[root@super pythonInstall]# ./make install

[root@super pythonInstall]# gunzip freetype-2.4.0.tar.gz

[root@super pythonInstall]# tar –xvf freetype-2.4.0.tar

[root@super pythonInstall]# cd freetype-2.4.0

[root@super pythonInstall]#./configure

[root@super pythonInstall]# make

[root@super pythonInstall]# make install

[root@super pythonInstall]# rpm -ivh tcl-8.5.13-8.el7.x86_64.rpm

[root@super pythonInstall]# rpm -ivh tk-8.5.13-6.el7.x86_64.rpm

[root@super pythonInstall]# rpm -ivh tix-8.4.3-12.el7.x86_64.rpm

[root@super pythonInstall]# rpm -ivh tcl-devel-8.5.13-8.el7.x86_64.rpm

[root@super pythonInstall]# rpm -ivh tkinter-2.7.5-34.el7.x86_64.rpm

[root@super pythonInstall]# tar -zxvf matplotlib-1.5.3.tar.gz

[root@super pythonInstall]# cd matplotlib-1.5.3

[root@super matplotlib-1.5.3]# python setup.py install

[root@super pythonInstall]# python

Python 2.7.11 (default, Aug 1 2018, 10:24:02)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import matplotlib

>>>

(需要安装g++,注意和gcc版本一致)

(如果找不到libpng16.so.16包,添加/usr/local/lib到环境变量vim /etc/ld.so.conf中,执行ldconfig生效)

(如果出现cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),

TypeError: constructor returned NULL,需要以Pdf方式

在pylab.py文件from matplotlib.pyplot import *之前,引入

import matplotlib

matplotlib.use(“Pdf”)

)


7.安装Tensorflows

Tensorflows是谷歌第二代人工智能学习系统。

[root@super pythonInstall]# pip install funcsigs-1.0.2-py2.py3-none-any.whl

[root@super pythonInstall]# pip install pbr-4.2.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install mock-2.0.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install wheel-0.31.1-py2.py3-none-any.whl

[root@super pythonInstall]# pip install protobuf-3.6.0-cp27-none-linux_x86_64.whl

[root@super pythonInstall]# pip install tensorflow-0.12.1-cp27-none-linux_x86_64.whl

[root@super pythonInstall]# cd subprocess32-3.5.2

[root@super subprocess32-3.5.2]# python setup.py install

[root@super pythonInstall]# pip install markerlib-0.6.0-py27-none-any.whl

[root@super pythonInstall]# unzip distribute-0.7.3.zip

[root@super pythonInstall]# cd distribute-0.7.3

[root@super distribute-0.7.3]# python setup.py install


8. 安装Sklearn

Sklearn是机器学习中一个常用的python第三方模块,封装了一些常用的机器学习方法,包括比如:分类算法、回归算法、聚类算法、降维算法、文本挖掘算法、模型优化、数据预处理等。

[root@super pythonInstall]# pip install patsy-0.5.0-py2.py3-none-any.whl

[root@super pythonInstall]# tar -zxvf scikit-learn-0.19.2.tar.gz

[root@super pythonInstall]# cd scikit-learn-0.19.2

[root@super scikit-learn-0.19.2]# python setup.py install

[root@super pythonInstall]# pip install pydot-1.2.4-py2.py3-none-any.whl

[root@super pythonInstall]# pip install more_itertools-4.2.0-py2-none-any.whl

[root@super pythonInstall]# pip install py-1.5.4-py2.py3-none-any.whl

[root@super pythonInstall]# tar -zxvf scandir-1.8.tar.gz

[root@super pythonInstall]# cd scandir-1.8

[root@super pythonInstall]# python setup.py install

[root@super pythonInstall]# pip install pathlib2-2.3.2-py2.py3-none-any.whl

[root@super pythonInstall]# pip install pluggy-0.7.1-py2.py3-none-any.whl

[root@super pythonInstall]# pip install atomicwrites-1.1.5-py2.py3-none-any.whl

[root@super pythonInstall]# pip install attrs-18.1.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install pytest-3.7.0-py2.py3-none-any.whl

[root@super pythonInstall]# pip install statsmodels-0.8.0-cp27-none-linux_x86_64.whl

[root@super pythonInstall]# pip install category_encoders-1.2.8-py2.py3-none-any.whl

[root@super pythonInstall]# pip install sklearn2-0.0.13-py2.py3-none-any.whl


9.安装Jieba

Jieba“结巴”是国人做的一个Python的分词库,对中文有很强大的分词能力,支持繁体分词和自定义词典,主要有三种模式,精确模式、全模式、搜索引擎模式。是自然语言中文文本分析的利器。

[root@super pythonInstall]# unzip jieba-0.39.zip

[root@super pythonInstall]# cd jieba-0.39

[root@super jieba-0.39]# python setup.py install


10.安装Nltk

Nltk,Natural Language Toolkit,是一个先进的Python自然语言处理库。

[root@super pythonInstall] # unzip nltk-3.3.0.zip

[root@super pythonInstall] # cd nltk-3.3.0

[root@super nltk-3.3.0] # python setup.py install


11.Nltk_data

Nltk_data提供了nltk的语料库,语法和训练模型等。

安装完nltk后,使用nltk.download(all)函数在线下载安装,或从http://nltk.org/nltk_data下载,离线安装。

把下载下来的nltk_data.zip包解压缩到/root/nltk_data目录下。

[root@super nltk_data] # unzip nltk_data.zip

[root@super nltk_data] # cd corpora

[root@super nltk_data] # find . -name "*.zip" | xargs -n1 unzip

验证安装是否成功

>>> import nltk.book

*** Introductory Examples for the NLTK Book ***

Loading text1, ..., text9 and sent1, ..., sent9

Type the name of the text or sentence to view it.

Type: 'texts()' or 'sents()' to list the materials.

text1: Moby Dick by Herman Melville 1851

text2: Sense and Sensibility by Jane Austen 1811

text3: The Book of Genesis

text4: Inaugural Address Corpus

text5: Chat Corpus

text6: Monty Python and the Holy Grail

text7: Wall Street Journal

text8: Personals Corpus

text9: The Man Who Was Thursday by G . K . Chesterton 1908

至此,OK,搞定!

本文由挨踢程序猿原创,欢迎关注,带你一起长知识!

相关推荐

当iPhone X遇上 Mate 10 Pro 怎么挑?

产品:Mate10Pro(全网通)华为手机1iPhoneX一出就遇上了对手Hello!大家好我是石头这里是zol。首先来看看我手里的这个,不是装x的意思,今天好多人欢天喜地的拿到了属于自己或者属...

谁是办公高手? 六款商务平板全推荐

1超低功耗联想Thinkpad10领衔ThinkPad的名字在笔记本上依然是高曝光率,从IBM到联想,它一直以来是商务、办公领域的不二人选,然而在平板电脑大行其道的今天,ThinkPad当然也不单...

如何仅用几行代码将微信4.0公测版转换成玲珑格式?

微信4.0(玲珑版)已上架如意玲珑应用商店!!!...

音乐研发必备:理解 MIDI 协议与标准 MIDI 文件格式

1.MIDI简介...

HEIF格式可以节约50%的空间!质量会有影响吗?

关于手机1亿像素到底有没有必要,争议肯定是存在的,但无法回避的一点是随着像素的成倍增加,一张照片十几MB成了常事,这必将给本就不太宽裕的存储容量造成压力,这种压力又会转嫁到用户身上,让他们不得不花更多...

「干货分享」30个前端知识技能提升的资源网站

今天给小伙伴们分享30个前端相关学习资源网站及一些在线小工具,希望能帮助到大家。CSS相关1、css精灵牛|在线图片CSS生成工具。...

用Facebook引流Shopify独立站,如何优化Facebook商户页面?

什么是FacebookBusinessPage?FacebookBusinessPage是官方的称号,其实你可以简单理解为facebookbusinesspage就是微信公众账户,而我们...

玩转手机摄影 nubia Z9 mini新品首测

1Z9系列新品nubiaZ9mini发布会开始之前的邀请函总能透露出很多内容,或者说我们总会特意解读出很多内容。nubia此前发出的3月26日智能手机新品发布会的邀请函很显然再一次着重强调了其产品...

影院看片怕座位不好?那买个盒子在家看

着消费者对高清播放器的需求的不断增加,高清播放器的功能也在不断得到提升。以前看电影的时候相信很多人更喜欢去电影院里观看,但是有时候去电影院的人太多买不到好位子也会让不少人感到扫兴。现在随着技术的革新,...

今天你买了么?不入后悔的8款平板推荐

随着高考大战的落幕,对于广大学生朋友们来说正真的暑假终于来了!这个假期想要外出旅行或是居家畅玩,没有一款便携式全能娱乐利器的平板电脑怎么能叫放假呢?正直京东618购物季即将到来的日子,相信你也不会错过...

Cursor使用指南:释放AI编程的无限潜能

Cursor简介...

谁说轻薄本缺乏生产力?没体验过别乱说

笔记本电脑轻薄化一直是各大厂商们不断努力的方向,不过早前的轻薄笔记本电脑会受制于技术方面的限制,无法将高能耗的CPU以及显卡塞入轻薄的机身内。为了能给这些芯片散热、供电,制造商们不得不对这些芯片的功耗...

通告ImageMagick再爆核心漏洞 站长小心

目前所有版本的GraphicsMagick和ImageMagick都支持打开文件,当文件名的第一个字符为“|”,则文件名会被传递给shell程序执行,导致(可能远程)代码执行。文件打开操作位于源代码文...

《玻璃之花与坏掉的世界》再曝新宣传片

雨文冰璃发表于昨天22:56【新闻】《玻璃之花与坏掉的世界》再曝新宣传片http://comic.qq.com/a/20151122/016784.htmPONYCANYON和A-1Pictu...

7 招教你轻松搭建以图搜图系统

作者|小龙责编|胡巍巍当您听到“以图搜图”时,是否首先想到了百度、Google等搜索引擎的以图搜图功能呢?事实上,您完全可以搭建一个属于自己的以图搜图系统:自己建立图片库;自己选择一张图片到...