Giter VIP home page Giter VIP logo

id3-decision-tree-algorithm's Introduction

ID3 Decision Tree Algorithm Implementation in Java

Overview

This repository contains a Java implementation of the ID3 (Iterative Dichotomiser 3) algorithm, a popular method used in machine learning for creating decision trees. The implementation is designed to build a decision tree based on a dataset for classification purposes.

Features

  • Tree Construction: Constructs a decision tree from a given dataset.
  • Entropy Calculation: Computes entropy to measure the purity of a subset.
  • Information Gain: Uses information gain to select the best attribute for node splitting.
  • Tree Pruning: Optional functionality to prevent overfitting by pruning the tree.
  • Prediction & Accuracy: Utilizes the constructed tree to make predictions and calculates the accuracy based on test data.

Class Structure

  • Node: Represents a node in the decision tree with attributes like state, atribut, parent, childNode, and children.
  • Id3: Main class for the ID3 algorithm implementation, containing methods for tree construction, prediction, and accuracy calculation.

Usage

To use this implementation, provide a dataset in a CSV format. The dataset should be split into training and test data. The program will build a decision tree based on the training data and then use the tree to make predictions on the test data.

Example

A simple example of using this implementation:

Id3 id3Algorithm = new Id3();
id3Algorithm.readCSV("path/to/training/data.csv", "path/to/test/data.csv");
id3Algorithm.id3();
System.out.println("Decision Tree Constructed.");

Output for volleyball_test.csv

IG(weather) 0.2467498197744391
IG(temperature) 0.029222565658954647
IG(humidity) 0.15183550136234136
IG(wind) 0.04812703040826927
weather
IG(weather) 0.0
IG(temperature) 0.01997309402197489
IG(humidity) 0.01997309402197489
IG(wind) 0.9709505944546686
wind
IG(weather) 0.0
IG(temperature) 0.5709505944546686
IG(humidity) 0.9709505944546686
IG(wind) 0.01997309402197489
humidity
null 0
cloudy 1
rainy 1
sunny 1
strong 2
weak 2
normal 2
high 2
[BRANCHES]:
1:weather=cloudy yes
1:weather=rainy 2:wind=strong no
1:weather=rainy 2:wind=weak yes
1:weather=sunny 2:humidity=normal yes
1:weather=sunny 2:humidity=high no
[PREDICTIONS]: yes yes yes yes no yes yes yes no yes yes no yes no no yes yes yes yes 
[ACCURACY]: 0.57895
[CONFUSION_MATRIX]:
4 7
1 7

id3-decision-tree-algorithm's People

Contributors

janb1701 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.