<?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 Patrick Long, PhD on Medium]]></title>
        <description><![CDATA[Stories by Patrick Long, PhD on Medium]]></description>
        <link>https://medium.com/@pkmklong?source=rss-bd0bff93b38f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0Jkd0PlKNofCFvIKaIw_zA.jpeg</url>
            <title>Stories by Patrick Long, PhD on Medium</title>
            <link>https://medium.com/@pkmklong?source=rss-bd0bff93b38f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 15:53:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pkmklong/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[Deploy a Python Machine Learning Model on your iPhone]]></title>
            <link>https://pub.towardsai.net/deploy-a-python-machine-learning-model-on-your-iphone-d006b1e04bc4?source=rss-bd0bff93b38f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d006b1e04bc4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Patrick Long, PhD]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 01:01:37 GMT</pubDate>
            <atom:updated>2021-02-11T01:01:37.007Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsai.net/p/category/machine-learning">Machine Learning</a>, <a href="https://towardsai.net/p/category/programming">Programming</a></h4><h4>A minimalist guide</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*He_DVTn2N7_-p2ZPVmpNwA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@altumcode?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">AltumCode</a> on <a href="https://unsplash.com/s/photos/machine-learning-iphone?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This article describes the shortest path from training a python machine learning model to a proof of concept iOS app you can deploy on an iPhone. The goal is to provide the basic scaffolding while leaving room for further customization suited to one’s specific use case. In the spirit of simplicity, we will overlook some tasks such as model validation and building a fully polished user interface (UI). By the end of this tutorial, you will have a trained model running on iOS that you can showcase as a prototype and load to your device.</p><h4><strong>Step 1. Set up your environment</strong></h4><p>First, let’s create a python virtual environment called .core_ml_demo and then install the necessary libraries i.e. pandas scikit-learn and coremltools. From your terminal run:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0c7cbf0b70bac2c33d5015d7a3241ec/href">https://medium.com/media/c0c7cbf0b70bac2c33d5015d7a3241ec/href</a></iframe><p>Next we will install <strong>Xcode</strong>. Xcode is a development toolkit for Apple products. Note that Xcode is quite large (&gt; 10 Gb). I’d recommend grabbing a cup of coffee or running your install overnight. -<em>Note, this guide uses Xcode Version 12.3 (12C33) on macOS Catalina 10.15.5.</em></p><p><a href="https://apps.apple.com/us/app/xcode/id497799835?mt=12">‎Xcode</a></p><h4><strong>Step 2. Train a model</strong></h4><p>We’ll use scikit-learn’s Boston Housing Price <a href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_boston.html"><strong>toy dataset</strong></a><strong> </strong>to train a linear regression model to predict home price based on property and socio-economic attributes. Since we’re aiming for simplicity, we’ll limit the feature space to 3 predictors and use house price as our target variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d53168fa3b4fe944b3bdb2ddda2f0151/href">https://medium.com/media/d53168fa3b4fe944b3bdb2ddda2f0151/href</a></iframe><h4><strong>Step 3. Convert the model to Core ML</strong></h4><p>Apple provides two avenues to develop models for iOS. The first, <a href="https://developer.apple.com/documentation/createml">Create ML</a>, allows one to produce models entirely within the Apple ecosystem. The second, <a href="https://coremltools.readme.io/">Core ML</a>, allows one to integrate models from third parties into the Apple platform by converting them to the Core ML format. Since we’re interested in running a python trained model on iOS, we’ll use the latter.</p><p>We’ll convert our sklearn model to the Core ML format (.mlmodel) using python’s coremltools package before importing to Xcode. coremltools allows one to assign metadata to a model object such as authorship information and model feature and outcome descriptions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de844acbe4f078bbf76004666f52d706/href">https://medium.com/media/de844acbe4f078bbf76004666f52d706/href</a></iframe><h4><strong>Step 4. Start a new Xcode project</strong></h4><p>And that’s it for python. From hereon, we can complete a prototype app using only Xcode and Swift. This can be done with the setup below.</p><ul><li>Open up Xcode and create a new Xcode project</li><li>Choose “iOS” as the Multiplatform type</li><li>Select “App” as the Application type</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8NKTxvgvgeoB6Udl8ntdA.png" /><figcaption>Creating a new Xcode project for iOS</figcaption></figure><ul><li>Next, name your project and select the “SwiftUI” Interface.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-Arib4hFQlZpeNfckjtWQ.png" /><figcaption>Naming your Xcode project</figcaption></figure><ul><li>Now simply drag and drop the .mlmodel file (saved above in step 3) into your Xcode directory. Xcode will automatically generate a Swift class for your model as shown in the editor below. If you inspect your model class, you’ll notice that it includes the details we entered when saving our python model using coremltools such as feature and target field descriptions. This is handy for model stewardship.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TZ7YlQbneqH_vr209hMWQ.png" /><figcaption>Importing your .coreml file into your Xcode project</figcaption></figure><h4><strong>Step 5. Build a model UI</strong></h4><p>Next we’ll build a basic UI by modifying the ContentView.swift file in your Xcode project. The Swift code below sets up a UI that allows users to adjust house attributes and then to predict house price. There are several elements we can review here.</p><p>The NavigationView contains our essential UI. It includes:</p><ul><li><a href="https://developer.apple.com/documentation/swiftui/stepper">Stepper</a> structs (<em>lines 19–30</em>) for each of our three features, which enable users to modify feature values. Steppers are basically widgets that modify the <a href="https://developer.apple.com/documentation/swiftui/state">@State</a> of our house attribute variables (<em>lines 6–8</em>).</li><li>A <a href="https://www.simpleswiftguide.com/how-to-add-button-to-navigation-bar-in-swiftui/">Button</a> on the navigation bar (<em>lines 31–40</em>) to call our model from within the predictPrice function (<em>line 46</em>). This yields an <a href="https://www.hackingwithswift.com/quick-start/swiftui/how-to-show-an-alert">Alert</a> message on the screen with the predicted price.</li></ul><p>Outside of the NavigationView we have our predictPrice function (<em>lines 46–62</em>). The predictPrice function instantiates our Swift Core ML model class and generates a prediction according the values stored in our feature states.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f1eae2a7d4fa7a2dee4643c849ecbeb/href">https://medium.com/media/5f1eae2a7d4fa7a2dee4643c849ecbeb/href</a></iframe><p>And at last the fun part. We can build and run a <a href="https://developer.apple.com/documentation/xcode/running_your_app_in_the_simulator_or_on_a_device"><strong>simulation</strong></a> of our app in Xcode to see our model in action. In the example below, I’ve created a simulation using the iPhone 12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*gHl_seOHITgT4hv2vdV5fg.gif" /><figcaption>Simulation of your model running on iOS</figcaption></figure><h4><strong>Conclusion</strong></h4><p>And that’s it! Our initial prototype is complete. There’s plenty left to be done such as model validation, tests to confirm expected performance after import to iOS and a sleeker/more friendly UI. Nonetheless, I hope this serves as a useful reference for your mobile machine learning deployment endeavors.</p><p>New and improved tools continue to make mobile pursuits more widely accessible to the data science community and there are many creative opportunities waiting to be claimed in the mobile space. As mobile technology is inherently multi-media, it provides a richness of data types (e.g. audio, video, movement and location) along with unique point of use applications to expand one’s data science toolkit.</p><p>As always, I welcome any feedback or suggestions.</p><p>Thanks for reading!</p><h4><strong>Resources</strong></h4><p><em>CoreML</em></p><ul><li><a href="https://developer.apple.com/machine-learning/models/">Models - Machine Learning - Apple Developer</a></li><li><a href="https://coremltools.readme.io/docs/introductory-quickstart">Quickstart Example</a></li></ul><p><em>iOS Deployment</em></p><p><a href="https://developer.apple.com/documentation/xcode/distributing_your_app_to_registered_devices">Apple Developer Documentation</a></p><p><em>SwiftUI</em></p><p><a href="https://www.hackingwithswift.com/quick-start/swiftui">SwiftUI by Example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d006b1e04bc4" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/deploy-a-python-machine-learning-model-on-your-iphone-d006b1e04bc4">Deploy a Python Machine Learning Model on your iPhone</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Python and R With Julia]]></title>
            <link>https://medium.com/better-programming/using-python-and-r-with-julia-b7019a3d1420?source=rss-bd0bff93b38f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7019a3d1420</guid>
            <category><![CDATA[julia]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Patrick Long, PhD]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 18:05:44 GMT</pubDate>
            <atom:updated>2021-02-01T18:05:44.982Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick intro to Julia’s PyCall and RCall packages</h4><figure><img alt="Rotary telephone" src="https://cdn-images-1.medium.com/max/1024/1*HSqhgqRosDqkxHc7OPQJEg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@meeuwesen?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">M.S. Meeuwesen</a> on <a href="https://unsplash.com/@meeuwesen?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>.</figcaption></figure><p>Great! So you’re venturing into the promising world of <a href="https://julialang.org/">Julia</a> but still want access to your familiar friends Python and R. While the benefits of Julia are best realized by operating purely in Julia, it’s reassuring to know that there are several ways to integrate your Python or R skills into your workflow while setting out.</p><p>Both Python and R can be invoked within Julia by using either the <a href="https://github.com/JuliaPy/PyCall.jl">PyCall</a> or <a href="https://juliainterop.github.io/RCall.jl/stable/gettingstarted/">RCall</a> packages. The simplest way to see these packages in play is by making use of their respective approaches<strong> </strong>to converting strings of Python or R into Julia-accessible operations and functions. For those familiar with Python, this is akin to using <a href="https://www.programiz.com/python-programming/methods/built-in/eval">eval</a><strong> </strong>for single-line/single-expression code or <a href="https://www.programiz.com/python-programming/methods/built-in/exec">exec</a> for multi-line/multi-expression code.</p><h3>PyCall Hello World</h3><p>To begin with Python, we’ll take a look at PyCall by running the following within the Julia REPL:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d279cafc4a34ee49804c91a851357dd/href">https://medium.com/media/0d279cafc4a34ee49804c91a851357dd/href</a></iframe><p>You’ll note that the output is a Julia type (in this case, String).</p><h3>RCall Hello World</h3><p>Here is the same demonstration using RCall:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52a81323efedb36524e5b73a6791cd0c/href">https://medium.com/media/52a81323efedb36524e5b73a6791cd0c/href</a></iframe><p>RCall outputs in the form of RObjects that can easily be converted to Julia types using the <a href="https://juliainterop.github.io/RCall.jl/v0.7.2/internal.html#RCall.rcopy-Tuple{RCall.RObject}">rcopy</a> method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b57bee53e4894278849bd5473e53d889/href">https://medium.com/media/b57bee53e4894278849bd5473e53d889/href</a></iframe><p>You can pass variables declared in Julia directly into Python or R code with simple syntax. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c84d14659ac5ea09f944c9e47f0e8ff0/href">https://medium.com/media/c84d14659ac5ea09f944c9e47f0e8ff0/href</a></iframe><h3>Loading Local Python Modules</h3><p>One practical use case for interoperability is to take advantage of any custom Python utilities you’ve developed and apply them in Julia. For an ultra-simplistic demonstration, let’s create a Python module that stores our hello_world function and then call it from Julia using PyCall.</p><p>First, create an example module below called mymodule. From the terminal, run:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98c65b456929a6229be790cbf389bd8c/href">https://medium.com/media/98c65b456929a6229be790cbf389bd8c/href</a></iframe><p>You may then import and call mymodule.hello_world<em> </em>from within your Julia REPL. There are a few ways to do so. The first is similar to what we did above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e25a41fa900145e82e119feb406f36b6/href">https://medium.com/media/e25a41fa900145e82e119feb406f36b6/href</a></iframe><p>The second and likely more applicable approach uses PyCall’s pyimport function to directly import your Python module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0aadc58b633cce1e73b5b0ef58489ee5/href">https://medium.com/media/0aadc58b633cce1e73b5b0ef58489ee5/href</a></iframe><h3>Loading Python and R Packages</h3><p>You can also use external Python and R packages. The code below loads the scikit-learn Boston housing dataset and generates a visual with matplotlib while inside the Julia REPL:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa1cfe7efd86b9d150b4d2c62cda0e99/href">https://medium.com/media/fa1cfe7efd86b9d150b4d2c62cda0e99/href</a></iframe><figure><img alt="Graph with crime rate by age info" src="https://cdn-images-1.medium.com/max/1024/1*OCLPjMgcfkkNSA2OPDc1cQ.png" /></figure><p>And if you’d prefer to plot with R’s <a href="https://ggplot2.tidyverse.org/">ggplot2</a> package, you can use RCall’s @rlibrary<em> </em>macro:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4c76c03f3f5d824bf30df2021b86712/href">https://medium.com/media/a4c76c03f3f5d824bf30df2021b86712/href</a></iframe><figure><img alt="Graph with crime rate by age info" src="https://cdn-images-1.medium.com/max/1024/1*uFeeJsE2h77trXGE_sl9Ow.png" /></figure><h3>Conclusion</h3><p>And that’s it. Both PyCall and RCall have much broader functionality to support interoperability with Julia than is demonstrated here. It’s great to see these efforts to facilitate language compatibility and reduce barriers of entry.</p><p>As Julia’s package ecosystem continues to grow, there may be little need to invoke tools from outside languages, but it is nonetheless a convenient stepping stone when getting started.</p><p>Check out PyCall and RCall’s documentation linked below for a deeper dive.</p><p>Thanks for reading!</p><h3><strong>Resources</strong></h3><ul><li><a href="https://julialang.org/">The Julia Programming Language</a></li><li><a href="https://github.com/JuliaPy/PyCall.jl">JuliaPy/PyCall.jl</a></li><li><a href="https://juliainterop.github.io/RCall.jl/stable/gettingstarted/">Getting Started · RCall.jl</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7019a3d1420" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/using-python-and-r-with-julia-b7019a3d1420">Using Python and R With Julia</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>