API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
应用程序接口(API:application programming interface)是一组定义、程序及协议的集合,通过 API 接口实现计算机软件之间的相互通信。API 的一个主要功能是提供通用功能集。程序员通过使用 API 函数开发应用程序,从而可以避免编写无用程序,以减轻编程任务。
本文章主要介绍数据挖掘之决策树的Web Service接口,详细描述决策树C50、CART的API使用方法。
1.接口参数说明
2.决策树方法API接口
API接口域名网址:
http://api.galaxystatistics.com
端口号:
8882 # 不同的接口,会使用不同的端口号
我相信程序员都是有节操的,不会恶意使用这个Key!
公共测试 ApiKey(token=xxxxxx): 098f6bcd4621d373cade4e832627b4f6
数据类型:
type=11 # 不同决策树方法的api接口,采用不同的type值【如:21、22、23】
输出变量名:
var_name=C50Method # 根据程序需求,自定义变量名称【如:C50Method、CARTMethod】
模型方法参数:
train_str # 训练集数据字符串
test_str # 测试集数据字符串
omethod # 回归树决策树方法选择【回归或分类】
模型方法参数举例:
# 训练集数据字符串
train_str = "5.1,3.5,1.4,0.2,A|4.9,3,1.4,0.2,A|5,3.6,1.4,0.2,A|4.7,3.2,1.6,0.2,A|5.4,3.4,1.5,0.4,A|5.5,3.5,1.3,0.2,A|4.4,3,1.3,0.2,A|5,3.5,1.3,0.3,A|4.5,2.3,1.3,0.3,A|4.4,3.2,1.3,0.2,A|5.1,3.8,1.6,0.2,A|7,3.2,4.7,1.4,B|6.4,3.2,4.5,1.5,B|6.9,3.1,4.9,1.5,B|5.5,2.3,4,1.3,B|5.2,2.7,3.9,1.4,B|6.1,2.9,4.7,1.4,B|5.6,2.9,3.6,1.3,B|5.8,2.7,4.1,1,B|6.2,2.2,4.5,1.5,B|5.9,3.2,4.8,1.8,B|5.5,2.4,3.7,1,B|5.8,2.7,3.9,1.2,B|5.4,3,4.5,1.5,B|6.7,3.1,4.7,1.5,B|5.6,3,4.1,1.3,B|5.7,3,4.2,1.2,B|6.3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