GithubHelp home page GithubHelp logo

dsc-testing-for-trends-lab-teacher-onboarding's Introduction

Testing for Trends - Lab

Introduction

In this lab, you'll practice your knowledge of testing for stationarity.

Objectives

You will be able to:

  • Use rolling statistics as a check for stationarity
  • Use the Dickey-Fuller test and conclude whether or not a dataset is exhibiting stationarity

Importing the data

Let's look at some new data. In this lab, we'll work with a time series in Python by using the popular Air Passengers dataset.

Start by running the cell below to import the necessary libraries.

# Import necessary libraries
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline

The dataset is stored in 'passengers.csv'. Import it and view the first five rows.

# Import 'passengers.csv'
data = None

# View the first five rows

Change the 'Month' column over to a datetime type and make sure it is set as the index of the DataFrame.

# Change the type of 'Month' to datetime


# Set 'Month' as the index
# Check the index

Now that we have successfully created a time series, we can use the .plot() method in pandas to visually inspect this time series.

# Plot the time series data 

Wec can see that that there is an overall increasing trend in the data along with some seasonal variations. However, it might not always be possible to make such visual inferences. Let's reconfirm this here using both rolling statistics and the Dickey-Fuller test.

Rolling Statistics

Use the .rolling() method to find the rolling mean and rolling std with a window of 12 months. Plot the original curve along with the rolling mean and standard error.

# Determine rolling statistics
# Plot rolling statistics

Though the variation in standard deviation is small, the mean is increasing with time and thus, this is not a stationary series.

Dickey-Fuller Test

Use the Dickey-Fuller test to verify your visual result.

from statsmodels.tsa.stattools import adfuller

Summary

In this lab, you checked for the stationarity of a time series in Python. Next, we'll further explore stationarity and how to make sure to make time series stationary!

dsc-testing-for-trends-lab-teacher-onboarding's People

Contributors

loredirick avatar sumedh10 avatar taylorhawks avatar

Watchers

James Cloos avatar Kevin McAlear avatar  avatar Mohawk Greene avatar Victoria Thevenot avatar Belinda Black avatar Bernard Mordan avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.