cs-decision-tree
1.0.1
dotnet add package cs-decision-tree --version 1.0.1
NuGet\Install-Package cs-decision-tree -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="cs-decision-tree" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add cs-decision-tree --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: cs-decision-tree, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install cs-decision-tree as a Cake Addin #addin nuget:?package=cs-decision-tree&version=1.0.1 // Install cs-decision-tree as a Cake Tool #tool nuget:?package=cs-decision-tree&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
cs-decision-tree
Decision Trees (ID3, C45) implemented in C#
Install
Run the following nuget command:
Install-Package cs-decision-tree
Usage
The sample codes below shows how to use ID3 and C45 to do classification:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DecisionTree.Demo
{
using System.Xml;
using System.IO;
using DecisionTree;
using Lang;
public class DecisionTreeTest
{
public static List<DDataRecord> LoadSample()
{
XmlDocument doc = new XmlDocument();
doc.Load("database.xml");
List<DDataRecord> records = new List<DDataRecord>();
XmlElement xml_root = doc.DocumentElement;
foreach (XmlElement xml_level1 in xml_root.ChildNodes)
{
if (xml_level1.Name == "record")
{
String outlook = xml_level1.Attributes["outlook"].Value;
string temperature = xml_level1.Attributes["temperature"].Value;
string humidity = xml_level1.Attributes["humidity"].Value;
String windy = xml_level1.Attributes["windy"].Value;
String class_label = xml_level1.Attributes["class"].Value;
DDataRecord rec = new DDataRecord();
rec["outlook"]=outlook;
rec["windy"]=windy;
rec["temperature"]=temperature;
rec["humidity"]=humidity;
rec.Label = class_label;
records.Add(rec);
}
}
return records;
}
public static void RunC45()
{
List<DDataRecord> records = LoadSample();
C45<DDataRecord> algorithm = new C45<DDataRecord>();
algorithm.UpdateContinuousAttributes(records, "temperature");
algorithm.UpdateContinuousAttributes(records, "humidity");
algorithm.Train(records);
//algorithm.RulePostPrune(records); //post pruning using cross valiation set
Console.WriteLine("C4.5 Tree Built!");
for(int i=0; i<records.Count; i++)
{
DDataRecord rec=records[i];
Console.WriteLine("rec: ");
string[] feature_names = rec.FindFeatures();
foreach(string feature_name in feature_names)
{
Console.WriteLine(feature_name+" = " + rec[feature_name]);
}
Console.WriteLine("Label: " + rec.Label);
Console.WriteLine("Predicted Label: " + algorithm.Predict(records[i]));
Console.WriteLine();
}
}
public static void RunID3()
{
List<DDataRecord> X = LoadSample();
//As ID3 does not support continuous value, must do manually conversion
foreach (DDataRecord rec in X)
{
int temperature = int.Parse(rec["temperature"]);
int humidity = int.Parse(rec["humidity"]);
if (temperature < 75)
{
rec["temperature"]="< 75";
}
else
{
rec["temperature"]=">= 75";
}
if (humidity < 80)
{
rec["humidity"]="< 80";
}
else
{
rec["humidity"]=">= 80";
}
}
ID3<DDataRecord> algorithm = new ID3<DDataRecord>();
algorithm.Train(X);
//algorithm.ErrorReducePrune(Xval); //error reduce prune using cross valiation set
Console.WriteLine("ID3 Tree Built!");
for (int i = 0; i < X.Count; i++)
{
DDataRecord rec = X[i];
Console.WriteLine("rec: ");
string[] feature_names = rec.FindFeatures();
foreach(string feature_name in feature_names)
{
Console.WriteLine(feature_name + " = " + rec[feature_name]);
}
Console.WriteLine("Label: " + rec.Label);
Console.WriteLine("Predicted Label: " + algorithm.Predict(X[i]));
Console.WriteLine();
}
algorithm.WriteToXml("ID3.xml");
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 1,332 | 4/29/2018 |
Decision Trees ID3 and C45 in .NET 4.6.1