4. An Introduction to Decision Trees
Activity 4.01: Car Data Classification
Solution:
- Open a new Jupyter Notebook file.
- Import the
pandas
package aspd
:import pandas as pd
- Create a new variable called
file_url
that will contain the URL to the raw dataset:file_url = 'https://raw.githubusercontent.com/'\ 'PacktWorkshops/'\ 'The-Applied-Artificial-Intelligence-Workshop/'\ 'master/Datasets/car.csv'
- Load the data using the
pd.read_csv()
method.:df = pd.read_csv(file_url)
- Print the first five rows of
df
:df.head()
The output will be as follows:
- Import the
preprocessing
module fromsklearn
:from sklearn import preprocessing
- Create a function called
encode()
that takes a DataFrame...