sklearn学习笔记之开始

简介

  自2007年发布以来,scikit-learn已经成为Python重要的机器学习库了。scikit-learn简称sklearn,支持包括分类、回归、降维和聚类四大机器学习算法。还包含了特征提取、数据处理和模型评估三大模块。
  sklearn是Scipy的扩展,建立在NumPy和matplotlib库的基础上。利用这几大模块的优势,可以大大提高机器学习的效率。
  sklearn拥有着完善的文档,上手容易,具有着丰富的API,在学术界颇受欢迎。sklearn已经封装了大量的机器学习算法,包括LIBSVM和LIBINEAR。同时sklearn内置了大量数据集,节省了获取和整理数据集的时间。

  • 机器学习基础

  定义:针对经验E和一系列的任务T和一定表现的衡量P,如果随着经验E的积累,针对定义好的任务T可以提高表现P,就说明机器具有学习能力。

  •  sklearn安装

    sklearn目前的版本是0.17.1,可以使用pip安装。在安装时需要进行包依赖检查,具体有以下几个要求:

  • Python(>=2.6 or >=3.3)
  • NumPy(>=1.6.1)
  • SciPy(>=0.9)

    如果满足上述条件,就能使用pip进行安装了:

1 pip install -U scikit-learn
SaintKings-Mac-mini:nlp saintking$ pip install -U scikit-learn
Collecting scikit-learn
  Using cached scikit_learn-0.19.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: scikit-learn
Exception:
Traceback (most recent call last):
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/Users/saintking/Library/Python/2.7/lib/python/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/scikit_learn-0.19.1.dist-info'

 安装方法:真机测试正常

SaintKings-Mac-mini:nlp saintking$ sudo pip install -U scikit-learn

现在采用安装Anaconda的方法.      

当然,使用pip安装会比较麻烦,推荐使用Anaconda科学计算环境,里面已经内置了NumPy、SciPy、sklearn等模块,直接可用。或者使用conda进行包管理。conda安装与pip类似:

1  conda install scikit-learn

       安装完sklearn以后,可以检查以下版本:

1  >>> import sklearn
2  >>> sklearn.__version__
3  '0.17.1'
posted @ 2017-11-03 12:09  小码哥0520  阅读(594)  评论(0编辑  收藏  举报