Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Slicing time-series data


Now that we know how to handle time-series data, let's see how we can slice it. The process of slicing refers to dividing the data into various sub-intervals and extracting relevant information. This is very useful when you are working with time-series datasets. Instead of using indices, we will use timestamp to slice our data.

Create a new Python file and import the following packages:

import numpy as np 
import matplotlib.pyplot as plt 
import pandas as pd 
 
from timeseries import read_data 

Load the third column (zero-indexed) from the input data file:

# Load input data 
index = 2 
data = read_data('data_2D.txt', index) 

Define the start and end years, and then plot the data with year-level granularity:

# Plot data with year-level granularity  
start = '2003' 
end = '2011' 
plt.figure() 
data[start:end].plot() 
plt.title('Input data from ' + start + ' to ' + end) 

Define the start and end months...