An analysis of motorcyclist habits through online sales
Contributed by Thomas Boulenger. He is currently in the NYC Data Science Academy 12 week full time Data Science Bootcamp program taking place between January 11th to April 1st, 2016. This post is based on his third class project – Web scraping (due on the 6th week of the program).
Overview and assumptions
The motorcycle industry is one that deals with passion, its History although parallel to that of the automotive industry, has long been restricted to a small circle of purists. Motorcycle buyers quite often remain loyal to a brand they like and they identify to. This implies that one often expects a given brand owner to show some behaviour typically associated to the brand's image. On average one would assume that BMW owners care more about security than others, drive their motorcycles more often and for longer distances than others, including holiday road-trips. On the other hand, Ducati owners are expected to use their motorcycle less often, but to care more about the look, the sound and general appeal of their vehicle.
Within a given brand, the same sort of differences in habits are expected from one particular model to another. Although maybe not as a strong distinction as the one by brand, we still expect to see something here.
An online sales listing website: Cycle-Crunch.com
Unlike other Western motorcycle markets, in the US the sales have long been dominated by one Historic emblematic brand: Harley-Davidson. However, in recent years the company have grown worried as their historical pool of customers, Caucasian 35+ men, ages and gets thinner over time. On the company's website, one may find information about the Demographics of their customers and shows that not only is the company aware of the matter, but also willing to address it.
Aim of the analysis
Here we wish to get a glimpse at the US market sales for motorcycles by scraping the website we have selected to obtain a dataset that will summarise the listed motorcycles' information (price, year of production, brand, model, city, color, listed date). The hope is then that the data we obtain allows us to say something about some brands characteristics, the owners habits. If a listed motorcycle has had a high average mileage over its lifetime, how likely is it to be an Harley-Davidson? Or a Yamaha? Can we find better suited indicators to decide wether a given listed motorcycle belongs to a given brand, or to be a given model?
Scraping with BeautifulSoup
To ease the scraping, we use the BeautifulSoup package in Python. Running a loop, we sift through all the results front pages by updating our current page url after we are done retrieving all the information we needed. More specifically, for all front page of the search results we find every box's url link to go look at the page dedicated to each listed model and get all the available details (such as mileage and descriptions which are for instance missing from the front page). See the Appendix A below for the detailed code.
After a few hours we were able to get the information contained in 1,282 front pages, giving us the details of 12,812 listed motorcycles. We thus obtain the following dataset
Some of the variables are categorical (color, condition, listed, make i.e. brand, model and state), so in order to compare them with the numerical variables, we first add some new variables representing an index for any of these categorical variables. It turns out that most of the above variables are quite poorly correlated to one another.
In order to get a better sense of what the data we have obtained looks like, we can plot the distribution of the motorcycle listed per brand
This seems a clear sign of the long time domination of Harley-davidson over the US market, but the magnitude by which Harley dominates over all the other brands is still a little surprising. When restricting at heavyweight motorcycles (those with engines of 601 cubic centimeters or greater), Harley Davidson represents roughly 50% of the US market share. However, in recent years signs of a decline have started to show, with their market share for the first semester of 2015 falling at 47.5%, below the psychological mark of the 50%. Yet here we see no sign of such a decrease in popularity of Harley Davidson models. If anything, the trend even seems to go in the opposite direction, with an even greater proportion of Harley Davidson among models to be sold as new than among models to be sold as used.
This kind of distribution seems a very particular feature of the US market where motorcycles owners often buy in the "chopper" category, that is low, heavy, very stable and relatively slow motorbikes but with a lot of torque. Among the heavyweight motorcycle category, the best selling model in the US would thus looks like the following Street Glide Special
Characteristics by brand
Let us now look a little more closely at our data and see wether we can find patterns to characterise brands or models.
- Evolution of prices
Though few data are available for years of production < 1980 (only 35 motorcycles listed), we see a funny bouncing showing how valuable old-style models have become, and that the rebound in devaluation seems to happen some time in the 1980s.
Based on this data it thus seems one should wait 35 years on average before a model becomes a classic, and that provided it is in good condition, its listed price starts increasing again as it ages. Zooming in recent years we see the slopes for Harley-Davidson and Indians appear steeper than the others, probably indicating a worse depreciation rate than for the most common competitor Japanese brands plotted here (Yamaha, Honda, Suzuki, Kawasaki).
We may next attempt to roughly average the amount by which motorcycles depreciate every year among every brand. To do so, for every brand we subset the used motorcycles and keep only the models for which at least one new such model is also listed on sale. For every model we then average the price over the ones listed as new and use it as our "Model Price as New". Within the dataset for used motorcycles, we may then calculate the yearly depreciation ratio. We then obtain the following graph
We see what is probably a big difference in Harley-Davidson owners habits: the difference between the price of used models and their price as new tend to be negative, as most riders love to customize their motorcycle, often spending half the price as new in accessories/painting jobs/exhaust pipes etc.. Of course this means that overall, they lose more money than others every year, but there is no simple way to find this out for sure. A possibility would be to use the pictures available in the description, compare them with original models and quantify how much the two differ.
Although we don't have enough observations for the other brands to make a definitive claim, it seems the depreciation per year is pretty low and similar for Honda, Suzuki and Yamaha. Indian on the other hand seems to be showing a negative feature, similar to Harley-Davidson. While one could assume owners of Honda, Suzuki or Yamaha tend to use their vehicle for more practical reason such as commuting, Indians owners may sow a love for customisation similar to Harley-Davidson owners.
How often do owners use their motorcycle is another pretty obvious characterising feature. The only way we have to measure this here is through the yearly mileage that we estimate by the ratio of the kilometres the motorcycle yet totalizes with the time since it has been produced
Note that given there are so many more Harley-Davidson listed than any other brand, there is an overfit to the distribution that doesn't allow us to initially compare it to the others. In order to produce the graph above we have reduced the resolution on the "ydist" (yearly mileage) variable in the following fashion
Surprisingly, the only obvious peak of yearly mileage appears for Honda, when the others seem scattered all across the spectrum. We don't even see an obvious peak for Harley-Davidson, although the number of motorbikes listed tends to decrease as the yearly mileage increases, it appears almost evenly distributed. The lowest peaks appear for Honda then Yamaha, when the highest peaks appear for Suzuki. Once again, Indian seems to closely follow Harley-Davidson's distribution. We start to clearly identify, at least within our dataset, two different kind of observations. One is of the like of Harley-Davidson and Indian, with a large distribution of different yearly mileage, probably corresponding to different sort of usage for different kind of customers. The other most obvious one appears for Suzuki and show a relatively large peak around 3.500 km a year on average and is likely to correspond to commuters. The other Japanese brands show much lower peaks, suggesting most owners do not drive many miles a year.
One thing that most riders dread is a rainy day and cold temperatures, as one might assume such things make the ride unpleasant to most riders. Owning a motorcycle in a region where cold temperatures and rainy conditions are common probably says a lot about an owner's behaviour. A regular commuter will have to drive almost every day and often face driving in the rain, while more occasional users will only get on a ride when the weather is nice.
In order to say something about the correlation between the local weather and an owner's habits, we must first obtain the weather's data. To do so we use the cities listed in our Dataframe from Cycle-Crunch.com and use it to sift through the online database provided by weatherbase.com:
Once again, we use the BeautifulSoup package in python to scrape the website. The procedure turns out a little more tricky than previously, as the website expects a response when sending cookies. One has to use the Mechanize package in Python to simulate a browser so that weatherbase.com does not load an error page. Furthermore there are some subtleties occurring when the initial query leads to multiple results or if the given city does not match any recorded location of the database. In that case the query's response is often a new search page with multiple results in a small radius (often 5-20 miles) of the initial query. Using the first closest location, we may thus obtain a pretty accurate approximation of the location's weather conditions. For the sake of simplicity we retain only annual figures for the following features: Average Precipitation, Average Number of Days With Precipitation, Average Number of Days Below 32F/0C, Average Number of Days Above 90F/32C, Average Number of Rainy Days.
Despite using the closest location when there is no result for the listed city, we still obtain some rows in the initial motorcycles DataFrame left with only partial weather information (one of the selected feature may simply be missing for a given location). Anyhow, we end up with additional valuable information to work with. See Appendix B for more details about the code for scraping the weather data.
The idea now is to try to looks at how the different brands and the new weather information behave with respect to one another. We for instance try to answer questions such as:
- What is the distribution of every brand with respect to the weather features? In other words, what is the conditional probability P(feature split|brand)?
- Given that the average number of days with precipitation is between x and y, what is our sample probability to obtain such and such brands when a listed sale is picked at random?
Consider for instance the weather feature "average number of days with Temperatures below 0°C". We split the feature in two, the number of such days is either less or more than 140 days a year. In the code below, note we can either split automatically in an even number of splits or provide a manual one. After trying a few cut-offs, here we decided to select 140 days for our cut-off value as it revealed an interesting contrast. We obtain the following set of proportions for the brands with at least 10 listed models:
We observe that 84.7% of the 59 yamaha listed where in "cold" zones with at least 140 days with temperatures below 0°C. This seems a common phenomenon among Japanese brands, as Honda, Suzuki and Kawasaki respectively have 68.7%, 92% and 72.2% of their observations listed in the "cold" zone (with 32, 25 and 18 total observations listed). This is in sheer contrast to Harley-Davidson, Buell, Big Dog or Victory for which the majority of observations are listed in the "hot" zones with fewer than 140 days with temperatures below 0°C, or respectively 76.6%, 72.7%, 88% and 87.5% of their total observations.
This suggests that this particular weather feature might be a good classifier. Considering now each of those splits, we may look at the conditional probability of belonging to a brand knowing that the observation lies within one of the previous two splits.
For both splits, the vast majority of observations are Harley-Davidson. However they vary from 97.5% in the "cold" region to 90.6% in the "hot" region, quite a significant drop given the skewness of the motorcycles data. We may also note the following interesting fact: given that an observation is NOT an Harley-Davidson, in the "cold" region, we have a 31.25% chance that it is a Yamaha, whereas in the "hot" it is only a 5.8% chance. For the brand Yamaha, there is a factor 6 between cold and hot regions, when a priori assuming we do not have an Harley-Davidson. Although Harley-Davidson massively predominates, we can thus recover some ways to hone in on Japanese brands by splitting the data between these regions with different weather conditions.
To obtain the previous tables and more given any of the weather feature we selected, we used the following generic code:
Let us finally make a final attempt to differentiate the different brands as best as we can by clustering the observations with both the yearly mileage and the weather features for the average number of days with precipitation and below 0°C/above 32°C. We use the K-means algorithm implemented by the SciKit library in Python. Note we first normalise our features to make them more comparable to one another and prevent the apparition of artificial clusters. Given the large number of observations and how they are vastly clouded by the majority class of Harley-Davidson, we may try to use different numbers of clusters and see if a large number of them could pinpoint a given brand other than Harley-Davidson. We try this with Yamaha and its 59 observations for which we have a complete record of average number of days below 0°C. To determine what number of clusters we should select, we test a range of possibilities from 2 clusters up to 250. In order to decide which number of cluster is best we record the the probability of an observation being a Yamaha among every cluster. Surprisingly, the Yamaha's family of observation remains stable and mostly contained within a single cluster of 48 observations so long as we select less than 101 clusters.
The "purest" cluster is achieved the ridicule number of 246 clusters, in which case one of them contains 15 Yamaha, representing 35.7% of its total 42 observations. Another run led to a different 30.7% (in K-means, the centroids being initialised randomly, the final result may vary from one run to another). In the 25th cluster, there were then 20 Yamahas while only 22 Harley-Davidsons, 12 Suzuki and 11 Honda. In other word that cluster contained 66% of Japanese brands.
Now a more stable clustering using only 92 clusters achieved 15.5% of Yamahas and 45% of Japanese brands and 55% of Harley-Davidson. That cluster contained 81% of the Yamahas observations and was much less likely to be an Harley-Davidson than in the rest of the clusters. Of course, repeating the process a certain number of times and recording the best results we may refine these results a little. But the hurdle of clearing the clusters of any Harley-Davidson to differentiate it from other brands is still difficult.
Appendix A: code for scraping Cycle-Crunch.com
Appendix B: scraping weatherbase.com