From e8f826976a5b99901aa5d37d51454705c7c7c666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Ramnel=C3=B6v?= <felra653@student.liu.se> Date: Tue, 3 Dec 2024 11:15:07 +0100 Subject: [PATCH] Lab 2: Added plot for tree structure and recall-precision-curve --- lab2/assignment2.R | 47 ++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lab2/assignment2.R b/lab2/assignment2.R index f965392..0cd21f7 100644 --- a/lab2/assignment2.R +++ b/lab2/assignment2.R @@ -102,6 +102,9 @@ optimal_tree <- prune.tree(fit2c, best = optimal_leaves) summary(optimal_tree) +plot(optimal_tree) +text(optimal_tree, pretty=0) + # ----4.---- TP <- function(x, x_pred) { @@ -237,25 +240,25 @@ legend( pch = c(16, 1) ) -# plot( -# logistic_recall, -# logistic_precision, -# type = "b", -# ylim = c(0, 1), -# xlim = c(0, 1), -# col = "red", -# main = "Precision depending on recall", -# xlab = "Recall", -# ylab = "Precision", -# pch = 16, -# ) -# points(tree_recall, -# tree_precision, -# col = "blue", -# type = "b") -# legend( -# "bottomleft", -# legend = c("Logistic regression model", "Optimal tree"), -# fill = c("red", "blue"), -# pch = c(16, 1) -# ) \ No newline at end of file +plot( + logistic_recall, + logistic_precision, + type = "b", + ylim = c(0, 1), + xlim = c(0, 1), + col = "red", + main = "Precision depending on recall", + xlab = "Recall", + ylab = "Precision", + pch = 16, +) +points(tree_recall, + tree_precision, + col = "blue", + type = "b") +legend( + "bottomleft", + legend = c("Logistic regression model", "Optimal tree"), + fill = c("red", "blue"), + pch = c(16, 1) +) \ No newline at end of file -- GitLab