install.packages("shiny")
install.packages("learnr")
dim(churn)
summary(churn)
churn <- read.csv("./churn.csv", stringAsFactors = TRUE)
dim(churn)
summary(churn)
churn <- read.csv("./churn.csv", stringAsFactors = TRUE)
churn <- read.csv("churn.csv", stringAsFactors = TRUE)
churn <- read.csv("churn.csv")
dim(churn)
summary(churn)
table(churn$Churn)
pop.churn -> sum(churn$Churn == "TRUE") / length(churn$Churn)
pop.churn
barplot(sum.churn, ylim = c(0, 3000, ylab = "Counts", main = "bar plot", col = "lightblue"))
table(churn$Churn)
pop.churn <- sum(churn$Churn == "TRUE") / length(churn$Churn)
pop.churn
sum.churn <- table(churn$Churn)
sum.churn
barplot(sum.churn, ylim = c(0, 3000, ylab = "Counts", main = "bar plot", col = "lightblue"))
)
churn <- read.csv("churn.csv")
dim(churn)
summary(churn)
table(churn$Churn)
pop.churn <- sum(churn$Churn == "TRUE") / length(churn$Churn)
pop.churn
sum.churn <- table(churn$Churn)
sum.churn
barplot(sum.churn, ylim = c(0, 3000), ylab = "Counts", main = "bar plot", col = "lightblue")
sumtable <-  addmargins(counts.intl, FUN = sum)
sumtable <-  addmargins(counts.int1, FUN = sum)
sumtable <-  addmargins(counts.intl, FUN = sum)
sumtable <- addmargins(counts.intl, FUN = sum)
sumtable <-  addmargins(counts.intl, FUN = sum)
sumtable
sumtable <-  addmargins(Counts.intl, FUN = sum)
sumtable <- addmargins(counts.Intl, FUN = sum)
mode
sd(stock_prices)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
outlier_z_score <- stock_prices[abs(z_score) > 3]
IQR_value <- IQR(stock_prices)
Q1 <- quantile(stock_prices, 0.25)
Q3 <- quantile(stock_prices, 0.75)
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
outliers_iqr <- stock_prices[stock_prices < lower_bound | stock_prices > upper_bound]
stock_prices_no_outlier <- stock_prices[stock_prices != 75]
# Mean and Median with and without the outlier
mean_with <- mean(stock_prices)
median_with <- median(stock_prices)
mean_without <- mean(stock_prices_no_outlier)
median_without <- median(stock_prices_no_outlier)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
outlier_z_score <- stock_prices[abs(z_score) > 3]
IQR_value <- IQR(stock_prices)
print(outlier_z_score)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
outlier_z_score <- stock_prices[abs(z_score) > 3]
print(outlier_z_score)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
outlier_z_score <- stock_prices[abs(z_score) > 3]
IQR_value <- IQR(stock_prices)
Q1 <- quantile(stock_prices, 0.25)
Q3 <- quantile(stock_prices, 0.75)
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
outliers_iqr <- stock_prices[stock_prices < lower_bound | stock_prices > upper_bound]
stock_prices_no_outlier <- stock_prices[stock_prices != 75]
# Mean and Median with and without the outlier
mean_with <- mean(stock_prices)
median_with <- median(stock_prices)
mean_without <- mean(stock_prices_no_outlier)
median_without <- median(stock_prices_no_outlier)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
# Calculate Z-scores for all stock prices
z_scores <- (stock_prices - mean(stock_prices)) / sd(stock_prices)
# Identify outliers based on Z-scores
outlier_z_scores <- stock_prices[abs(z_scores) > 3]
# Print identified outliers based on Z-scores
print(outlier_z_scores)
IQR_value <- IQR(stock_prices)
Q1 <- quantile(stock_prices, 0.25)
Q3 <- quantile(stock_prices, 0.75)
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
outliers_iqr <- stock_prices[stock_prices < lower_bound | stock_prices > upper_bound]
# Display the outliers_iqr in the term for screenshot / lab purposes
print(outliers_iqr)
stock_prices <- c(10, 7, 20, 12, 75, 15, 9, 18, 4, 12, 8, 14)
# Mean
mean(stock_prices)
# median
median(stock_prices)
# Mode
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode <- getmode(stock_prices)
mode
sd(stock_prices)
# min-max
normalized <- (20 - min(stock_prices)) / (max(stock_prices) - min(stock_prices))
normalized
z_score <- (20 - mean(stock_prices)) / sd(stock_prices)
z_score
# 7
# Calculate the Z-score for 75
z_score_75 <- (75 - mean(stock_prices)) / sd(stock_prices)
# Check if Z-score is greater than 3 or less than -3 (common criteria for outliers)
is_outlier_z_score <- abs(z_score_75) > 3
print(is_outlier_z_score)
# Calculate the Interquartile Range (IQR)
IQR_value <- IQR(stock_prices)
Q1 <- quantile(stock_prices, 0.25)
Q3 <- quantile(stock_prices, 0.75)
# Determine the lower and upper bounds for outliers
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
# Check if 75 is outside the bounds
is_outlier_iqr <- 75 < lower_bound | 75 > upper_bound
print(is_outlier_iqr)
# 8
# Calculate Z-scores for all stock prices
z_scores <- (stock_prices - mean(stock_prices)) / sd(stock_prices)
# Identify outliers based on Z-scores
outlier_z_scores <- stock_prices[abs(z_scores) > 3]
# Print identified outliers based on Z-scores
print(outlier_z_scores)
# we already Calculated the upper and lower bound as well as Q1 and Q3
outliers_iqr <- stock_prices[stock_prices < lower_bound | stock_prices > upper_bound]
# Display the outliers_iqr in the term for screenshot / lab purposes
print(outliers_iqr)
stock_prices_no_outlier <- stock_prices[stock_prices != 75]
# Mean and Median with and without the outlier
mean_with <- mean(stock_prices)
median_with <- median(stock_prices)
mean_without <- mean(stock_prices_no_outlier)
median_without <- median(stock_prices_no_outlier)
print(mean_with)
print(median_with)
print(mean_without)
print(median_without)
