首页 > 其他分享 >Intel daal4py demo运行过程

Intel daal4py demo运行过程

时间:2023-05-30 22:05:41浏览次数:38  
标签:Intel License demo daal4py shape res print csv data

daal安装(记得先安装anaconda):

git clone https://github.com/IntelPython/daal4py.git
cd daal4py
conda create -n DAAL4PY -c intel -c intel/label/test -c conda-forge python=3.6 mpich cnc tbb-devel daal daal-include cython jinja2 numpy
source activate DAAL4PY
export CNCROOT=$CONDA_PREFIX
export TBBROOT=$CONDA_PREFIX
export DAALROOT=$CONDA_PREFIX
python setup.py build_ext
python setup.py install
# 运行后面的demo

source deactivate DAAL4PY # 退出

 注意:安装过程较慢,耐心等待。

 

随机森林:

#*******************************************************************************
# Copyright 2014-2018 Intel Corporation
# All Rights Reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the
# "License"), the following terms apply:
#
# You may not use this file except in compliance with the License.  You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

# daal4py Decision Forest Classification example for shared memory systems

import daal4py as d4p
import numpy as np

# let's try to use pandas' fast csv reader
try:
    import pandas
    read_csv = lambda f, c: pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=np.float32).values
except:
    # fall back to numpy loadtxt
    read_csv = lambda f, c: np.loadtxt(f, usecols=c, delimiter=',', ndmin=2, dtype=np.float32)


def main():
    # input data file
    infile = "./data/batch/df_classification_train.csv"
    testfile = "./data/batch/df_classification_test.csv"

    # Configure a training object (5 classes)
    train_algo = d4p.decision_forest_classification_training(5, nTrees=10, minObservationsInLeafNode=8, featuresPerNode=3, engine = d4p.engines_mt19937(seed=777),
                                                             varImportance='MDI', bootstrap=True, resultsToCompute='computeOutOfBagError')
    
    # Read data. Let's use 3 features per observation
    data   = read_csv(infile, range(3))
    labels = read_csv(infile, range(3,4))
    train_result = train_algo.compute(data, labels)
    # Traiing result provides (depending on parameters) model, outOfBagError, outOfBagErrorPerObservation and/or variableImportance

    # Now let's do some prediction
    predict_algo = d4p.decision_forest_classification_prediction(5)
    # read test data (with same #features)
    pdata = read_csv(testfile, range(3))
    plabels = read_csv(testfile, range(3,4))
    # now predict using the model from the training above
    predict_result = predict_algo.compute(pdata, train_result.model)

    # Prediction result provides prediction
    assert(predict_result.prediction.shape == (pdata.shape[0], 1))

    return (train_result, predict_result, plabels)


if __name__ == "__main__":
    (train_result, predict_result, plabels) = main()
    print("\nVariable importance results:\n", train_result.variableImportance)
    print("\nOOB error:\n", train_result.outOfBagError)
    print("\nDecision forest prediction results (first 10 rows):\n", predict_result.prediction[0:10])
    print("\nGround truth (first 10 rows):\n", plabels[0:10])
    print('All looks good!')

 demo示例数据:

0.00125126,0.563585,8,2,
0.193304,0.808741,12,1,
0.585009,0.479873,6,1,
0.350291,0.895962,13,4,
0.82284,0.746605,11,2,
0.174108,0.858943,12,0,
0.710501,0.513535,10,2,
0.303995,0.0149846,1,2,
0.0914029,0.364452,4,0,
0.147313,0.165899,0,4,
0.988525,0.445692,7,2,
0.119083,0.00466933,0,2,
0.0089114,0.37788,4,2,
0.531663,0.571184,10,3,
0.601764,0.607166,10,4,
0.166234,0.663045,8,4,
0.450789,0.352123,5,3,
0.0570391,0.607685,8,4,
0.783319,0.802606,15,3,
0.519883,0.30195,6,2,
0.875973,0.726676,11,1,
0.955901,0.925718,15,3,
0.539354,0.142338,2,3,
0.462081,0.235328,1,2,
0.862239,0.209601,3,1,
0.779656,0.843654,15,3,
0.996796,0.999695,15,2,
0.611499,0.392438,6,0,
0.266213,0.297281,5,2,
0.840144,0.0237434,3,1,
0.375866,0.0926237,1,0,
0.677206,0.0562151,2,3,
0.00878933,0.91879,12,2,
0.275887,0.272897,5,2,
0.587909,0.691183,10,4,
0.837611,0.726493,11,1,
0.484939,0.205359,1,2,
0.743736,0.468459,6,2,
0.457961,0.949156,13,3,
0.744438,0.10828,2,2,
0.599048,0.385235,6,0,
0.735008,0.608966,10,2,
0.572405,0.361339,6,0,
0.151555,0.225105,0,3,
0.425153,0.802881,13,3,

 

 

计算均值 方差等统计特征:

#*******************************************************************************

# Copyright 2014-2018 Intel Corporation

# All Rights Reserved.

#

# This software is licensed under the Apache License, Version 2.0 (the

# "License"), the following terms apply:

#

# You may not use this file except in compliance with the License.  You may

# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

#

# See the License for the specific language governing permissions and

# limitations under the License.

#*******************************************************************************



# daal4py low order moments example for shared memory systems



import daal4py as d4p

import numpy as np



# let's try to use pandas' fast csv reader

try:

    import pandas

    read_csv = lambda f, c: pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=np.float64).values

except:

    # fall back to numpy loadtxt

    read_csv = lambda f, c: np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)





def main():

    # read data from file

    file = "./data/batch/covcormoments_dense.csv"

    data = read_csv(file, range(10))



    # compute

    alg = d4p.low_order_moments()

    res = alg.compute(data)



    # result provides minimum, maximum, sum, sumSquares, sumSquaresCentered,

    # mean, secondOrderRawMoment, variance, standardDeviation, variation

    assert res.minimum.shape == (1, data.shape[1])

    assert res.maximum.shape == (1, data.shape[1])

    assert res.sum.shape == (1, data.shape[1])

    assert res.sumSquares.shape == (1, data.shape[1])

    assert res.sumSquaresCentered.shape == (1, data.shape[1])

    assert res.mean.shape == (1, data.shape[1])

    assert res.secondOrderRawMoment.shape == (1, data.shape[1])

    assert res.variance.shape == (1, data.shape[1])

    assert res.standardDeviation.shape == (1, data.shape[1])

    assert res.variation.shape == (1, data.shape[1])



    return res





if __name__ == "__main__":

    res = main()

    # print results

    print("\nMinimum:\n", res.minimum)

    print("\nMaximum:\n", res.maximum)

    print("\nSum:\n", res.sum)

    print("\nSum of squares:\n", res.sumSquares)

    print("\nSum of squared difference from the means:\n", res.sumSquaresCentered)

    print("\nMean:\n", res.mean)

    print("\nSecond order raw moment:\n", res.secondOrderRawMoment)

    print("\nVariance:\n", res.variance)

    print("\nStandard deviation:\n", res.standardDeviation)

    print("\nVariation:\n", res.variation)

    print('All looks good!')

 

标签:Intel,License,demo,daal4py,shape,res,print,csv,data
From: https://blog.51cto.com/u_11908275/6382270

相关文章

  • MarkdownDemo
    标题语法与#号键有关,此为二级标题段落要创建段落,请使用空白行将一行或多行文本进行分隔。suchasthis标题似乎自带空白行换行语法在一行的末尾添加两个或多个空格,然后按回车键,即可创建一个换行似乎用处不大(换行还得是回车键)强调语法通过将文本设置为粗体或斜体来强调......
  • IntelliJ IDEA安装教程
    在安装编译器之前,有些人可能会疑惑是否需要安装Java环境。如果你使用的是IntelliJIDEA,那么你不需要手动安装Java环境,因为IDEA已经包含了Java开发所需的一切。除了Java环境,你还提到了Git和Maven。同样地,如果你使用的是IntelliJIDEA,你也不需要手动安装Git和Maven。IDEA已经......
  • U3DFrameWorkDemo:六、网络
    代码参考代码文件参考下述详解的类图,工程参考第零章工程说明概述在多人联机游戏中,大多采用前、后台的架构,前台多表现相关,后台则多交互、资产相关。网络消息的传递其实是由系统内核完成的,大多语言封装了Socket库面向开发者提供网络消息传递的接口,而这里的网络模块是对网络消息传......
  • Multiserver游戏服务器Demo[C++&Lua]
    代码参考代码文件参考下述详解的类图,工程参考第零章工程说明关键特性对Socket库进行封装,抹平Socket的Window&Linux的平台差异。C++嵌入lua脚本,增加开发者编码效率,减少编译时间消耗。非阻塞网络IO多线程任务模型多服务模型详解Socket库封装主要是对C++的Socket库进行......
  • U3DFrameWorkDemo:四、资源打包和热更
    代码参考代码文件参考下述详解的类图,工程参考第零章工程说明概述热更新方便用户更新,增加用户的留存量。它依赖打包生成的版本文件。思路打包考虑分包策略,包体太大加载速度慢且可能有无效的内存冗余,包体太小可能会频繁加载AB造成效率下降。核心思想是把用到的东西放在一起,通......
  • U3DFrameWorkDemo:二、资源管理
    代码参考代码文件参考下述详解的类图,工程参考第零章工程说明概述在游戏项目中有很多资产如:预制体,图片,音频,Lua脚本,Shader等等。他们随打包放在用户的硬盘里。在游戏的运行过程中,需要对这些资产加载和卸载,资源管理模块负责做这些事情。思路U3D会托管资产,也就是说资产一旦被加......
  • U3DFrameWorkDemo:零、工程说明
    序言前段时间拾起U3D时,重新看了一下之前的学习资料,整理成了一个demo。主要包含框架基本模块核心功能实现。当然,这个小demo是我个人的学习和探索,如demo的中文解释,它是一个“原型”--既是它的优点,也是它的缺点。它并不是一个完整的框架,但包含其核心功能模块的实现思路,简单直接(应用......
  • U3DFrameWorkDemo:一、生命周期管理
    代码参考见工程MgrBase、GameManager等代码文件,工程参考第零章工程说明概述在游戏的项目中,有一些APP中阶段的转换节点,如:进入App,登录,切地图等。通常有一些模块只在某个阶段被使用,比如:在玩家登录后启动玩家资产管理模块,玩家切地图清理(或刷新)地图资源管理模块等等。还要注意的是这......
  • thisDemo
    packagecom.thisDemo;publicclassStudent{doublescore;publicvoidprinThis(){System.out.println(this);}publicvoidprintPass(doublescore){if(this.score>score){System.out.println("成功");......
  • java——微服务——spring cloud——Eureka——插叙——服务访问——Demo——示例演示
                 user查询:             order订单查询:            user服务,查询user对象:            查询order对象:            ......