mit-lcp / bst209 Goto Github PK
View Code? Open in Web Editor NEWCourse materials for BST209
License: MIT License
Course materials for BST209
License: MIT License
There are some inconsistencies in the way folders and files are named, so we should do a quick clean up. We need to be a bit careful when we do this to avoid confusing everyone.
Capitalization is treated differently by different operating systems, which can lead to confusing errors (e.g. a chunk of code works for one person, but not for another). To make things easier, we could convert filenames and foldernames to lowercase.
Description:
Currently, there is a limitation in R packages for tree models that prevent the extraction of decision boundaries for individual trees. Unlike Python packages, which allow for easy extraction of decision boundaries, R lacks this functionality. Additionally, there is no existing package in R specifically designed to visualize decision boundaries.
What I have trouble reproducing is a decision boundary plot for individual tress as can be seen here:
https://carpentries-incubator.github.io/machine-learning-trees-python/06-random-forest/index.html
Current Behavior:
In R I am currently only able to visualize decision boundaries for the entire model. Here users are required to manually create decision boundary plots using the ggplot2 package and other relevant packages. The process involves generating a grid of points, predicting the class labels for those points, and then plotting the points with appropriate fill colors to represent the predicted classes. An example can be seen here:
library(ggplot2)
library(gridExtra)
library(rpart)
library(rpart.plot)
# Generate grid of points
grid <- expand.grid(age = seq(min(train_df$age), max(train_df$age), length.out = 100),
acutephysiologyscore = seq(min(train_df$acutephysiologyscore), max(train_df$acutephysiologyscore), length.out = 100))
# Predict class label for each point in the grid
grid$prediction <- predict(mdl, newdata = grid, type = "class")
# Create decision boundary plot
decision_boundary_plot <- ggplot(grid, aes(x = age, y = acutephysiologyscore, fill = prediction)) +
geom_point() +
geom_tile() +
scale_color_manual(values = c("blue", "red")) +
labs(title = "Decision Boundary",
x = "Age",
y = "Acute Physiology Score",
fill = "Predicted Class") +
theme_classic()
decision_boundary_plot
Desired Enhancement:
It would be beneficial to have an R package that provides a function to easily extract decision boundaries for tree models since this would greatly simplify the process of creating decision boundary plots, eliminating the need for manual implementation using ggplot2 or other general-purpose plotting libraries. Additionally, a dedicated package for visualizing decision boundaries within the individual trees would be beneficial but seems very cumbersome.
In the machine-learning-novice
There is a discrepancy between how we train a model with the data:
reg <- glm(y_train ~ ., data = data.frame(cbind(X_train, y_train)), family = binomial())
model <- glm(actualhospitalmortality ~ apachescore , data = train, family = "binomial")
reg <- glm(as.factor(y_train) ~ x_train, family = binomial())
I suggest we all create a train and test data frame like this:
train_df = cbind(x_train, y_train)
test_df = cbind(x_test, y_test)
And all train the models where we have the variable names within the model: model <- glm(actualhospitalmortality ~ apachescore , data = train_df, family = "binomial")
In this way we are consistent and the formula is also just easier to understand. Also the train_df and test_df are now in the "Data" folder, which can be directly accessed for training.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.