Anaconda 安装 ml_metrics package

ml_metrics is the Python implementation of Metrics implementations a library of various supervised machine learning evaluation metrics.

首先,打开 Anaconda Prompt,


按如下步骤操作

1、搜索 ml_metrics 包

[Anaconda2] C:\Users\klchang> anaconda search -t conda ml_metrics
Using anaconda-server api site https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' to get more details:
Packages:
Name | Version | Package Types | Platforms
------------------------- | ------ | --------------- | ---------------
chdoig/ml_metrics | 0.1.3 | conda | osx-64
: Machine Learning Evaluation Metrics
dan_blanchard/ml_metrics | 0.1.3 | conda | linux-64
: https://github.com/benhamner/Metrics
/tree/master/Python
m0nhawk/ml_metrics | 0.1.4 | conda | linux-64, win-32,
win-64, linux-32, osx-64
Found 3 packages


2、显示 ml_metrics 包的信息

[Anaconda2] C:\Users\klchang> anaconda show m0nhawk/ml_metrics
Using anaconda-server api site https://api.anaconda.org
Name: ml_metrics
Summary:
Access: public
Package Types: conda
Versions:
+ 0.1.3
+ 0.1.4

To install this package with conda run:
conda install --channel https://conda.anaconda.org/m0nhawk ml_metrics


3、安装最新版本的ml_metrics 包

[Anaconda2] C:\Users\klchang>conda install --channel https://conda.anaconda.org/m0nhawk ml_metrics==0.1.4
Fetching package metadata: ......
Solving package specifications: ................
Package plan for installation in environment E:\Users\klchang\Anaconda2:

The following packages will be downloaded:

package | build
---------------------------|-----------------
mkl-11.3.3 | 1 110.0 MB defaults
vs2008_runtime-9.00.30729.1| 1 1.2 MB defaults
python-2.7.11 | 4 23.1 MB defaults
conda-env-2.4.5 | py27_0 65 KB defaults
menuinst-1.4.1 | py27_0 105 KB defaults
numpy-1.11.0 | py27_1 3.0 MB defaults
pycosat-0.6.1 | py27_1 83 KB defaults
pytz-2016.4 | py27_0 171 KB defaults
pyyaml-3.11 | py27_4 169 KB defaults
requests-2.10.0 | py27_0 615 KB defaults
setuptools-21.2.1 | py27_0 763 KB defaults
wheel-0.29.0 | py27_0 121 KB defaults
conda-4.0.7 | py27_0 228 KB defaults
pip-8.1.1 | py27_1 1.5 MB defaults
python-dateutil-2.5.3 | py27_0 236 KB defaults
pandas-0.18.1 | np111py27_0 7.0 MB defaults
ml_metrics-0.1.4 | 0 31 KB m0nhawk
------------------------------------------------------------
Total: 148.4 MB

The following NEW packages will be INSTALLED:

mkl: 11.3.3-1 defaults
ml_metrics: 0.1.4-0 m0nhawk
vs2008_runtime: 9.00.30729.1-1 defaults

The following packages will be UPDATED:

conda: 3.18.6-py27_0 defaults --> 4.0.7-py27_0 defaults

conda-env: 2.4.4-py27_2 defaults --> 2.4.5-py27_0 defaults

menuinst: 1.2.1-py27_0 defaults --> 1.4.1-py27_0 defaults

numpy: 1.10.1-py27_0 defaults --> 1.11.0-py27_1 defaults

pandas: 0.17.0-np110py27_0 defaults --> 0.18.1-np111py27_0 defaults

pip: 7.1.2-py27_0 defaults --> 8.1.1-py27_1 defaults

pycosat: 0.6.1-py27_0 defaults --> 0.6.1-py27_1 defaults

python: 2.7.10-4 defaults --> 2.7.11-4 defaults

python-dateutil: 2.4.2-py27_0 defaults --> 2.5.3-py27_0 defaults

pytz: 2015.6-py27_0 defaults --> 2016.4-py27_0 defaults

pyyaml: 3.11-py27_2 defaults --> 3.11-py27_4 defaults

requests: 2.8.1-py27_0 defaults --> 2.10.0-py27_0 defaults

setuptools: 18.5-py27_0 defaults --> 21.2.1-py27_0 defaults

wheel: 0.26.0-py27_1 defaults --> 0.29.0-py27_0 defaults


Proceed ([y]/n)? y

menuinst-1.4.1 100% |###############################| Time: 0:00:00 161.14 kB/s
Fetching packages ...
mkl-11.3.3-1.t 100% |###############################| Time: 0:02:39 725.30 kB/s
vs2008_runtime 100% |###############################| Time: 0:00:02 424.65 kB/s
python-2.7.11- 100% |###############################| Time: 0:00:24 984.44 kB/s
conda-env-2.4. 100% |###############################| Time: 0:00:00 101.80 kB/s
numpy-1.11.0-p 100% |###############################| Time: 0:00:05 580.68 kB/s
pycosat-0.6.1- 100% |###############################| Time: 0:00:00 97.22 kB/s
pytz-2016.4-py 100% |###############################| Time: 0:00:01 161.02 kB/s
pyyaml-3.11-py 100% |###############################| Time: 0:00:01 104.81 kB/s
requests-2.10. 100% |###############################| Time: 0:00:03 180.66 kB/s
setuptools-21. 100% |###############################| Time: 0:00:02 293.96 kB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:01 109.30 kB/s
conda-4.0.7-py 100% |###############################| Time: 0:00:01 142.15 kB/s
pip-8.1.1-py27 100% |###############################| Time: 0:00:05 307.28 kB/s
python-dateuti 100% |###############################| Time: 0:00:01 160.14 kB/s
pandas-0.18.1- 100% |###############################| Time: 0:00:38 189.41 kB/s
ml_metrics-0.1 100% |###############################| Time: 0:00:00 45.44 kB/s
Extracting packages ...
[ COMPLETE ]|##################################################| 100%
Unlinking packages ...
[ COMPLETE ]|##################################################| 100%
Linking packages ...
[ COMPLETE ]|##################################################| 100%

 

4、测试 ml_metrics 包,以 apk,mapk度量函数为例,(apk为average precision@k的缩写, mapk为mean average precision@k的缩写)

[Anaconda2] C:\Users\klchang> python
Python 2.7.11 |Anaconda 2.4.0 (64-bit)| (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import ml_metrics as metrics
>>> actual = [1]
>>> predicted = [1,2,3,4,5]
>>> print 'Answer=%s predicted=%s' % (actual,predicted)
Answer=[1] predicted=[1, 2, 3, 4, 5]
>>> print 'AP@5 =', metrics.apk(actual,predicted,5)
AP@5 = 1.0
>>> predicted = [2,1,3,4,5]
>>> print 'Answer=%s predicted=%s' % (actual, predicted)
Answer=[1] predicted=[2, 1, 3, 4, 5]
>>> print 'AP@5 =', metrics.apk(actual, predicted, 5)
AP@5 = 0.5
>>> predicted = [3,2,1,4,5]
>>> print 'Answer=%s predicted=%s' % (actual,predicted)
Answer=[1] predicted=[3, 2, 1, 4, 5]
>>> print 'AP@5 =', metrics.apk(actual,predicted,5)
AP@5 = 0.333333333333
>>>
>>> predicted = [4,2,3,1,5]
>>> print 'Answer=%s predicted=%s' % (actual,predicted)
Answer=[1] predicted=[4, 2, 3, 1, 5]
>>> print 'AP@5 =', metrics.apk(actual,predicted,5)
AP@5 = 0.25
>>>
>>> predicted = [2,3,4,5,1]
>>> print 'Answer=%s predicted=%s' % (actual,predicted)
Answer=[1] predicted=[2, 3, 4, 5, 1]
>>> print 'AP@5 =', metrics.apk(actual,predicted,5)
AP@5 = 0.2
>>>
>>> print 'MAP@5 = ', metrics.mapk([[1],[1],[1],[1],[1]],[[1,2,3,4,5],[2,1,3,4,5],[3,2,1,4,5],[4,2,3,1,5],[4,2,3,5,1]],5)
MAP@5 = 0.456666666667

 

参考资料:

https://www.kaggle.com/wendykan/expedia-hotel-recommendations/map-k-demo

posted @ 2016-06-15 21:16  klchang  阅读(1898)  评论(0编辑  收藏  举报