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

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

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

本文搭建包括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,搞定!

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

相关推荐

Github霸榜的SpringBoot全套学习教程,从入门到实战,内容超详细

前言...

SpringBoot+LayUI后台管理系统开发脚手架

源码获取方式:关注,转发之后私信回复【源码】即可免费获取到!项目简介本项目本着避免重复造轮子的原则,建立一套快速开发JavaWEB项目(springboot-mini),能满足大部分后台管理系统基础开...

Spring Boot+Vue全栈开发实战,中文版高清PDF资源

SpringBoot+Vue全栈开发实战,中文高清PDF资源,需要的可以私我:)SpringBoot致力于简化开发配置并为企业级开发提供一系列非业务性功能,而Vue则采用数据驱动视图的方式将程序...

2021年超详细的java学习路线总结—纯干货分享

本文整理了java开发的学习路线和相关的学习资源,非常适合零基础入门java的同学,希望大家在学习的时候,能够节省时间。纯干货,良心推荐!第一阶段:Java基础...

探秘Spring Cache:让Java应用飞起来的秘密武器

探秘SpringCache:让Java应用飞起来的秘密武器在当今快节奏的软件开发环境中,性能优化显得尤为重要。SpringCache作为Spring框架的一部分,为我们提供了强大的缓存管理能力,让...

3,从零开始搭建SSHM开发框架(集成Spring MVC)

目录本专题博客已共享在(这个可能会更新的稍微一些)https://code.csdn.net/yangwei19680827/maven_sshm_blog...

Spring Boot中如何使用缓存?超简单

SpringBoot中的缓存可以减少从数据库重复获取数据或执行昂贵计算的需要,从而显著提高应用程序的性能。SpringBoot提供了与各种缓存提供程序的集成,您可以在应用程序中轻松配置和使用缓...

我敢保证,全网没有再比这更详细的Java知识点总结了,送你啊

接下来你看到的将是全网最详细的Java知识点总结,全文分为三大部分:Java基础、Java框架、Java+云数据小编将为大家仔细讲解每大部分里面的详细知识点,别眨眼,从小白到大佬、零基础到精通,你绝...

1,从零开始搭建SSHM开发框架(环境准备)

目录本专题博客已共享在https://code.csdn.net/yangwei19680827/maven_sshm_blog1,从零开始搭建SSHM开发框架(环境准备)...

做一个适合二次开发的低代码平台,把程序员从curd中解脱出来-1

干程序员也有好长时间了,大多数时间都是在做curd。现在想做一个通用的curd平台直接将我们解放出来;把核心放在业务处理中。用过代码生成器,在数据表设计好之后使用它就可以生成需要的controller...

设计一个高性能Java Web框架(java做网站的框架)

设计一个高性能JavaWeb框架在当今互联网高速发展的时代,构建高性能的JavaWeb框架对于提升用户体验至关重要。本文将从多个角度探讨如何设计这样一个框架,让我们一起进入这段充满挑战和乐趣的旅程...

【推荐】强&牛!一款开源免费的功能强大的代码生成器系统!

今天,给大家推荐一个代码生成器系统项目,这个项目目前收获了5.3KStar,个人觉得不错,值得拿出来和大家分享下。这是我目前见过最好的代码生成器系统项目。功能完整,代码结构清晰。...

Java面试题及答案总结(2025版持续更新)

大家好,我是Java面试分享最近很多小伙伴在忙着找工作,给大家整理了一份非常全面的Java面试场景题及答案。...

Java开发网站架构演变过程-从单体应用到微服务架构详解

Java开发网站架构演变过程,到目前为止,大致分为5个阶段,分别为单体架构、集群架构、分布式架构、SOA架构和微服务架构。下面玄武老师来给大家详细介绍下这5种架构模式的发展背景、各自优缺点以及涉及到的...

本地缓存GuavaCache(一)(guava本地缓存原理)

在并发量、吞吐量越来越大的情况下往往是离不开缓存的,使用缓存能减轻数据库的压力,临时存储数据。根据不同的场景选择不同的缓存,分布式缓存有Redis,Memcached、Tair、EVCache、Aer...