<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Python on Blog from chriscomputing</title><link>https://blog.chriscomputing.de/en/tags/python/</link><description>Recent content in Python on Blog from chriscomputing</description><generator>Hugo -- gohugo.io</generator><language>en-EN</language><copyright>chriscomputing (CC BY-NC-SA 4.0)</copyright><lastBuildDate>Sun, 16 Aug 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.chriscomputing.de/en/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Predicting bikeshare demand using using machine learning</title><link>https://blog.chriscomputing.de/en/blog/xgboost-bikeshare-predictions/</link><pubDate>Sun, 16 Aug 2026 00:00:00 +0000</pubDate><guid>https://blog.chriscomputing.de/en/blog/xgboost-bikeshare-predictions/</guid><description>&lt;p&gt;In this competition, we used Machine Learning to predict dynamic demand for bikesharing based on a Kaggle dataset. Since the organizers restricted us to regression, we decided to use XGBoost. The small competition was held last year at my university. I competed together with a friend of mine. You can see the code on my &lt;a href="https://github.com/chriscomputing/bikeshare-competition"&gt;Github&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="bikesharing-dataset"&gt;Bikesharing dataset&lt;/h2&gt;
&lt;p&gt;The dataset was provided by the organizers, but I believe it to be &lt;a href="https://www.kaggle.com/c/bike-sharing-demand/data/"&gt;this&lt;/a&gt; dataset from Kaggle. The dataset contains for example information about the temperature, humidity, windspeed, if it was a holiday or workday and time and date.&lt;/p&gt;</description><content:encoded><![CDATA[<p>In this competition, we used Machine Learning to predict dynamic demand for bikesharing based on a Kaggle dataset. Since the organizers restricted us to regression, we decided to use XGBoost. The small competition was held last year at my university. I competed together with a friend of mine. You can see the code on my <a href="https://github.com/chriscomputing/bikeshare-competition">Github</a>.</p>
<h2 id="bikesharing-dataset">Bikesharing dataset</h2>
<p>The dataset was provided by the organizers, but I believe it to be <a href="https://www.kaggle.com/c/bike-sharing-demand/data/">this</a> dataset from Kaggle. The dataset contains for example information about the temperature, humidity, windspeed, if it was a holiday or workday and time and date.</p>
<h3 id="preprocessing-the-dataset">Preprocessing the dataset</h3>
<p>We used <a href="https://seaborn.pydata.org/">seaborn</a>, a statistical data visualization library for Python to analyze the dataset. As expected, a correlation matrix showed that <code>atemp</code> (appearent temperature) and <code>temp</code> are highly correlated, and that <code>season</code> and <code>month</code> are equally highly correlated. For this reason, we decided to drop <code>season</code> and <code>atemp</code>.</p>
<p>
















  
  
  
      
      
  <figure class="figure " >
  <picture  >
  <img class="figure-img img-fluid" src="https://blog.chriscomputing.de/images/posts/bikeshare-comp/corr-matrix.png?v=1d7cd3aee4d81d9687fe5f8e2bb0627f" alt="Feature correlation matrix using matplotlib and seaborn in Python" title="Correlation matrix of all features. Blue is low correlation, red is high correlation." loading="lazy" height="749" width="843" />
</picture>

  <figcaption class="figure-caption">Correlation matrix of all features. Blue is low correlation, red is high correlation.</figcaption>
</figure>
</p>
<p>Some features were continuous data, for example temperature, while others were cyclic (like time  or workingday). Only few were categorical. This is a problem for regression, since it enforces a strict linear relation between these features and the prediction target. A regression will run into problems predicting usage (cnt, shored for count) based on temperature, since both very high and very low temperatures will lead to less usage. Even worse, weekday simply jumps from 7 back to 1 at the beginning of the week, marking a large and sudden shift at midnight. Therefore, we had to one-hot encode many features during preprocessing.</p>
<h2 id="using-xgboost-regression-to-predict-bikeshare-customers">Using XGBoost regression to predict bikeshare customers</h2>
<p>After trying multiple models, the best one was the <code>XGBRegressor</code> from <a href="https://xgboost.readthedocs.io/en/stable/">XGBoost</a>, trained on a logratihmic scale. For hyperparameter search, we used the <code>RandomizedSearchCV</code> from sklearn across 9 different parameters.</p>
<p>On the evaluation set, our model scored a Root Mean Squared Error (RMSE) of 37.78, while the Mean Absolute Error (MAE) was 23.27. That is not fantastic, but also not a terrible job. Unfortunately, we did not have time to improve our model further. In the end, our model scored an RMSE of 56.897 on the hidden evaluation set. Which is admittedly even worse, but it still got us <strong>first place</strong> in end. All teams had an unexpected high RMSE on the hidden evaluation set. Maybe it was not very representative of the entire dataset.</p>
<h2 id="what-could-be-improved">What could be improved</h2>
<p>As I already said, we did not have a lot of time for this competition. While being restricted to regression did not help, we could have done a more in-depth analysis on our worst performing predictions.</p>
]]></content:encoded></item></channel></rss>