chapter eight

8 Machine learning

 

In this chapter

  • Solving problems with machine learning algorithms
  • Grasping a machine learning life cycle, preparing data, and selecting algorithms
  • Understanding and implementing a linear regression algorithm for predictions
  • Understanding and implementing a decision-tree learning algorithm for classification

What is machine learning?

Machine learning can seem like a daunting concept to learn and apply, but with the right framing and understanding of the process and algorithms, it can be interesting and fun. Suppose that you’re looking for a new apartment. You speak to friends and family members and do some online searches for apartments in the city. You notice that apartments in different areas are priced differently. Here are some of your observations from all your research:

  • A one-bedroom apartment in the city center (close to work) costs $5,000 per month.
  • A two-bedroom apartment in the city center costs $7,000 per month.
  • A one-bedroom apartment in the city center with a garage costs $6,000 per month.
  • A one-bedroom apartment outside the city center, from which you’ll have to commute to work, costs $3,000 per month.
  • A two-bedroom apartment outside the city center costs $4,500 per month.
  • A one-bedroom apartment outside the city center with a garage costs $3,800 per month.

Problems that machine learning can solve

Supervised learning

Unsupervised learning

Reinforcement learning

Following a machine-learning workflow

Collecting and understanding data

Preparing data: Clean and wrangle

Encoding categorical data

Testing and training data

Training a model: Predict with linear regression