Book Image

Data Science Algorithms in a Week - Second Edition

By : David Natingga
Book Image

Data Science Algorithms in a Week - Second Edition

By: David Natingga

Overview of this book

Machine learning applications are highly automated and self-modifying, and continue to improve over time with minimal human intervention, as they learn from the trained data. To address the complex nature of various real-world data problems, specialized machine learning algorithms have been developed. Through algorithmic and statistical analysis, these models can be leveraged to gain new knowledge from existing data as well. Data Science Algorithms in a Week addresses all problems related to accurate and efficient data classification and prediction. Over the course of seven days, you will be introduced to seven algorithms, along with exercises that will help you understand different aspects of machine learning. You will see how to pre-cluster your data to optimize and classify it for large datasets. This book also guides you in predicting data based on existing trends in your dataset. This book covers algorithms such as k-nearest neighbors, Naive Bayes, decision trees, random forest, k-means, regression, and time-series analysis. By the end of this book, you will understand how to choose machine learning algorithms for clustering, classification, and regression and know which is best suited for your problem
Table of Contents (16 chapters)
Title Page
Packt Upsell
Contributors
Preface
Glossary of Algorithms and Methods in Data Science
Index

Business profits – analyzing trends


We are interested in predicting the profits of a business for the year 2018 given its profits for previous years:

Year

Profit in USD

2011

$40,000

2012

$43,000

2013

$45,000

2014

$50,000

2015

$54,000

2016

$57,000

2017

$59,000

2018

?

 

Analysis

In this example, the profit is always increasing, so we can think of representing the profit as a growing function that's dependent on the time variable, which is represented by years. The variations in profit between the subsequent years are $3,000, $2,000, $5,000, $4,000, $3,000, and $2,000. These differences do not seem to be affected by time, and the variation between them is relatively low. Therefore, we may try to predict the profit for the coming years by performing linear regression. We express profit, p, in terms of the year, y, in a linear equation, also called a trend line:

We can find the constants, a and b, using linear regression.

Analyzing trends using the least squares method in Python

Input:

We store the data from the preceding...