How to visualise regression analysis in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to visualise regression analysis in R?

This recipe helps you to visualise a regression analysis in R using ggplot()

3

This recipe uses the ggplot () package in R to visualize the output of a regression analysis. This visualization combines a regression line with confidence intervals and prediction intervals.

What is Regression Analysis ?
Regression analysis is a statistical technique used to find the relationship between 2 or more variables. It is used in business to understand what factors impact a specific outcome. Regression allows you to determine which factors matter most, which factors can be ignored, and how these factors influence each other. In order to conduct a regression analysis, you'll need to define a dependent variable that you hypothesize is being influenced by one or several independent variables.

What is R ?
R is a programming language used for statistics and data science computing. R has very powerful libraries (almost 12,000) for performing data analytics including regression, classification, visualisation etc.

In [ ]:
```# --------------------------------------------------------------
# Regression Analysis in R - How to visualise predict() function
# --------------------------------------------------------------
library(mlbench)
library(gridExtra)
library(ggpubr)

# Visualise prediction with CI and PI
# 1. Build linear model
data("cars", package = "datasets")
model <- lm(dist ~ speed, data = cars)

pred.int <- predict(model, interval = "prediction")
mydata <- cbind(cars, pred.int)

# 3. Regression line + confidence intervals
library("ggplot2")
p1 <- ggplot(mydata, aes(speed, dist)) +
geom_point() +
stat_smooth(method = lm)

p2 <- p1 + geom_line(aes(y = lwr), color = "red", linetype = "dashed")+
geom_line(aes(y = upr), color = "red", linetype = "dashed")
# plot
grid.arrange(p1,p2, nrow=1)
```

#### Relevant Projects

##### Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

##### Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

##### Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

##### Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

##### Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

##### Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

##### Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

##### Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

##### Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

##### Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.