Creating a predictive model using a random forest
A random forest is an ensemble (a group) of decision trees which will output a prediction value.
For this recipe, we are going to use the Heart dataset from An Introduction to Statistical Learning with Applications in R.
How to do it…
- First, import the Python libraries that you need:
import pandas as pd import numpy as np import matplotlib as plt import matplotlib.pyplot as plt %matplotlib inline
- Next, define a variable for the heart data file, import the data, and view the top five rows:
data_file = '/Users/robertdempsey/Dropbox/private/Python Business Intelligence Cookbook/Data/ISL/Heart.csv' heart = pd.read_csv(data_file, sep=',', header=0, index_col=0, parse_dates=True, tupleize_cols=False, error_bad_lines=False, ...
Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.