Search icon CANCEL
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
Practical Data Analysis Cookbook

You're reading from   Practical Data Analysis Cookbook Over 60 practical recipes on data exploration and analysis

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781783551668
Length 384 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Tomasz Drabas Tomasz Drabas
Author Profile Icon Tomasz Drabas
Tomasz Drabas
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Preparing the Data FREE CHAPTER 2. Exploring the Data 3. Classification Techniques 4. Clustering Techniques 5. Reducing Dimensions 6. Regression Methods 7. Time Series Techniques 8. Graphs 9. Natural Language Processing 10. Discrete Choice Models 11. Simulations Index

Preparing a dataset to estimate discrete choice models


The dataset prepared for these recipes consists of 10,000 choice situations. The first column contains the ID of the chosen alternative and the second column contains a list of all the alternatives the person was choosing from; not all of the alternatives were available in all choice situations.

Getting ready

To execute this query, you will need pandas, NumPy, and the regular expressions module. No other prerequisites are required.

How to do it…

Python Biogeme requires a tab-separated dataset, where each row contains the attributes of all the alternatives and the flag for the chosen one (an integer) as well as an indicator whether the alternative was available to the decision-maker at the time when the decision was made. Only numerical values are allowed. The following code can be found in the dcm_dataPrep.py file:

import pandas as pd
import numpy as np
import re

# read datasets
observations_filename = '../../Data/Chapter10/observations...
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 R$50/month. Cancel anytime