- Credit Risk Modelling - Case Studies
- Classification vs. Regression Models
- Case Study - German Credit - Steps to Build a Predictive Model
- Import Credit Data Set in R
- German Credit Data : Data Preprocessing and Feature Selection in R
- Credit Modelling: Training and Test Data Sets
- Build the Predictive Model
- Logistic Regression Model in R
- Measure Model Performance in R Using ROCR Package
- Create a Confusion Matrix in R
- Credit Risk Modelling - Case Study- Lending Club Data
- Explore Loan Data in R - Loan Grade and Interest Rate
- Credit Risk Modelling - Required R Packages
- Loan Data - Training and Test Data Sets
- Data Cleaning in R - Part 1
- Data Cleaning in R - Part 2
- Data Cleaning in R - Part 3
- Data Cleaning in R - Part 5
- Remove Dimensions By Fitting Logistic Regression
- Create a Function and Prepare Test Data in R
- Building Credit Risk Model
- Credit Risk - Logistic Regression Model in R
- Support Vector Machine (SVM) Model in R
- Random Forest Model in R
- Extreme Gradient Boosting in R
- Predictive Modelling: Averaging Results from Multiple Models
- Predictive Modelling: Comparing Model Results
- How Insurance Companies Calculate Risk

# Data Cleaning in R - Part 2

### Attributes with Zero Variance

Datasets can sometimes contain attributes (predictors) that have near-zero variance, or may have just one value. Such variables are considered to have less predictor power. Apart from being uninformative, these predictors may also sometimes break the model that you are trying to fit to your data. This can occur, for example, due to division by zero (if a standardization is performed in the data).

One quick solution is to remove all predictors that satisfy some threshold criterion related to their variance.

In our dataset, we will look for predictors that have zero variance and will remove them.

We will first define some generic functions that we will use later.

```
# Returns the Numeric columns from a dataset
getNumericColumns<-function(t){
tn = sapply(t,function(x){is.numeric(x)})
return(names(tn)[which(tn)])
}
```

```
# Returns the character columns from a dataset
getCharColumns<-function(t){
tn = sapply(t,function(x){is.character(x)})
return(names(tn)[which(tn)])
}
```

```
# Returns the factor columns in a dataset
getFactorColumns<-function(t){
tn = sapply(t,function(x){is.factor(x)})
return(names(tn)[which(tn)])
}
```

```
# Returns index of columns along with the column names
getIndexsOfColumns <- function(t,column_names){
return(match(column_names,colnames(t)))
}
```

# This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.