Week14 - LAQs - SWR
Week14 - LAQs - SWR
Decision trees are supervised machine learning models used for classification and
regression tasks. They work by splitting data into branches based on feature values,
forming a tree-like structure. Decision trees are simple, interpretable, and widely used in
data analysis.
library(rpart)
library(rpart.plot)
library(caret)
Dataset: iris
4. Making Predictions
predictions <- predict(tree_model, test_data, type="class")
head(predictions)
Confusion Matrix
conf_matrix <- confusionMatrix(predictions, test_data$Species)
print(conf_matrix)
✅ Advantages
Easy to interpret
Requires little data preprocessing
Works with both numerical and categorical data
❌ Disadvantages
Prone to overfitting
Sensitive to small data variations
Can create biased splits with imbalanced datasets