Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 307 additions & 0 deletions your-code/.ipynb_checkpoints/main-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Before your start:\n",
"- Read the README.md file\n",
"- Comment as much as you can and use the resources (README.md file)\n",
"- Happy learning!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import numpy and pandas\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge 1 - Loading and Evaluating The Data\n",
"\n",
"In this lab, we will look at a dataset of sensor data from a cellular phone. The phone was carried in the subject's pocket for a few minutes while they walked around.\n",
"\n",
"To load the data, run the code below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run this code:\n",
"\n",
"sensor = pd.read_csv('../sub_1.csv')\n",
"sensor.drop(columns=['Unnamed: 0'], inplace=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Examine the data using the `head` function."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check whether there is any missing data. If there is any missing data, remove the rows containing missing data."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How many rows and columns are in our data?"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To perform time series analysis on the data, we must change the index from a range index to a time series index. In the cell below, create a time series index using the `pd.date_range` function. Create a time series index starting at 1/1/2018 00:00:00 and ending at 1/1/2018 00:29:10. The number of periods is equal to the number of rows in `sensor`. The frequency should be set to `infer`."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Assign the time series index to the dataframe's index."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Our next step is to decompose the time series and evaluate the patterns in the data. Load the `statsmodels.api` submodule and plot the decomposed plot of `userAcceleration.x`. Set `freq=60` in the `seasonal_decompose` function. Your graph should look like the one below.\n",
"\n",
"![time series decomposition](../images/tsa_decompose.png)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the decomposed time series of `rotationRate.x` also with a frequency of 60."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge 2 - Modelling the Data\n",
"\n",
"To model our data, we should look at a few assumptions. First, let's plot the `lag_plot` to detect any autocorrelation. Do this for `userAcceleration.x`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a lag plot for `rotationRate.x`"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What are your conclusions from both visualizations?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Your conclusions here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next step will be to test both variables for stationarity. Perform the Augmented Dickey Fuller test on both variables below."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What are your conclusions from this test?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Your conclusions here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we'll create an ARMA model for `userAcceleration.x`. Load the `ARMA` function from `statsmodels`. The order of the model is (2, 1). Split the data to train and test. Use the last 10 observations as the test set and all other observations as the training set. "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To compare our predictions with the observed data, we can compute the RMSE (Root Mean Squared Error) from the submodule `statsmodels.tools.eval_measures`. You can read more about this function [here](https://www.statsmodels.org/dev/generated/statsmodels.tools.eval_measures.rmse.html). Compute the RMSE for the last 10 rows of the data by comparing the observed and predicted data for the `userAcceleration.x` column."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading