Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Decision Tree: Creating a Decision Tree Using R and the party Package, Assignments of Computer Science

A decision tree is a graphical representation of choices and their results, used primarily in machine learning and data mining applications. In this example, we demonstrate how to create a decision tree using r and the party package. We will use the ctree() function to build the tree and visualize it.

What you will learn

  • What is a decision tree and how is it used?
  • What data is required to create a decision tree using the ctree() function?
  • How can the ctree() function be used to create a decision tree in R?

Typology: Assignments

2019/2020

Uploaded on 06/04/2020

murugan-s
murugan-s 🇮🇳

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DECISION TREE
Decision tree is a graph to represent choices and their
results in form of a tree. The nodes in the graph
represent an event or choice and the edges of the graph
represent the decision rules or conditions. It is mostly
used in Machine Learning and Data Mining applications
using R.
We will use the ctree() function to create the decision
tree and see its graph.
# Load the party package. It will
automatically load other
# dependent packages.
library(party)
# Create the input data frame.
input.dat <- readingSkills[c(1:105),]
# Give the chart file a name.
png(file = "decision_tree.png")
# Create the tree.
output.tree <- ctree(
nativeSpeaker ~ age + shoeSize + score,
data = input.dat)
# Plot the tree.
plot(output.tree)
# Save the file.
dev.off()
pf2

Partial preview of the text

Download Decision Tree: Creating a Decision Tree Using R and the party Package and more Assignments Computer Science in PDF only on Docsity!

DECISION TREE

Decision tree is a graph to represent choices and their

results in form of a tree. The nodes in the graph

represent an event or choice and the edges of the graph

represent the decision rules or conditions. It is mostly

used in Machine Learning and Data Mining applications

using R.

We will use the ctree() function to create the decision

tree and see its graph.

Load the party package. It will

automatically load other

dependent packages.

library(party)

Create the input data frame.

input.dat <- readingSkills[c( 1 : 105 ),]

Give the chart file a name.

png(file = "decision_tree.png")

Create the tree.

output.tree <- ctree( nativeSpeaker ~ age + shoeSize + score, data = input.dat)

Plot the tree.

plot(output.tree)

Save the file.

dev.off()

When we execute the above code, it produces the

following result –

null device 1 Loading required package: methods Loading required package: grid Loading required package: mvtnorm Loading required package: modeltools Loading required package: stats Loading required package: strucchange Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich

BY,

N. HARISMITA

16MSS