Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python for ArcGIS Pro

You're reading from   Python for ArcGIS Pro Automate cartography and data analysis using ArcPy, ArcGIS API for Python, Notebooks, and pandas

Arrow left icon
Product type Paperback
Published in Apr 2022
Publisher Packt
ISBN-13 9781803241661
Length 586 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
William Parker William Parker
Author Profile Icon William Parker
William Parker
Silas Toms Silas Toms
Author Profile Icon Silas Toms
Silas Toms
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part I: Introduction to Python Modules for ArcGIS Pro
2. Introduction to Python for GIS FREE CHAPTER 3. Basics of ArcPy 4. ArcGIS API for Python 5. Part II: Applying Python Modules to Common GIS Tasks
6. The Data Access Module and Cursors 7. Publishing to ArcGIS Online 8. ArcToolbox Script Tools 9. Automated Map Production 10. Part III: Geospatial Data Analysis
11. Pandas, Data Frames, and Vector Data 12. Raster Analysis with Python 13. Geospatial Data Processing with NumPy 14. Part IV: Case Studies
15. Case Study: ArcGIS Online Administration and Data Management 16. Case Study: Advanced Map Automation 17. Case Study: Predicting Crop Yields 18. Other Books You May Enjoy
19. Index

Fitting a random forest model

We will use the combined dataset we now have to perform preliminary tests and fit the model. To run these tests and eventually the model, the sklearn module will need to be installed using pip via the command prompt (or within the Notebook):

  1. In the next cell, install the sklearn module and import the following (note that the sklearn module may already be installed):
    pip install sklearn 
    from sklearn.model_selection import train_test_split
    from sklearn.ensemble import RandomForestRegressor
    from sklearn.metrics import r2_score
    

    Run the cell.

Before running any tests, note that the random forest model only accepts numeric variables, meaning all the categorical variables – specifically the 'Item' field – will need to be changed to numeric. Essentially, each value will be represented by a number. Some cleanup needs to be completed as well, removing null values and dropping columns that are redundant...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime