<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pablo Oberhauser on Medium]]></title>
        <description><![CDATA[Stories by Pablo Oberhauser on Medium]]></description>
        <link>https://medium.com/@jpoberhauser?source=rss-491b42d285a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*g7CRFZ0GwhjfDfXJ.</url>
            <title>Stories by Pablo Oberhauser on Medium</title>
            <link>https://medium.com/@jpoberhauser?source=rss-491b42d285a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:02:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jpoberhauser/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting your machine ready to use Yolov3 Object Detector on Ubuntu 18.04]]></title>
            <link>https://medium.com/data-science/getting-your-machine-ready-to-use-yolov3-object-detector-on-ubuntu-18-04-185799ebc18d?source=rss-491b42d285a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/185799ebc18d</guid>
            <dc:creator><![CDATA[Pablo Oberhauser]]></dc:creator>
            <pubDate>Fri, 31 Jan 2020 15:35:06 GMT</pubDate>
            <atom:updated>2020-08-31T14:02:21.285Z</atom:updated>
            <content:encoded><![CDATA[<h4>This post shows how to get your machine ready for object detection using yolov3, and more specifically AlexeyAB’s yolov3 Github repo.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*tZXkFkkK2pM2SnxWTZmerA.png" /></figure><p>At Actuate, our goal is to stay at the forefront of computer vision development. As such, we like to keep up to date with the best work happening in the broader computer vision space. Part of this involves keeping track of the best systems to deploy on, such as darknet.</p><p>This post shows how to get your machine ready for object detection using yolov3, and more specifically AlexeyAB’s yolov3 Github repo. This is a high level post on steps needed to start up a virtual machine, install necessary packages, and preliminary testing to make sure you are ready to get started with object detection. This post uses several tutorials I have found to be useful in the installation process for some of these dependencies. The main steps are the following:</p><ol><li>Get either your local machine or VM booted and making sure your GPU is Cuda enabled.</li><li>Cloning necessary GitHub repos</li><li>Installing OpenCV and testing darknet with OpenCV</li><li>Installing Cuda, Cudnn, and other necessary packages to speed up training process in GPU.</li></ol><h4>1. Cloud Compute Resources</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/95/1*PSAZjFOAGLMYD5KO2Lk0Ig.png" /></figure><p>If you have a GPU enabled machine, you can skip to step 2. Otherwise, getting a virtual machine with GPUs will be important for the task of object detection to speed things up considerably. For this walk through we’ll be using Microsoft Azure machines, but any local machine with GPUs or any other cloud computing service will obviously work as well.</p><ul><li>Once you set up your account in Azure, you can navigate to your Home and then inspect the Virtual Machines service.</li><li>Click on the ‘Add +’ button and that will open the ‘Create a virtual machine page’. Make sure you have a resource group set up, otherwise you’ll have to create it as you begin to set up your instance.</li><li>Key part here is selecting a size for your VM. On the first page of configuration when starting up a new VM in Azure, you will find the ‘Change Size’ option. Click on that and pick a size where the ‘Family’ column says GPU.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*g_DFqzVCI6ZetH3n2iixTg.png" /><figcaption>Changing the size of your VM in Azure</figcaption></figure><ul><li>Once the machine has been created you can still configure later, so for example if you want to add disk space or change to another family of machines, that is possible to do down the road. Once you start it, you can ssh into it and you can make sure your machine has a CUDA-enbled GPU with lspci | grep -i nvidia</li></ul><p>The output should look somewhat similar to the screenshot below, although the details of the GPU can vary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*i5dM8d-xrAgg1XmvYvwzhw.png" /><figcaption>Output showing details of CUDA-enabled GPU</figcaption></figure><p>If you are new to Azure, <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-portal">this</a> Getting Started Guide could be very useful:</p><h4>2. Cloning Github repos</h4><ul><li>If you have ssh enabled on your github account simply do</li></ul><pre>git clone <a href="/service/mailto:git@github.com">git@github.com</a>:AlexeyAB/darknet.git</pre><ul><li>If this a new vm, you might have to install git before by:</li></ul><pre>sudo apt install git-all</pre><p>Once that is done, make sure it worked and your working directory should look somewhat similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*DjccSxHae109ENczg4Fq2g.png" /><figcaption>Working directory after cloning AlexeyAB darknet repo</figcaption></figure><ul><li>There are a couple of other dependencies you’ll need:</li></ul><pre>sudo apt install make</pre><ul><li>If you don&#39;t have it already, you’ll need C compiler gcc and g++ . You can check with which gcc and which g++ . If not installed you can do so with the following commands.</li></ul><pre>sudo apt install gcc<br>sudo apt install g++</pre><ul><li>Now we are ready to test out the darknet repo (without OpenCV and without using GPU for training or predictions. Go to the darknet directory and try $make. You should see bunch of warning messages and printed output to your console, and if there are no errors, you are technically ready to start with object detection. Try the $ ./darknet command and you should see the following output on your console:</li></ul><pre>usage: ./darknet &lt;function</pre><p><strong>3. Installing OpenCV 3.4.4 on Ubuntu 18.04</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*0i_2QOhrTCHoQW9Mwf2l_Q.png" /></figure><p>Following these steps, you will install OpenCV3.4.4 but the object detection repo should also work with version 4+.</p><p><a href="https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/">This</a> is one of the easiest to follow tutorials I have found. Adrian Rosebrock does a really good job at explaining the steps you are copying and pasting so you can understand what these dependencies do. He also has pretty good alternatives for when steps might throw errors back at you.</p><p>So go check it out, and hopefully, things go smoothly.</p><p>You can check if the installation worked by opening up a python process in your command line and typing</p><pre>import cv2<br>print(cv2.__version__)</pre><p>Now to check if darknet will now work with opencv:</p><p>Change the Makefile in the /darknet/ directory to show OPENCV=1 and then re- make . As stated in the official documentation, you can test this out with ./darknet imtest data/eagle.jpg although keep in mind that if you are working on a virtual machine you will encounter the “cannot open display” error, but everything should work as it should at this point, and you should see the detection probabilities on the test image.</p><p><strong>4. Installing CUDA and CUDNN on Ubuntu 18.04</strong></p><p>You’ll probably want to run darknet on GPU so you’ll need CUDA, CUDNN installed as well. “Darknet on the CPU is fast but it’s like 500 times faster on GPU!” — Joseph Redmon</p><p>This is an extremely <a href="https://gist.github.com/Mahedi-61/2a2f1579d4271717d421065168ce6a73">helpful post</a> by <a href="https://gist.github.com/Mahedi-61">Mahedi-61</a> with a script that performs a good chunk of the installation. Go ahead and work through these steps.</p><p>The post also highlights how to remove previous CUDA installations:</p><pre>sudo apt-get purge nvidia*<br>sudo apt remove nvidia-*<br>sudo rm /etc/apt/sources.list.d/cuda*<br>sudo apt-get autoremove &amp;&amp; sudo apt-get autoclean<br>sudo rm -rf /usr/local/cuda*</pre><p>If you want a different Cuda or CUDNN version, just change the download files to the desired version in the above script.</p><p>To make sure installation was successful, try</p><pre>nvidia-smi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*EoyfUVannXIASiU-h7w3lQ.png" /><figcaption>Expected output for successful installation of cuda</figcaption></figure><p>And finally, try</p><pre>nvcc -V</pre><p>And hopefully, you get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*dFbSxcIWN82AoEBsNElXjg.png" /><figcaption>output showing nvcc -V results</figcaption></figure><p>Finally, it&#39;s important to make sure that all of this works with darknet and we can then begin testing the object detector.</p><p>Change your Makefile in the darknet directory to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*4KJBh40hP-4mJ4QGkqtI_g.png" /><figcaption>Head of the Makefile</figcaption></figure><p>If make command is successful, then you are ready to begin testing.</p><p>If you want to test with some real weights</p><pre>wget <a href="https://pjreddie.com/media/files/yolov3.weights">https://pjreddie.com/media/files/yolov3.weights</a></pre><pre>./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -dont_show</pre><p>Hope this high level recipe to get your machine ready for object detectors with yolov3 from AlexeyAB’s repo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=185799ebc18d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/getting-your-machine-ready-to-use-yolov3-object-detector-on-ubuntu-18-04-185799ebc18d">Getting your machine ready to use Yolov3 Object Detector on Ubuntu 18.04</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[pyGAM : Getting Started with Generalized Additive Models in Python]]></title>
            <link>https://codeburst.io/pygam-getting-started-with-generalized-additive-models-in-python-457df5b4705f?source=rss-491b42d285a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/457df5b4705f</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Pablo Oberhauser]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 14:12:40 GMT</pubDate>
            <atom:updated>2017-11-29T15:48:21.087Z</atom:updated>
            <content:encoded><![CDATA[<p>I came across pyGAM a couple months ago, but found few examples online. Below is a more practical extension to the documentation found in the pyGAM homepage.</p><p><a href="https://github.com/dswah/pyGAM">dswah/pyGAM</a></p><p>Generalized additive models are an extension of generalized linear models. They provide a modeling approach that combines powerful statistical learning with interpretability, smooth functions, and flexibility. As such, they are a solid addition to the data scientist’s toolbox.</p><p>FYI: This tutorial will not focus on the theory behind GAMs. For more information on that there is an amazing blog post by Kim Larsen here:</p><p><a href="http://multithreaded.stitchfix.com/blog/2015/07/30/gam/">GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology - Multithreaded</a></p><p>Or for a much more in depth read check out Simon. N. Wood’s great book, “Generalized Additive Models: an Introduction in R”</p><p>Some of the major development in GAMs has happened in the R front lately with the mgcv package by Simon N. Wood. At our company, we had been using GAMs with modeling success, but needed a way to integrate it into our python-based “machine learning for production” framework.</p><p><strong>Enter pyGAM</strong></p><p><strong>Installation</strong></p><p>Installation is simple</p><pre>pip install pygam</pre><p>pyGAM also makes use of scikit-sparse which you can install via conda. Not doing so will result in a warning and potential problems with the slowing down of optimization for models with monotonicity/convexity penalties.</p><p><strong>Classification Example</strong></p><p>Let’s walk through a classification example…</p><p>We import LogisticGAM to begin the classification training process, and load_breast_cancer for the data. This data contains 569 observations and 30 features. The target variable in this case is whether the tumor of malignant or benign, and the features are several measurements of the tumor. For showcasing purposes, we keep the first 6 features only.</p><pre>import pandas as pd        <br>from pygam import LogisticGAM<br>from sklearn.datasets import load_breast_cancer<br>#load the breast cancer data set</pre><pre>data = load_breast_cancer()<br>#keep first 6 features only</pre><pre>df = pd.DataFrame(data.data, columns=data.feature_names)[[&#39;mean radius&#39;, &#39;mean texture&#39;, &#39;mean perimeter&#39;, &#39;mean area&#39;,&#39;mean smoothness&#39;, &#39;mean compactness&#39;]]<br>target_df = pd.Series(data.target)<br>df.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*pmf_aCoTgvDEAn996QUFXQ.png" /><figcaption>Description of sample classification data</figcaption></figure><p><strong>Building the model</strong></p><p>Since this is a classification problem, we want to make sure we use pyGam’s LogisticGAM() function.</p><pre>X = df[[&#39;mean radius&#39;, &#39;mean texture&#39;, &#39;mean perimeter&#39;, &#39;mean area&#39;,&#39;mean smoothness&#39;, &#39;mean compactness&#39;]]<br>y = target_df</pre><pre>#Fit a model with the default parameters</pre><pre>gam = LogisticGAM().fit(X, y)</pre><p>The summary() function provides a statistical summary of the model. In the diagnostics below, we can see statistical metrics such as AIC, UBRE, log likelihood, and pseudo-R² measures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*89qhbKzWrGKDbkovKvFurA.png" /><figcaption>Model summary</figcaption></figure><p>To get the training accuracy we simply run</p><pre>gam.accuracy(X, y)</pre><p>And we get a <strong>.961335676625659 accuracy</strong> right off the bat.</p><p>One of the nice things about GAMs is that their additive nature allows us to <strong>explore and interpret individual features</strong> by holding others at their mean. The snippet of code below shows these plots for the features included in the trained model. generate_X_grid helps us build a grid for nice plotting.</p><pre>XX = generate_X_grid(gam)<br>plt.rcParams[&#39;figure.figsize&#39;] = (28, 8)<br>fig, axs = plt.subplots(1, len(data.feature_names[0:6]))<br>titles = data.feature_names<br>for i, ax in enumerate(axs):<br>    pdep, confi = gam.partial_dependence(XX, feature=i+1, width=.95)<br>    ax.plot(XX[:, i], pdep)<br>    ax.plot(XX[:, i], confi[0][:, 0], c=&#39;grey&#39;, ls=&#39;--&#39;)<br>    ax.plot(XX[:, i], confi[0][:, 1], c=&#39;grey&#39;, ls=&#39;--&#39;)<br>    ax.set_title(titles[i])</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*fgyrbyKm_FkOHBTPMqlU8g.png" /><figcaption>Partial dependency plots with confidence intervals</figcaption></figure><p>We can already see some very interesting results. It is clear that some features have a fairly simple linear relationship with the target variable. There are about three features that seem to have strong non-linear relationships though. We will want to combine the interpretability of these plots, and the power to prevent over fitting in GAMs to come up with a model that generalizes well to a holdout set of data.</p><p><strong>Partial dependency plots</strong> are extremely useful because they are highly interpretable and easy to understand. For example at first examination we can tell that there is a very strong relationship between the mean radius of the tumor and the response variable. The bigger the radius of the tumor, the more likely it is to be malignant. Other features like the mean texture are harder to decipher, and we can already infer that we might want to make that a smoother line (we walk through smoothing parameters in the next section).</p><p><strong>Tuning Smoothness and Penalties</strong></p><p>This is where the functionality of pyGAM begins to really shine through. We can choose to build a grid for parameter tuning or we can use intuition and domain expertise to find optimal smoothing penalties for the model.</p><p>Main parameters to keep in mind are:</p><p>n_splines , lam , and constraints</p><p>n_splines refers to the number of splines to use in each of the smooth function that is going to be fitted.</p><p>lam is the penalization term that is multiplied to the second derivative in the overall objective function.</p><p>constraints is a list of constraints that allows the user to specify whether a function should have a monotonically constraint. This needs to be a string in [‘convex’, ‘concave’, ‘monotonic_inc’, ‘monotonic_dec’,’circular’, ‘none’]</p><p>The default parameters that are being used in the model presented above are the following….</p><p>n_splines = 25</p><p>lam = 0.6</p><p>constraints = None</p><p>So let’s play around with n_splines. Let’s say for example we think mean texture is too “un-smooth” at the moment. We change parameter list to the following: (Note that another cool thing about pyGAM is that we can specify one single value of lambda and it will be copied to all of the functions. Otherwise, we can specify each one in a list…)</p><pre>lambda_ = 0.6<br>n_splines = [25, 6, 25, 25, 6, 4] <br>constraints = None<br>gam = LogisticGAM(constraints=constraints, <br>          lam=lambda_,<br>         n_splines=n_splines).fit(X, y)</pre><p>Which changes our training accuracy to <strong>0.9507</strong></p><p>And now the partial dependency plots look like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*eFpCPoFIK-7IMBxuQe1mqw.png" /><figcaption>Mean texture, mean smoothness, and mean compactness changed</figcaption></figure><p>The drop in accuracy tells us that there is some information we are not capturing by smoothing the mean texture estimator that much, but it highlights how the analyst can encode intuition into the modeling process.</p><p>Keep in mind that n_splines is only one parameter to change. Lambda controls how much we penalize ‘wiggliness’, so even if we keep a large value for n_splines we could get a straight line if lambda is large enough. Tuning these can be labor intensive, but there is an automated way to do this in pyGAM.</p><p><strong>Grid search with pyGAM</strong></p><p>The gridsearch()function creates a grid to search over smoothing parameters. This is one of the coolest functionalities in pyGAM because it is very easy to create a custom grid search. One can easily add parameters and ranges. For example, the default arguments are a dictionary of possible lambdas to create a grid search {&#39;lam&#39;:np.logspace(-3,3,11)}</p><p>And just like the default argument is shows, we can add more and more arguments to the function and thus create a custom grid search.</p><pre>gam = LogisticGAM().gridsearch(X, y)</pre><p><strong>Generalizing a GAM</strong></p><p>Using a holdout set is the best way to balance bias-variance trade off in models. GAMs do a very good job at allowing the analyst to directly control over fitting in a statistical learning model.</p><p>pyGAM really plays nice with the sklearn workflow, so once it is installed it’s basically like fitting a sklearn model.</p><p>We can split the data just like we usually would:</p><pre>import numpy as np<br>from sklearn.model_selection import train_test_split<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)<br>gam = LogisticGAM().gridsearch(X_train, y_train)</pre><p>Predict classes or probabilities and use sklearn metrics for accuracy;</p><pre>from sklearn.metrics import accuracy_score<br>from sklearn.metrics import log_loss<br>predictions = gam.predict(X_test)<br>print(&quot;Accuracy: {} &quot;.format(accuracy_score(y_test, predictions)))<br>probas = gam.predict_proba(X_test)      <br>print(&quot;Log Loss: {} &quot;.format(log_loss(y_test, probas)))</pre><p><strong>Accuracy: 0.957446808511</strong></p><p><strong>Log Loss: 0.126179009744</strong></p><p>Let’s try a model that better generalizes. To do so, we can reduce the number of splines and see how the holdout set errors turn out.</p><pre>lambda_ = [0.6, 0.6, 0.6, 0.6, 0.6, 0.6]<br>n_splines = [4, 14, 4, 6, 12, 12] <br>constraints = [None, None, None, None, None, None]<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)<br>gam = LogisticGAM(constraints=constraints, <br>                  lam=lambda_,<br>                 n_splines=n_splines).train(X_train, y_train)<br>predictions = gam.predict(X_test)<br>print(&quot;Accuracy: {} &quot;.format(accuracy_score(y_test, predictions)))<br>probas = gam.predict_proba(X_test)      <br>print(&quot;Log Loss: {} &quot;.format(log_loss(y_test, probas)))</pre><p><strong>Accuracy: 0.968085106383</strong></p><p><strong>Log Loss: 0.0924671883985</strong></p><p><strong>Regression</strong></p><p>Switching to a regression context is simple:</p><pre>from sklearn.datasets import load_boston<br>boston = load_boston()<br>df = pd.DataFrame(boston.data, columns=boston.feature_names)<br>target_df = pd.Series(boston.target)<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*rFYY30dbvgEyPedg4rijFA.png" /><figcaption>Data for regression problem</figcaption></figure><pre>X = df<br>y = target_df</pre><pre>gam = LinearGAM(n_splines=10).gridsearch(X, y)<br>gam.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*teuLvpq3B6JIn-gVpKxE4g.png" /><figcaption>Regression GAM summary</figcaption></figure><p>And we can similarly plot the feature dependencies:</p><pre>XX = generate_X_grid(gam)<br>plt.rcParams[&#39;figure.figsize&#39;] = (28, 8)<br>fig, axs = plt.subplots(1, len(boston.feature_names[0:6]))<br>titles = boston.feature_names<br>for i, ax in enumerate(axs):<br>    pdep, confi = gam.partial_dependence(XX, feature=i+1, width=.95)<br>    ax.plot(XX[:, i], pdep)<br>    ax.plot(XX[:, i], confi[0][:, 0], c=&#39;grey&#39;, ls=&#39;--&#39;)<br>    ax.plot(XX[:, i], confi[0][:, 1], c=&#39;grey&#39;, ls=&#39;--&#39;)<br>    ax.set_title(titles[i],fontsize=26)</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*nt0GYDItW2bwZ6EVXKvrmg.png" /><figcaption>Regression partial dependency plots</figcaption></figure><p>There are many more features and knobs to turn when building a GAM. Stay tuned for the advanced tutorial on further generalizing a GAM, CV for feature and smoothness selection, residual diagnostics, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=457df5b4705f" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/pygam-getting-started-with-generalized-additive-models-in-python-457df5b4705f">pyGAM : Getting Started with Generalized Additive Models in Python</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>