<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: hannahyan</title>
    <description>The latest articles on Forem by hannahyan (@hannahyan).</description>
    <link>https://forem.com/hannahyan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F344919%2F89fcd887-3210-4296-bf79-25c58dbf33ab.jpg</url>
      <title>Forem: hannahyan</title>
      <link>https://forem.com/hannahyan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hannahyan"/>
    <language>en</language>
    <item>
      <title>Brain-inspired agentic memory</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Sun, 01 Jun 2025 06:58:13 +0000</pubDate>
      <link>https://forem.com/hannahyan/brain-inspired-agentic-memory-4765</link>
      <guid>https://forem.com/hannahyan/brain-inspired-agentic-memory-4765</guid>
      <description>&lt;p&gt;Memory brings stateful continuity to agentic systems. Unlike an infinitely long context window, it evolves and is portable across sessions. It could be short-term or long-term, storing user preferences and abstracted knowledge. But what kind of architectures enables LLM to retain and prioritize information across multiple interactions and sources?&lt;/p&gt;

&lt;p&gt;In the Advanced LLM Agent open course by Berkeley, a neurobiology-inspired long-term memory is introduced. It includes two main components: memory encoding and memory retrieval.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Offline Indexing (Memory Encoding)&lt;/strong&gt;&lt;br&gt;
An instruction-tuned LLM processes a corpus of text and extracts a schemaless knowledge graph (KG) from each passage using Open Information Extraction, treating noun phrases as nodes and their relationships as edges. This KG acts as an artificial hippocampal memory index. Retrieval encoders then enrich the KG by adding edges between semantically similar noun phrases, simulating pattern completion. The result is a unified graph that integrates knowledge across the entire corpus, structurally mirroring the brain's memory formation process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Online Retrieval (Memory Retrieval)&lt;/strong&gt;&lt;br&gt;
When a query is given, an LLM identifies key named entities and matches them to related nodes in the KG. These nodes serve as cues to initiate retrieval. HippoRAG then runs Personalized PageRank (PPR) from these nodes to explore the KG, distributing relevance across connected nodes and mimicking context-based memory recall. Node specificity adjusts the influence of each seed node, favoring more distinctive concepts. The final PPR distribution determines which passages are most relevant based on the density of high-ranking KG nodes they contain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Brain functions&lt;/strong&gt;&lt;br&gt;
These components directly correspond to brain functions: the neocortex handles abstraction, the parahippocampal region manages contextual associations, and the hippocampus serves as the indexing center. By mirroring this division of labor, HippoRAG enables biologically inspired memory retrieval grounded in cognitive science.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros &amp;amp; Cons&lt;/strong&gt;&lt;br&gt;
These systems offer significant advantages: continuous learning without catastrophic forgetting, efficient handling of partial queries, and transparent retrieval processes. With these, it enables multi-hop reasoning in a single retrieval system, with lower latency and cost.&lt;/p&gt;

&lt;p&gt;However, they also present challenges: implementation complexity, resource requirements, and potential scalability issues with extremely large datasets.&lt;/p&gt;

&lt;p&gt;** Reference **&lt;br&gt;
&lt;a href="https://mem0.ai/blog/memory-in-agents-what-why-and-how/" rel="noopener noreferrer"&gt;https://mem0.ai/blog/memory-in-agents-what-why-and-how/&lt;/a&gt;&lt;br&gt;
HippoRAG: Neurobiologically Inspired Long-Term Memory for Large Language Models&lt;/p&gt;

</description>
      <category>multiagent</category>
      <category>agents</category>
      <category>memory</category>
      <category>ai</category>
    </item>
    <item>
      <title>4 tools to boost data science reproducibility</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Tue, 08 Dec 2020 05:27:48 +0000</pubDate>
      <link>https://forem.com/hannahyan/4-tools-to-boost-data-science-reproducibility-4j6b</link>
      <guid>https://forem.com/hannahyan/4-tools-to-boost-data-science-reproducibility-4j6b</guid>
      <description>&lt;p&gt;In a data science project, it's typically important to have reproducibility and minimize manual work. That involves a number of things from config to parameterization. Here are a few tools to improve that workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/pypa/pipenv"&gt;Pipenv&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Before &lt;em&gt;pipenv&lt;/em&gt;, the main way to set up a project would be activating a virtual environment, put all the needed packages in a &lt;em&gt;requirements.txt&lt;/em&gt; and it might also incur some manual work, as &lt;code&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt; would bring in a lot of extra packages.&lt;/p&gt;

&lt;p&gt;The elegant thing about &lt;em&gt;pipenv&lt;/em&gt;, in its own words, is that it "automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages". It feels like npm in the python world.&lt;/p&gt;

&lt;p&gt;So instead of the usual &lt;code&gt;pip install&lt;/code&gt; one would now use &lt;code&gt;pipenv install&lt;/code&gt; within the virtual environments, and there's no need to manually maintain a requirements.txt file anymore.&lt;/p&gt;

&lt;p&gt;However, it goes without saying that if you didn't specify the package version during installation, &lt;em&gt;pipfile&lt;/em&gt; won't carry the version either. Instead, it will show a generic one like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[packages]
pandas = "*"
sklearn = "*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: this is not to be confused with &lt;em&gt;pyenv&lt;/em&gt; which is another library for switching between different versions of python.&lt;/p&gt;

&lt;h3&gt;
  
  
  Makefile
&lt;/h3&gt;

&lt;p&gt;If there are multiple repeated steps in a project, such as setup, format, test, lint, deploy, then a Makefile would concurrently save time for the project owner and make it user-friendly for the users. &lt;/p&gt;

&lt;p&gt;A sample snippet of makefile in combination with the aforementioned &lt;em&gt;pipenv&lt;/em&gt; would look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setup:
    pip install pipenv
    pipenv install
    pipenv shell
format:
    black *.py
    pylint --disable=R,C sample 
all: setup format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And by running one line of script &lt;code&gt;make all&lt;/code&gt;, one can do everything in the makefile – set up a virtual environment, install all the dependencies, auto-format the code, and lint the script to show any unused libraries/variables, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  config.yml + argparse
&lt;/h3&gt;

&lt;p&gt;Sometimes one wants to run multiple experiments in a machine learning project or conduct the same analysis on different datasets. In this case, it would be good to keep the different configurations for each of the inputs instead of overwriting them. One can achieve that by having a configs folder with several config.yml, each containing a set of inputs. And in the main script, one could use &lt;em&gt;argparse&lt;/em&gt; to load the config.yml as a dictionary and then refer to the specific parameters in the config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ArgumentParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;__doc__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"-f"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"--config_file"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;default&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"configs/config1.yml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Configuration file to load."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ARGS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ARGS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'r'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="err"&gt;    &lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;full_load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"Loaded configuration file &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ARGS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config_file&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way, each of the settings is preserved rather than overwritten, and it becomes easier to track the outcome.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/nteract/papermill"&gt;papermill&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If the setup above helps boost productivity and reproducibility for python scripts, then this library is for ipython notebooks, which might be used at the initial stages of the project due to its interactive nature. By defining all the variables/parameters in a cell in ipynb, and create a runner.ipynb, one can specify new parameters and generate a new notebook for each set of these new parameters.&lt;/p&gt;

&lt;p&gt;One can generate a new notebook like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;papermill&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pm&lt;/span&gt;
&lt;span class="n"&gt;pm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute_notebook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="err"&gt;   &lt;/span&gt;&lt;span class="s"&gt;'path/to/input.ipynb'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt;   &lt;/span&gt;&lt;span class="s"&gt;'path/to/output.ipynb'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt;   &lt;/span&gt;&lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ratio&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be handy and time-saving compared to the alternative of duplicate-altering-renaming a set of highly similar, especially a large number of notebooks different only in some variables.&lt;/p&gt;

&lt;p&gt;Overall I find these tools useful in maintaining dependencies, tracking inputs, and reducing repetition. &lt;/p&gt;

&lt;p&gt;Image credit: &lt;a href="https://unsplash.com/photos/dqXiw7nCb9Q"&gt;unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>tooling</category>
      <category>python</category>
    </item>
    <item>
      <title>10 tips for current data science students</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Fri, 15 May 2020 20:56:57 +0000</pubDate>
      <link>https://forem.com/hannahyan/10-pieces-of-advice-for-current-data-science-students-4i7h</link>
      <guid>https://forem.com/hannahyan/10-pieces-of-advice-for-current-data-science-students-4i7h</guid>
      <description>&lt;p&gt;Graduating during the time of quarantine has been a unique experience. As I reflect on the past years, I'd like to share tips and advice for people interested in data science. I hope those are valuable regardless of whether you are pursuing an advanced degree or MOOC in applied data science. &lt;/p&gt;

&lt;h1&gt;
  
  
  1. prioritize your learning plan
&lt;/h1&gt;

&lt;p&gt;Data science is an evolving field that roughly subdivides into 3 subfields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analytics (expect to be well-versed in business lingos and non-technical communication)&lt;/li&gt;
&lt;li&gt;Inference (expect to understand experimentation, causality and statistical modeling)&lt;/li&gt;
&lt;li&gt;Machine learning (expect to know ML/DL algorithms at a deep level. Understand cloud technologies can be helpful too. Might need to specialize in a field such as computer vision or NLP)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes a role might entail a combination of these. Other related fields include data engineering, software engineer, or data visualization.&lt;/p&gt;

&lt;p&gt;Knowing which track you are most interested in can help. Personalized education is not yet a reality, so you might want to DIY a curriculum. Many programs offer independent studies, where you can decide on a project and a lecturer will provide guidance. Another setting I liked is the inversed classroom where students learn from each other and the lecturer play a facilitator role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unique tips&lt;/strong&gt;&lt;br&gt;
Getting into a lab or collaborating with a research team can help develop domain knowledge even if your goal is not research. By default, you are most likely to be dedicated to applied/practical problems. So considering factoring some time for those too.&lt;/p&gt;

&lt;h1&gt;
  
  
  2.Balance exploitation vs exploration
&lt;/h1&gt;

&lt;p&gt;There will be no shortage of learning but a shortage of time. Given the limited energy, you can consider balancing these two to achieve the breadth and depth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;exploitation (do only what you are good at) &lt;/li&gt;
&lt;li&gt;exploration (try a bit of everything else) &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  3. Sharing and communicating
&lt;/h1&gt;

&lt;p&gt;Sharing either concepts or projects are helpful in two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;helps you fortify learning and identify weaknesses.&lt;/li&gt;
&lt;li&gt;your learning journey, thought process, trials and tribulations are helpful to others. You do not have to be the world's top expert before you can share learning or provide advice. Your experience can be valuable for those who yet to have it, and vice versa.&lt;/li&gt;
&lt;li&gt;at work you will notice that verbal, visual, and written communication skills matter as much, if not more, than your Python/R skills. And it is important to communicate the impact in a concise way. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Unique tips&lt;/strong&gt;&lt;br&gt;
If possible, explaining the concepts as simply as possible. There are no shortage of technical papers, but few can explain complex concepts like to 4-year-olds. This is probably why youtube channels like &lt;a href="https://www.youtube.com/c/3blue1brown"&gt;3blue1brown&lt;/a&gt;, &lt;a href="https://www.youtube.com/channel/UCbfYPyITQ-7l4upoX8nvctg"&gt;2 Minute Papers&lt;/a&gt; and &lt;a href="https://www.youtube.com/playlist?list=PL1sJQ3lOys1jXxVgoaRSVJ77twbbRKJX5"&gt;StatsQuest&lt;/a&gt; are popular. Unless your goal is academic publishing, you might want to make it more accessible.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Everyone can have a portfolio
&lt;/h1&gt;

&lt;p&gt;Neither design nor web dev skill should be a hurdle for you to start a portfolio that is uniquely you. I made my first &lt;a href="https://medium.com/@yanhann10/building-a-data-science-portfolio-on-github-io-6abdc8fb0fc7"&gt;portfolio&lt;/a&gt; years ago when I barely know CSS which later &lt;a href="http://www.hannahyan.com"&gt;evolved&lt;/a&gt; a bit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommended tools&lt;/strong&gt;&lt;br&gt;
After I learned more about design and web, I made this table of recommended tools for building a portfolio depending on whether you have design/web dev experience or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HQFFBqgr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r78v4k7ww2mwiw99p9kw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HQFFBqgr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r78v4k7ww2mwiw99p9kw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Two ways of approaching challenges
&lt;/h1&gt;

&lt;p&gt;Before I chose my first elective my advisor asked me if I prefer to ease in or ease out the workload. Two ways of facing challenges and getting un-stuck are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decrescendos: if you habitually solve hard challenges, some day you will find everything easy. This is applicable is you are moving from hard sciences to other fields.&lt;/li&gt;
&lt;li&gt;Crescendos: if the topic at hand is too challenging, find a simpler explanation first. After establishing some foundation, tune up the level. This is applicable in more scenarios.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  6. Plan ahead on stress relief
&lt;/h1&gt;

&lt;p&gt;Learning is a life long journey but life is more than learning. So it is important to find a balance, and seek help early when you stress out. You can plan out different pathways to peace in advance, and deploy them when stress levels go through the roof, as it will happen.&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Get involved in communities and conferences
&lt;/h1&gt;

&lt;p&gt;If you have a local or online community, there are ways to help organize or get involved. If not you can find 2-3 like-minded friends to explore topics of interest and give each other feedback. &lt;/p&gt;

&lt;p&gt;Going to conferences allow you to immerse in different topics and talk to people from different perspectives. Many conferences offer student volunteering opportunities, which come with a free ticket. &lt;/p&gt;

&lt;p&gt;Each conference has its own persona. Last year a lecturer recommended me attend the &lt;a href="http://eyeofestival.com"&gt;Eyeo festival&lt;/a&gt; for data visualization. It is a great sense of community. I then went to Strata Data Conference in NYC, which has a more commercial feel. This year I volunteered at data science conference &lt;a href="https://odsc.com"&gt;ODSC&lt;/a&gt; East, where most speakers are PhDs working in the industry, and quite a few are involved in open-source and open-tech. I've seen other more academic-minded graduate students presenting at conferences like ICML etc.&lt;/p&gt;

&lt;p&gt;For introverts, online conferences might be easier to handle. And organizers are taking efforts to make the online experience immersive. &lt;/p&gt;

&lt;h1&gt;
  
  
  8. Start early
&lt;/h1&gt;

&lt;p&gt;There is a natural tendency to procrastinate.  Strategic procastination might even be conducive to creativity. But the field of data science moves very fast, and there is an influx of people from other fields. There might be PR and economic reason for this. But I also choose to think it is partly because there is a real value in leveraging data to solve organization problems, commericial or social. Taking stock of the competition, you may want to start early in whatever you are doing.&lt;/p&gt;

&lt;h1&gt;
  
  
  9. Own it
&lt;/h1&gt;

&lt;p&gt;In grad school study is largely self-directed. As such you need to be disciplined in owning your progress, ideas and unique contributions. This might be particularly relevant in the post-pandemic virtual new norm.&lt;br&gt;
&lt;strong&gt;Recommended tools&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://clockify.me/apps"&gt;Clockify - a browser plug-in for tracking time&lt;/a&gt;&lt;br&gt;
Evernote for note taking&lt;/p&gt;

&lt;h1&gt;
  
  
  10. Think beyond technicalities
&lt;/h1&gt;

&lt;p&gt;There are often human behind the numbers and algorithms. It is good to be aware of the biases, privacy concerns and consequences. &lt;br&gt;
&lt;strong&gt;Some of the recommended books&lt;/strong&gt; (I've yet to read):&lt;br&gt;
Weapons of Math Destruction&lt;br&gt;
Invisible Women: Data Bias in a World Designed for Men.&lt;/p&gt;

&lt;p&gt;Cover image credit: Photo by Matt Howard on Unsplash&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>beginners</category>
      <category>learning</category>
      <category>career</category>
    </item>
    <item>
      <title>I recently finished Udacity Machine Learning Engineer nanodegree and here’s my experience</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Sun, 03 May 2020 19:13:26 +0000</pubDate>
      <link>https://forem.com/hannahyan/i-recently-finished-udacity-machine-learning-engineer-nanodegree-and-here-s-my-experience-jpk</link>
      <guid>https://forem.com/hannahyan/i-recently-finished-udacity-machine-learning-engineer-nanodegree-and-here-s-my-experience-jpk</guid>
      <description>&lt;p&gt;I want to know more about how to deploy ML algorithms in a web app. And that prompted me to enroll in this course.&lt;/p&gt;

&lt;p&gt;The course assumes certain prior foundation and focuses on how to use AWS Sagemaker.&lt;/p&gt;

&lt;h1&gt;
  
  
  An ultra-compressed guide for Sagemaker
&lt;/h1&gt;

&lt;p&gt;Sagemaker is a development platform for ML practitioners.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ease of deployment: it enables real-time inference and batch transformation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variety: It offers both high- and low-level API as well as pre-built models on Marketplace. The SageMaker autopilot offers automatic build, train, and tune functionalities for tabular data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auto-scaling: The model runs on container clusters, enabling it to deliver high availability.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The environment is akin to ipynb with a somewhat different workflow and syntax. Data are often read in from S3 after serialization. One can also optimize the models by targeting certain recall, or specifying the imbalance treament. &lt;/p&gt;

&lt;p&gt;One can either load a prebuilt model, or create a training object called Estimator. After training, one can deploy the model endpoint as a predictor and run inference on it. It's also important to delete the endpoint after training since they charge by the time in use.&lt;/p&gt;

&lt;h1&gt;
  
  
  Topics and Projects
&lt;/h1&gt;

&lt;p&gt;The syllabus is very well structured. Here are the main topics covered and the related project built.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How data scientists can leverage DevOps principles. It has a section covering how to make a python package – including testing, logging, and uploading to PyPI. This came in handy later on when I built a &lt;a href="https://github.com/yanhann10/afprop"&gt;clustering package&lt;/a&gt; with a statistician teammate. The package has the advantage of not having to pre-specifying the number of clusters over KMeans.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to deploying models as API endpoint. The corresponding project I completed is a &lt;a href="https://github.com/yanhann10/sagemaker_plagiarism_detector"&gt;plagiarism detector&lt;/a&gt;. It was trained and deployed on Sagemaker, invoked via lambda and API gateway.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to plan a project end-to-end. The program contains a capstone with a few recommended options and a customized option. One needs to write a proposal of project plan before proceeding, and then submit the project with a report. I find the rubric of the report detailed and insightful. The corresponding project I did is &lt;a href="https://github.com/yanhann10/deep_learning_use_cases/tree/master/which_dog_breed"&gt;dog breed classifier&lt;/a&gt; with dataset containing 133 types of dogs. It could be a good starting point for other image-related applications. Taking a spin from the original Kaggle competition, if supplied an image of a human face as detected by openCV, it will also identify the resembling dog breed. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What’s unique
&lt;/h1&gt;

&lt;p&gt;Overall I had a positive experience. After submitting the project, one can receive some quick and detailed feedback. There are forums where one can discuss with TA or help each other out.&lt;/p&gt;

&lt;p&gt;What stood out is that they also provide the rare offering of provide Github and Linkedin review. I received a few helpful feedback on Github usage, including suggestions on writing commit message in the style of:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;feat: a new feature&lt;br&gt;
fix: a bug fix&lt;br&gt;
docs: changes to documentation&lt;br&gt;
style: formatting, missing semicolons, etc; no code change&lt;br&gt;
refactor: refactoring production code&lt;br&gt;
test: adding tests, refactoring test; no production code change&lt;br&gt;
chore: updating build tasks, package manager configs, etc; no production code change&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While I like the style, I think the it can be further expanded to the data science context. Common code chunks such as feature selection or model interpretation won't fit in to either feat or chore.&lt;/p&gt;

&lt;h1&gt;
  
  
  How does it compare with graduate-level courses
&lt;/h1&gt;

&lt;p&gt;What’s unique about Udacity is that it is very pertinent to the industry and the materials are continuously updated. The videos are clearly explained, highly digestible, with extra readings and resources. And  they involve significantly less mathematical derivation. All the projects are hands-on. &lt;/p&gt;

&lt;p&gt;Usually university courses on machine learning don't cover deployment, so this is more like a mixture of a machine learning and a AWS cloud computing course with a small dose of software development.&lt;/p&gt;

&lt;p&gt;Another difference is that its program typically has a product tie-in. The MLE program, for example, is tied-in with the commercial software from AWS. In classroom setting, on the other hand, courses tend to be more vendor-agnostic, and could cover AWS, GCP, Azure across the board.&lt;/p&gt;

&lt;p&gt;These products, after all, are only means to an end. Tools change, techniques evolve, but thought process and knowledge stays. It is more important to understand the field on both theoretical and practical grounds than simply mastering the tools in the field. This might not necessarily be a downside, as long as one can transfer the learning onto other cloud platforms.&lt;/p&gt;

&lt;h1&gt;
  
  
  Who is it suitable for
&lt;/h1&gt;

&lt;p&gt;The program is for someone who already had a first course in ML and intermediate Python skills, and wants to learn deployment/production. I did it during the free month and appreciate the fact that they have such a program.&lt;/p&gt;

&lt;h1&gt;
  
  
  What's next
&lt;/h1&gt;

&lt;p&gt;I find it helpful to understand the entire ML workflow, which may potentially expand the kind of personal projects I can do.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>aws</category>
      <category>github</category>
    </item>
    <item>
      <title>Getting started in building &amp; deploying interactive data science apps with Streamlit - Part 2</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Tue, 10 Mar 2020 04:40:43 +0000</pubDate>
      <link>https://forem.com/hannahyan/getting-started-in-deploying-interactive-data-science-apps-with-streamlit-part-2-3ob</link>
      <guid>https://forem.com/hannahyan/getting-started-in-deploying-interactive-data-science-apps-with-streamlit-part-2-3ob</guid>
      <description>&lt;p&gt;After building a data science app, we want to make it accessible instead of gathering dust in a code dump.&lt;/p&gt;

&lt;p&gt;In the previous &lt;a href="https://dev.to/hannahyan/getting-started-in-building-and-deploying-interactive-data-science-apps-with-streamlit-6ab"&gt;post&lt;/a&gt;, we used Streamlit to quickly spin up a slick-looking app with straightforward Python script, and not even a single line of React.js. Next, we will go over several methods of deployment: hosting it on Heroku, containerizing it with Docker, plus running it from Github direct as an easy way to share.&lt;/p&gt;

&lt;h1&gt;
  
  
  🍳Prerequisite
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;A Github/Gitlab account&lt;/li&gt;
&lt;li&gt;The files in this &lt;a href="https://gist.github.com/yanhann10/e0cde1215722732b82fa195b19511394"&gt;gist&lt;/a&gt; covered from the previous post&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  ☁️Deployment
&lt;/h1&gt;

&lt;p&gt;Among the several deployment options, I find Heroku one of the most beginner-friendly. Before we start, we need to register an account on Heroku, install its CLI, and create a project folder on its UI with a preferred folder name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosting on Heroku
&lt;/h2&gt;

&lt;p&gt;Two additional files from the Gist are needed in the project folder.&lt;/p&gt;

&lt;p&gt;Procfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: sh setup.sh &amp;amp;&amp;amp; streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;setup.sh&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/.streamlit/

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
[general]&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
email = &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;your-email@domain.com&lt;/span&gt;&lt;span class="se"&gt;\"\n\&lt;/span&gt;&lt;span class="s2"&gt;
"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.streamlit/credentials.toml

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
[server]&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
headless = true&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
enableCORS=false&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
port = &lt;/span&gt;&lt;span class="nv"&gt;$PORT&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.streamlit/config.toml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thereafter in your local terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are working from your local repo, you could skip the git init part.&lt;br&gt;
Then followed by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku git:remote -a &amp;lt;heroku_project_name&amp;gt;
git add .
git commit -am “&amp;lt;commit message&amp;gt;”
git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now instead of only having the app in your local browser, you have a live url to share. It resembles .herokuapp.com.&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Tips and Tricks
&lt;/h3&gt;

&lt;p&gt;Like most cloud platforms, Heroku has the function of auto-deploy through Github integration, under the Deploy tab. It's good to test the code beforehand.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eSsNZ-st--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s1g8db1l57bbxpkw2dtx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eSsNZ-st--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s1g8db1l57bbxpkw2dtx.png" alt="auto screenshot"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deploy with Docker via GCP or AWS cloud services
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Why Docker
&lt;/h3&gt;

&lt;p&gt;While you could have other users git clone your repo and run it locally, they might run into all sorts of issues - such as installing certain packages, or some wrong version might throw everything off, or they could be on a different operating system. All the things you don't want to see happening after all that work. Having the app/code easily accessible &amp;amp; reproducible also can makes it easier for conducting user testing and gather feedback.&lt;/p&gt;
&lt;h3&gt;
  
  
  Two main concepts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Container: a Docker container encapsulates an application together with the packages and libraries it requires to run&lt;/li&gt;
&lt;li&gt;Image: a snapshot of a container&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Getting ready
&lt;/h3&gt;

&lt;p&gt;To begin with, we can register a DockerHub account and create a repo there. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T--KK70J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lrjnhmvqmx8thb2erou8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T--KK70J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lrjnhmvqmx8thb2erou8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two options – public and private, are very similar to Github's options. One could grant access to specific people for their private repo. For now, we will create a public one for demo purpose.&lt;/p&gt;

&lt;p&gt;Next you will need a &lt;a href="https://docs.docker.com/engine/reference/builder/"&gt;Dockerfile&lt;/a&gt;, such as this &lt;a href="https://gist.github.com/yanhann10/e0cde1215722732b82fa195b19511394#file-dockerfile"&gt;one&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Now we are ready to Dockerize the app, there are just a few key commands to know. Since Docker/Kubernetes (the thing that orchestrates multiple Dockers) can get complex, it is better to start from the bare essentials.&lt;/p&gt;

&lt;p&gt;I prefer to work from GCP cloud console or AWS cloud9 so I don't need to install Docker, but you can work from local terminal if you already have Docker installed. &lt;/p&gt;
&lt;h3&gt;
  
  
  Main commands
&lt;/h3&gt;

&lt;p&gt;In cloud console, choose a project, clone a repo if you have the code on Github or upload the project folder.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It will prompt for Docker Hub username and password.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build --tag=&amp;lt;DockerHub Account Name&amp;gt;/&amp;lt;DockerHub Repo Name&amp;gt;:0.0 .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You could specify a version number or use latest. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You should be able to find the image you just built under REPOSITORY&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Push
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image push &amp;lt;DockerHub Account Name&amp;gt;/&amp;lt;DockerHub Repo Name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next you will see the latest version has been reflected in Docker Hub. Clicking the public view on the right, you will be able to share the url and others should be able to pull it.&lt;/p&gt;
&lt;h3&gt;
  
  
  💡 Tips and Tricks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Better to use a dash instead of underscore in the docker tags&lt;/li&gt;
&lt;li&gt;If you want to keep your Dockerfile clean and tidy, you can use Hadolint which is a Dockerfile linter and also add this to the make file hadolint streamlit_demo/Dockerfile&lt;/li&gt;
&lt;li&gt;To save the hassle of having to push to Docker Hub after every update, you can click on Builds &amp;gt; Configure Automated Builds and connect to your Github.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fln4dMD8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ov6xpjnw7fogcuxzsuiz.png" alt="github connect"&gt;
&lt;/li&gt;
&lt;li&gt;Instead of running several commands for each project, you can save them in a bash file called run.sh and then run &lt;code&gt;sh run.sh&lt;/code&gt; to execute all the commands.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;dockerpath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"change this to &amp;lt;DockerHub Account Name&amp;gt;/&amp;lt;DockerHub Repo Name&amp;gt;"&lt;/span&gt;
&lt;span class="c"&gt;#log in&lt;/span&gt;
docker login
&lt;span class="c"&gt;#build&lt;/span&gt;
docker build &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$dockerpath&lt;/span&gt;:latest &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="c"&gt;#push&lt;/span&gt;
docker image push &lt;span class="nv"&gt;$dockerpath&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Running the app directly with Github url
&lt;/h2&gt;

&lt;p&gt;The 3rd method is to share the Github url link of your app.py, under the condition that app.py is all the file you need to run the app and you have no other dependencies such as data files or helper scripts etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit run &amp;lt;app.py github url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And see the app in action. However, this method doesn't bring alone the csv files in your folder. So the previous 2 methods are still the most solid for sharing your apps.&lt;/p&gt;

&lt;p&gt;Yet another option is that Streamlit will offer its own deployment solution. When that happens, it would be the most convenient solution for Streamlit. But deployment methods we covered earlier are still applicable to all kinds of apps and scripts beyond Streamlit (some tweaking might be needed in the config files).&lt;/p&gt;

&lt;h2&gt;
  
  
  ⌛Wrap-up
&lt;/h2&gt;

&lt;p&gt;Today we reviewed how to use Docker to containerize Streamlit app and how to deploy it to Heroku. You could also deploy it to GCP/AWS/Azure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional useful resources&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/streamlit/streamlit/wiki/FAQ"&gt;Streamlit wiki&lt;/a&gt; - links to articles on GCP/AWS/Azure deployment&lt;br&gt;
&lt;a href="https://github.com/dylanlrrb/Please-Contain-Yourself"&gt;Please contain yourself&lt;/a&gt; - Clear &amp;amp; thorough explanation of how Docker works in a series.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/photos/AM53LSIBnRo"&gt;Cover photo credit&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>beginners</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Getting started in building and deploying interactive data science apps with Streamlit - Part 1</title>
      <dc:creator>hannahyan</dc:creator>
      <pubDate>Sun, 08 Mar 2020 04:59:47 +0000</pubDate>
      <link>https://forem.com/hannahyan/getting-started-in-building-and-deploying-interactive-data-science-apps-with-streamlit-6ab</link>
      <guid>https://forem.com/hannahyan/getting-started-in-building-and-deploying-interactive-data-science-apps-with-streamlit-6ab</guid>
      <description>&lt;p&gt;Flask used to come to mind when data scientists want to spin up a python-based data science app, but there is a better option now. To create an interactive facade for a machine learning or visualization script, Streamlit is way faster, since it removed the need to write any front-end code. &lt;/p&gt;

&lt;p&gt;Now we 'll go through step-by-step how to build a Streamlit app. I will also review some pros and cons of Streamlit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is this for
&lt;/h2&gt;

&lt;p&gt;Anyone who wants to put an interactive user interface or visible facade to the python scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;Python knowledge&lt;/p&gt;

&lt;h2&gt;
  
  
  What can it do
&lt;/h2&gt;

&lt;p&gt;Streamlit can be used to built machine learning/AI apps or display exploratory/analytical data visualizations or both at the same time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkynviiqxqx8n5a2bvg6u.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkynviiqxqx8n5a2bvg6u.gif" alt="YOLO gif"&gt;&lt;/a&gt;&lt;br&gt;
Image credit: Streamlit&lt;/p&gt;
&lt;h2&gt;
  
  
  ⛵ Getting started
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Hello world
&lt;/h3&gt;

&lt;p&gt;To get started, first install the library&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a folder called streamlit_demo (or your preferred name) and add an app.py file to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt;
&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello world&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In terminal cd into the folder and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;streamlit&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see these in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F27p4ldw8gn04614azrcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F27p4ldw8gn04614azrcj.png" alt="code screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now a browser window will automatically open up and you have the first app up and running🎉&lt;/p&gt;

&lt;p&gt;Next we can start to add UI components, which are treated as variables in app.py, add this snippet to understand what that means.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkbox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;show&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My first app&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some of the common UI components include radio button, checkbox, selectbox, slider, and text input can be found in this &lt;a href="https://docs.streamlit.io/api.html" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have a basic idea of how this works, we can start reading data and make a simple plot. The data and code for the following sections can be found in this &lt;a href="https://gist.github.com/yanhann10/e0cde1215722732b82fa195b19511394" rel="noopener noreferrer"&gt;gist&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;st&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;


&lt;span class="c1"&gt;# header
&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;London Bikes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subheader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Numuber of Trips starting from Hyde Parker Corner&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# read data - source: London Bicycle Hires from Greater London Authority on Google Datasets via Bigquery
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;london_bikes.csv&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c1"&gt;# area plot
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;start_day&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;start_date&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;
&lt;span class="n"&gt;df_trips_by_day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;start_day&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;value_counts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;area_chart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df_trips_by_day&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using Streamlit's built in charting function, we made our first plot in a few lines of code, and it's interactive and downloadable!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl63ozhglc1w39ykggq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl63ozhglc1w39ykggq1.png" alt="Number of bike trips by day"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Going one step further, one can visualize the destinations of all the trip started from Hyde Park Corner.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp114vvxg7np3a87pp9ac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp114vvxg7np3a87pp9ac.png" alt="arc plot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Tips and Tricks
&lt;/h3&gt;

&lt;p&gt;As one adds libraries and functions to the app, it becomes more important to organize the dependencies in one place. A nifty trick to make things easier is to create Makefile and requirements.txt. As an option, we can create these two files to make the workflow easier.&lt;/p&gt;

&lt;p&gt;Requirements.txt list out the packages needed for the app to run&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw0q07gbegm5rxklt37iz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw0q07gbegm5rxklt37iz.png" alt="pkgs screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Makefile offers a recipe on how to properly set up the app. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg8bgdawa00b2hd3nnzol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg8bgdawa00b2hd3nnzol.png" alt="code screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, when you run make install, it will automatically install all the dependencies.&lt;/p&gt;

&lt;p&gt;Now that we had a glimpse of the functionalities of Streamlit, we can weigh it against other frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚖️Pros and Cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Streamlit has a long list of pros which I love:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Accessible app making for everyone (who uses Python)&lt;/em&gt;. This is the main draw, since it can save time by allowing one to focus on the data science aspect, and also suits those who may not want to learn HTML/CSS. The learning curve is fairly flat.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Cover most common UIs needed in a data app. Plus, they look good!&lt;/em&gt; It contains slider, checkbox, radio buttons, a collapsible side bar, progress bar, file upload, etc. Overall these functionalities and the ease of use are impressive. It would be even nicer if can have an information button next to certain components to offer further explanations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Support multiple interactive visualization libraries&lt;/em&gt;. It supports libraries such as &lt;a href="https://plot.ly/" rel="noopener noreferrer"&gt;plotly&lt;/a&gt;, &lt;a href="https://www.altair.com/" rel="noopener noreferrer"&gt;altair&lt;/a&gt;, &lt;a href="https://docs.bokeh.org/en/1.0.0/" rel="noopener noreferrer"&gt;bokeh&lt;/a&gt;, &lt;a href="https://vega.github.io/vega-lite/" rel="noopener noreferrer"&gt;Vega-Lite&lt;/a&gt;, and &lt;a href="https://medium.com/vis-gl/pydeck-unlocking-deck-gl-for-use-in-python-ce891532f986" rel="noopener noreferrer"&gt;pydeck&lt;/a&gt;. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1tfc7nyiuz9zy6s7dlj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1tfc7nyiuz9zy6s7dlj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
And here are some other libraries it's compatible with.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbzcppr06gim2um24o8en.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbzcppr06gim2um24o8en.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And since it's python-based, one can run some ml algorithm in the same app and then plot charts on the output of algorithm, such as cluster or classification labels.&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Tips and Tricks
&lt;/h3&gt;

&lt;p&gt;To view more UI chart components in action, this &lt;a href="https://fullstackstation.com/streamlit-components-demo" rel="noopener noreferrer"&gt;demo app&lt;/a&gt; is a good place to start where you can view both the chart and code side-by-side.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some cons:
&lt;/h3&gt;

&lt;p&gt;I shall start off by saying none of these cons is prohibitive. They are more of a good-to-have and are listed here to keep a balanced evaluation of the tool&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Convenience vs flexibility&lt;/em&gt;. Not specific to Streamlit, the higher level a framework is, the less customization it tends to provide. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In streamlit's case, one cannot customize the layout currently (but it's on their roadmap), which makes it not the most suitable choice for complex dashboards that require container-like layout. Streamlit layout mainly consists of a big vertical panel and a small side panel. One cannot really position 2 different charts side-by-side, or add custom elements in any specified locations. If you want to customize everything, you might have to use React.js/Vue.js.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Size of data input&lt;/em&gt;. Streamlit has a soft limit of 50MB for data upload. I will be interested in How the framework enables large scale application going forward.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Limited support for video/animation&lt;/em&gt;. No native support for video format and no play button. This can limit certain use case involving video analysis and animation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Last but not least, one needs to be aware that it is focused on DS/ML use cases, thus will not offer the full suite of functionalities that Flask/Django have. This might not necessarily be a con, having a focus could a good thing. It simply means if one wants to build apps with other functionalities such as user authentication, newsletter subscription, or user-to-user interaction, then it's better to look elsewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⌛ Wrap-up
&lt;/h2&gt;

&lt;p&gt;Streamlit is simple enough such that everyone can use it. It can be a superb option if you need a quick solution for an interactive data app, especially with both machine learning algorithm running in the background and interactive plots. Hopefully today we had some fun building data science apps. In a future &lt;a href="https://dev.to/hannahyan/getting-started-in-deploying-interactive-data-science-apps-with-streamlit-part-2-3ob"&gt;post&lt;/a&gt;, we'll cover how to deploy it to the cloud and containerized it using Docker.&lt;/p&gt;

&lt;p&gt;For more information, these resources might be useful. &lt;br&gt;
&lt;a href="https://github.com/marcskovmadsen/awesome-streamlit" rel="noopener noreferrer"&gt;awesome-streamlit&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.streamlit.io/gallery" rel="noopener noreferrer"&gt;streamlit gallery&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>machinelearning</category>
      <category>webdev</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
