定制 medansoftware/c45-algorithm-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

medansoftware/c45-algorithm-php

Composer 安装命令:

composer require medansoftware/c45-algorithm-php

包简介

README 文档

README

Use Example File

Installation

The recommended way to install the C45 PHP library is through Composer :

composer require medansoftware/c45-algorithm-php

Manual Installation

composer dump-autoload

Setup

$c45 = new Algorithm\C45('example.xlsx', 'PLAY');
$initialize = $c45->initialize(); // initialize
$buildTree = $initialize->buildTree(); // build tree

$arrayTree = $buildTree->toArray(); // set to array
$stringTree = $buildTree->toString(); // set to string

echo "<pre>";
print_r ($arrayTree);
echo "</pre>";

echo $stringTree;

or

$c45 = new Algorithm\C45();
$c45->loadFile('example.xlsx'); // load example file
$c45->setTargetAttribute('PLAY'); // set target attribute

$initialize = $c45->initialize(); // initialize
$buildTree = $initialize->buildTree(); // build tree

$arrayTree = $buildTree->toArray(); // set to array
$stringTree = $buildTree->toString(); // set to string

echo "<pre>";
print_r ($arrayTree);
echo "</pre>";

echo $stringTree;

Other Examples

$c45 = new Algorithm\C45();
$c45->loadFile('example.xlsx')->setTargetAttribute('PLAY')->initialize();

echo "<pre>";
print_r ($c45->buildTree()->toString()); // print as string
echo "</pre>";

echo "<pre>";
print_r ($c45->buildTree()->toJson()); // print as JSON
echo "</pre>";

echo "<pre>";
print_r ($c45->buildTree()->toArray()); // print as array
echo "</pre>";

Initialize Data from Array

$c45 = new Algorithm\C45();
$input = new Algorithm\C45\DataInput;
$data = array(
	array(
		"OUTLOOK" => "Sunny",
		"TEMPERATURE" => "Hot",
		"HUMIDITY" => "High",
		"WINDY" => "False",
		"PLAY" => "No"
	),
	array(
		"OUTLOOK" => "Sunny",
		"TEMPERATURE" => "Hot",
		"HUMIDITY" => "High",
		"WINDY" => "True",
		"PLAY" => "No"
	),
	array(
		"OUTLOOK" => "Cloudy",
		"TEMPERATURE" => "Hot",
		"HUMIDITY" => "High",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Rainy",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "High",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Rainy",
		"TEMPERATURE" => "Cool",
		"HUMIDITY" => "Normal",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Rainy",
		"TEMPERATURE" => "Cool",
		"HUMIDITY" => "Normal",
		"WINDY" => "True",
		"PLAY" => "No"
	),
	array(
		"OUTLOOK" => "Cloudy",
		"TEMPERATURE" => "Cool",
		"HUMIDITY" => "Normal",
		"WINDY" => "True",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Sunny",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "High",
		"WINDY" => "False",
		"PLAY" => "No"
	),
	array(
		"OUTLOOK" => "Sunny",
		"TEMPERATURE" => "Cool",
		"HUMIDITY" => "Normal",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Rainy",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "Normal",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Sunny",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "Normal",
		"WINDY" => "True",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Cloudy",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "High",
		"WINDY" => "True",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Cloudy",
		"TEMPERATURE" => "Hot",
		"HUMIDITY" => "Normal",
		"WINDY" => "False",
		"PLAY" => "Yes"
	),
	array(
		"OUTLOOK" => "Rainy",
		"TEMPERATURE" => "Mild",
		"HUMIDITY" => "High",
		"WINDY" => "True",
		"PLAY" => "No"
	)
);

// Initialize Data
$input->setData($data); // Set data from array
$input->setAttributes(array('OUTLOOK', 'TEMPERATURE', 'HUMIDITY', 'WINDY', 'PLAY')); // Set attributes of data

// Initialize C4.5
$c45->c45 = $input; // Set input data
$c45->setTargetAttribute('PLAY'); // Set target attribute
$initialize = $c45->initialize(); // initialize

// Build Output
$buildTree = $initialize->buildTree(); // Build tree
$arrayTree = $buildTree->toArray(); // Set to array
$stringTree = $buildTree->toString(); // Set to string

echo "<pre>";
print_r ($arrayTree);
echo "</pre>";

echo $stringTree;
$new_data = array(
	'OUTLOOK' => 'Sunny',
	'TEMPERATURE' => 'Hot',
	'HUMIDITY' => 'High',
	'WINDY' => FALSE
);

echo $c45->initialize()->buildTree()->classify($new_data); // print "No"

Refrence

Made with ❤️ + ☕ ~ Agung Dirgantara

统计信息

  • 总下载量: 292
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固