Publications by Ndungu Gakunga

Document

27.04.2024

set.seed(42) # for reproducibility n <- 500 # number of observations x <- runif(n, min=-2, max=2) # feature x, uniformly distributed between -2 and 2 noise <- rnorm(n, sd=0.2) # some noise to add to the y values # Define the quadratic decision boundary y_boundary <- x^2 + noise # Generate the second feature based on the decision bounda...

934 sym R (41409 sym/132 pcs) 6 img

Assignment 7

20.04.2024

# Load necessary library library(ggplot2) # Generating pm1 values from 0 to 1 pm1 <- seq(0, 1, by = 0.01) # Calculating Gini index, Classification error, and Entropy gini_index <- 2 * pm1 * (1 - pm1) classification_error <- 1 - pmax(pm1, 1 - pm1) entropy <- -pm1 * log2(pm1) - (1 - pm1) * log2(1 - pm1) # Replacing NaN with 0 for log(0) ca...

18302 sym R (38871 sym/46 pcs) 5 img

Document

12.04.2024

library(rsconnect) library(ISLR) # Load the ISLR library data("Wage") # Load the Wage dataset head("Wage") ## [1] "Wage" # Assuming you have already loaded the ISLR package and the Wage dataset # Display the first few rows of the dataset head(Wage) ## year age maritl race education region ## 231655 2006 ...

2986 sym R (15576 sym/49 pcs) 3 img

Assignment 5

23.03.2024

Less flexible and hence will give improved prediction accu- racy when its increase in bias is less than its decrease in variance. Less flexible and hence will give improved prediction accuracy when its increase in bias is less than its decrease in variance. More flexible and hence will give improved prediction accuracy when its increase in va...

1628 sym R (16323 sym/44 pcs) 3 img

Assignment 4

09.03.2024

Question 3 Divide the Dataset: Split your entire dataset into kk equally or nearly equally sized segments or folds. If the dataset is not inherently ordered, it is a good practice to shuffle the data before splitting to ensure randomness. Perform K Iterations: For each unique group: Use One Fold as the Test Set: Take one of the kk folds to be t...

3844 sym R (12330 sym/44 pcs)

Assignment 3

26.02.2024

# Load the necessary library library(readr) # Set the file path relative to the R Markdown file # Assuming "Weekly.csv" is in the same directory as your R Markdown file file_path <- "Weekly.csv" # Read the CSV file # Load the CSV file into a data frame weekly_data <- read.csv("C:/Users/ngaku/Downloads/Weekly.csv") # View the first few ro...

2711 sym R (33670 sym/108 pcs) 8 img