This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This post provides an overview of performing diagnostic and performance evaluation on logistic regression models in R. After training a statistical model, it’s important to understand how well that model did in regards to it’s accuracy and predictive power. The following content will provide the background and theory to ensure that the right technique are being utilized for evaluating logistic regression models in R. | |
| Logistic Regression Example | |
| We will use the GermanCredit dataset in the caret package for this example. It contains 62 characteristics and 1000 observations, with a target variable (Class) that is allready defined. The response variable is coded 0 for bad consumer and 1 for good. It’s always recommended that one looks at the coding of the response variable to ensure that it’s a factor variable that’s coded accurately with a 0/1 scheme or two factor levels in the right order. The first step is to partition the data into training and testing sets. | |
| ``` | |
| library(caret) | |
| data(GermanCredit) | |
| Train <- cr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Convert a list of vectors to a data frame. | |
| #' | |
| #' This function will convert a list of vectors to a data frame. This function | |
| #' will handle three different types of lists of vectors. First, if all the elements | |
| #' in the list are named vectors, the resulting data frame will have have a number | |
| #' of columns equal to the number of unique names across all vectors. In cases | |
| #' where some vectors do not have names in other vectors, those values will be | |
| #' filled with \code{NA}. | |
| #' | |
| #' The second case is when all the vectors are of the same length. In this case, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # script stolen from http://goo.gl/YbQyAQ | |
| # install.packages("tm") | |
| # install.packages("ggplot2") | |
| # install.packages("lsa") | |
| # install.packages("scatterplot3d") | |
| #install.packages("SnowballC") | |
| #if !(require('SnowballC')) then install.packages("SnowballC") | |
| library(tm) | |
| library(ggplot2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| makeCacheMatrix <- function( m = matrix() ) { | |
| ## Initialize the inverse property | |
| i <- NULL | |
| set <- function( matrix ) { | |
| m <<- matrix | |
| i <<- NULL | |
| } | |
| ## Method the get the matrix | |
| get <- function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| makeVector <- function(x = numeric()) { | |
| + m <- NULL | |
| + set <- function(y) { | |
| + x <<- y | |
| + m <<- NULL | |
| + } | |
| + get <- function() x | |
| + setmean <- function(mean) m <<- mean | |
| + getmean <- function() m | |
| + list(set = set, get = get, |