Book Image

Practical Data Science with Python

By : Nathan George
Book Image

Practical Data Science with Python

By: Nathan George

Overview of this book

Practical Data Science with Python teaches you core data science concepts, with real-world and realistic examples, and strengthens your grip on the basic as well as advanced principles of data preparation and storage, statistics, probability theory, machine learning, and Python programming, helping you build a solid foundation to gain proficiency in data science. The book starts with an overview of basic Python skills and then introduces foundational data science techniques, followed by a thorough explanation of the Python code needed to execute the techniques. You'll understand the code by working through the examples. The code has been broken down into small chunks (a few lines or a function at a time) to enable thorough discussion. As you progress, you will learn how to perform data analysis while exploring the functionalities of key data science Python packages, including pandas, SciPy, and scikit-learn. Finally, the book covers ethics and privacy concerns in data science and suggests resources for improving data science skills, as well as ways to stay up to date on new data science developments. By the end of the book, you should be able to comfortably use Python for basic data science projects and should have the skills to execute the data science process on any data source.
Table of Contents (30 chapters)
1
Part I - An Introduction and the Basics
4
Part II - Dealing with Data
10
Part III - Statistics for Data Science
13
Part IV - Machine Learning
21
Part V - Text Analysis and Reporting
24
Part VI - Wrapping Up
28
Other Books You May Enjoy
29
Index

Forecasting

Another use of regression is for forecasting. For example, we can forecast future values in a time series like security prices, the weather, sales, or web traffic data. Let's use our daily bitcoin price data from Chapter 4, Loading and Wrangling Data with Pandas and NumPy as an example:

btc_df = pd.read_csv('data/bitcoin_price.csv')
btc_df['time'] = pd.to_datetime(btc_df['time'], unit='ms')
btc_df.set_index('time', inplace=True)
btc_df = btc_df[['close', 'volume']]

We load the data and only keep the closing price and volume. We are also setting the time column as the index after parsing it to a datetime. The units for the time column are milliseconds since the epoch.

To create a target column with future closing price data, we can use a pandas function:

btc_df['close_1d_future'] = btc_df['close'].shift(-1)
btc_df.dropna(inplace=True)

The shift function...