<?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 James Opacich on Medium]]></title>
        <description><![CDATA[Stories by James Opacich on Medium]]></description>
        <link>https://medium.com/@jamesopacich?source=rss-faee93b62ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1PWNkXA-vHyIwuJUQ2ALgw.png</url>
            <title>Stories by James Opacich on Medium</title>
            <link>https://medium.com/@jamesopacich?source=rss-faee93b62ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:43:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesopacich/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[Simulating A Real-world SQL Environment]]></title>
            <link>https://medium.com/geekculture/simulating-a-real-world-sql-environment-63784f7f37ae?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/63784f7f37ae</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Tue, 25 May 2021 23:57:18 GMT</pubDate>
            <atom:updated>2021-05-27T06:42:59.683Z</atom:updated>
            <content:encoded><![CDATA[<h4>A tutorial using PostgreSQL, pgAdmin 4 and the Pagila Dataset.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*Y78dbrH1oiAbc0m1Ws2xQQ.jpeg" /><figcaption>Postgres is an open-source project under a liberal Open Source license. <a href="https://www.postgresql.org/about/licence/">You can find the PostgreSQL licence here</a></figcaption></figure><p>The following tutorial will walk you through the following tasks:</p><ol><li>Download PostgreSQL and pgAdmin 4 to your own PC or environment.</li><li>Connect to PostgreSQL server</li><li>Download and load the Pagila database set (based on the famous Sakila training database).</li><li>Provide resources and a link to a Github repository detailing these steps. The data and the question sets will be included.</li></ol><p>As I quickly worked through many different methods for teaching myself SQL I began to notice that very few of them truly embody the real-world feel of using the database querying language in the wild. I also felt a longing to understand the deeper relationships between SQL and whichever database management system (DBMS) it was being used in. This lead me to the thought that certainly there is a dataset out there somewhere that will allow me to create a real-world environment to practice in. To my joy, there was. Sakila was created to train people in MySQL and shortly afterward Pagila was created to train new users in PostgreSQL. I will go over later where I found and how I used the Pagila data. You can also find a link to it under the movie film image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w535MNUQFoQEtG7yaqJRg.jpeg" /><figcaption>The Pagila Database is a copy of the Sakila database and is designed more specifically for Postgre SQL learning. You can find the version of the database that I used here: <a href="https://github.com/devrimgunduz/pagila">Pagila Database by Devrim Gündüz</a>. There is another Github repository that may also be helpful found here: Pagila by <a href="https://github.com/xzilla">Robert Treat</a>.</figcaption></figure><p>The Pagila Database is a simulated set of tables that would mimic the operations and data of a chain of video stores. Think of Blockbuster Video circa 1990’s. At first glance the use case of a video store may not seem very relevant in a post-Blockbuster world yet I assure you that this dataset still does relatively well mimicking many retail environments or environments where there is revenue, customers, and products.</p><h3>1. Let’s Get Started: Downloading PostgreSQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*c79hz9KYk_HcbEtgdsL0Tg.png" /><figcaption><a href="https://www.postgresql.org/download/">Download PostgreSQL</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTw9SY7NnXr-Ark_rYoFLQ.png" /><figcaption>I downloaded the Mac installer from EDB for PostgreSQL Version 13.3 here: <a href="https://www.postgresql.org/download/">PostgreSQL 13.3 from EDB</a></figcaption></figure><p><a href="https://www.postgresql.org/download/">Download PostgreSQL </a>. You can do this a number of ways (all of which are featured in the link). I chose to use the interactive installer by EDB but there may be some options that are easier and in fact better. If I took the time to do this all over again I would likely choose the postgres.app instead. The postgres.app install not only allows for a simple download and install but may even have a more intuitive GUI than pgAdmin 4. nonetheless, pgAdmin works just fine and if you’re into command line usage I believe all of these implementations also allow SQL on CLI.</p><ul><li>I’m using Mac so I downloaded the <a href="https://www.postgresql.org/download/macosx/">installer from EDB.</a> Installer will save an image to your computer that will open up a folder.</li><li>Click on the folder and an installer will pop up. Follow the prompts.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*xP7oV_HycyCFOPbHk1rcWQ.png" /><figcaption>You can see the You can see the PostgreSQL 13.2–2 image file in the top left of this pic. Click on that box with the arrow going right and then the PostgreSQL 13.2–2 app image (bottom-left of pic) will pop up. Click on that disk-drive looking file and the installer will open up. Follow the prompts on the setup wizard. Click “Next”.</figcaption></figure><p>During the installation a prompt will come up asking you to select your locale. This is where you set up cultural preferences including language. It is <strong>important to select the right locale. </strong>If you’re in the U.S. for instance you will select en_US.UTF-8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*Xw6s2C1EHQwIOzAj1Qrt4A.png" /><figcaption>It is important that you select the right locale here. If in United States then select the one pictured above.</figcaption></figure><ul><li>The installer will then show you a summary of your install configurations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*i0mZJqvx8R6vlLBMf0FrwQ.png" /><figcaption>Pre-install summary. Your configurations should look fairly similar.</figcaption></figure><ul><li>Click Next to install.</li></ul><h3>2. Setting up Postgre SQL Server</h3><p>There is a really nice tutorial walking you through Postgre SQL Server setup located here: <a href="https://www.postgresqltutorial.com/connect-to-postgresql-database/">Connect to a PostgreSQL Server Database.</a> OR you can follow my quick and less thorough instructions below.</p><h4>Two Ways to Connect on Mac (App-based or Terminal-based)</h4><p><strong>Terminal Based Server Connection (Using psql)</strong></p><p>One way to connect, especially if you love using command line, is to use the psql SQL shell.</p><ol><li>For terminal based you will need to open up the psql app that should have been downloaded as part of the PostgreSQL package in the previous steps. This will open up a SQL Shell. On mac I just type “psql” in the search bar or you can go to the application folder and find it there.</li><li>Then you will enter Server name, Database name, Port, your username and your password. You can also press the Enter key and default values will be filled in. The default values are displayed in brackets next to each prompt.</li><li>Lastly, you can interact directly with the PostgreSQL Database Server by writing a SQL statement. The below statement shows all of your databases in PostgreSQL. There is usually just a template database in there to start.</li></ol><pre>\l </pre><p><strong>Application Based Server Connection (Using pgAdmin 4)</strong></p><p>You can also use pgAdmin 4 web-app. This allows you to connect and interact with PostgreSQL database server via a user-friendly GUI.</p><ol><li>Launch the pgAdmin application. Again, I just used the search bar in my mac but you can also find it via command line and in the applications folder.</li><li>One tutorial I had seen said that pgAdmin will open in a web-browser but when I opened it pgAdmin actually opened in its own app on the Mac dock.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jptb6rOx-FU1L0EEZgJ7Iw.png" /><figcaption>When you launch pgAdmin it will open in its own application window on Mac. It will look something like this.</figcaption></figure><p>3. Right click on “Servers.” and select <strong>Create &gt; Server</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*CNwMRkkZuts9tmCTIMQ0pQ.png" /><figcaption>This will create a server in pgAdmin 4</figcaption></figure><p>4. Enter server name (whatever you want it to be)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*9oEYjy9FdLHWOtqF3WQO7Q.png" /><figcaption>I used “test_postgreSQL” as my server name. After this step click the “Connection” tab up top.</figcaption></figure><p>5. Click the connection tab and enter host and password. This is the username and password you created in the PostgreSQL installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*7zlx31835t6y-wf-5t6nHg.png" /><figcaption>This will be the username and password you created in the PostgreSQL installation process.</figcaption></figure><p>6. Expand the servers cluster and then the databases node and you will see a default database called postgres already installed. Ignore the Pagila database in the image below. I had already downloaded it so it shows an unconnected database there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*FWVsjQM7qZBNkRKIKplp8w.png" /><figcaption>Ignore the pagila database here. I already had it installed at time of pic.</figcaption></figure><p>Once you’ve navigated to the desired database you can click on it and then click on the query tool. You can do this two ways. Clicking on the “Tools” drop down and then the “Query Tool” option or by clicking on the icon that looks like databases with a “play” logo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaYAMgrtWiqNZm1Uugydeg.png" /><figcaption>diagram describing how to access and use the query tool</figcaption></figure><p>7. Enter a query into the editor and click the execute button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*GjqqdxSgtxc1q7LLr-E6uA.png" /><figcaption>Click execute button to run query. Result will output below in the Data Output field.</figcaption></figure><h3>3. Download and Load The Pagila Database</h3><p>There are two good githubs that I found which house the Pagila Database. I used the <a href="https://github.com/devrimgunduz/pagila">Pagila Database by Devrim Gündüz</a>. It was the first one I found that had the database and clear instructions on what it was and how it works. If you are into using containerized environments he also has a tutorial for implementing the database in Docker. In this process I am assuming you already have a github account and know how to use git. If you do not then you can <a href="https://github.com/join">create a github account here</a> and familiarize yourself with <a href="https://guides.github.com/">github tutorials</a>.</p><h4>Fork Repository</h4><p>copy the https or ssh link from the repository to clone it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*JJQAZ-q0TV_P_zz9kt7Ppg.png" /><figcaption>This will create a forked copy of this repository into your own github repository. It will also navigate the page to your new forked repository.</figcaption></figure><h4>Clone Repository</h4><p>You can see in the image that the repository address in the top left of the screen is now my repository. From your forked repository you will clone the repository down to your PC. Click on code and copy the https or SSH url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*qrnrNJQhP0T-dTe1_FELOQ.png" /><figcaption>Copy the url from the code button. You will insert this into the command line to create a local repository on your own computer.</figcaption></figure><p>Start a new command line terminal. You can do this by typing terminal in the search bar on Mac or In the Finder you can open the /Applications/Utilities folder, then double-click Terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*OjtHLN_mnEc8Ronw.png" /><figcaption>Finder</figcaption></figure><p>Once terminal is open you can navigate over to the folder/directory where you would like to store the Pagila directory. Learn how to navigate through command line here: <a href="https://computers.tutsplus.com/tutorials/navigating-the-terminal-a-gentle-introduction--mac-3855">Navigate Through Command Line</a>. You will then copy the link into the command line within the desired directory and a new directory will be created that houses all of the pagila database files that were housed in github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*mWNG4NDzPqE1o17DR73MEg.png" /><figcaption>I chose to save my directory into a folder/directory that I call projects.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*tdUic_GuQ8TUfsvjCUAsDw.png" /><figcaption>The ```ls``` command lists out all the files in my new Pagila directory.</figcaption></figure><p>At this point you will now have a Pagila directory that houses the Pagila databases on your own computer. We will not pull the Pagila files into PostgreSQL server using pgAdmin 4. Before doing this I strongly recommend reading the <a href="https://github.com/devrimgunduz/pagila">README.md</a> file in Devrim Gündüz’s Pagila github repository.</p><h4>Create a New Database in pgAdmin 4</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*sk5C5dbTHr00HB6d2G4M7g.png" /><figcaption>Right click on “Databases”, click “Create” and then “Database”.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*pgMBSvyQzMpAi1oSIATpyQ.png" /><figcaption>Name your database, I named mine “test_pagila.” Click on the save button.</figcaption></figure><p>At this point a new database should show up under the Databases heading in the left broswer. Click on the new database (in my case it is test_pagila), then click on the query tool, go into the new query editor and find the file icon in the top left of the editor and then click on that to search for your Pagila SQL files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_3akWamaqfQZoHk_uNOmw.png" /><figcaption>These are the steps you will take to find your Pagila SQL files.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*EJAg3E797XKRd__TKrBCrg.png" /><figcaption>Choose the pagila-insert-data.sql file and click select</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*e4CTFVX1msRFXqvRv9CatA.png" /><figcaption>The schema and data for the database will autofill into the query editor. Click the run icon and you should see a message that says “ALTER TABLE” below in the Data Ouput box.</figcaption></figure><p>Now your database has been created. You can run queries and use this for whatever purposes you now desire. Happy querying!</p><h3>4. Resources for Using Pagila</h3><p>There are many ways to train with The Pagila Database. You can spin up your own queries and use it any way you would use a real-world database or you can use question sets that quiz you on your abilities to query using realistic data and data-structures. This repository from <a href="https://github.com/xzilla">Robert Treat</a> is extremely helpful. It contains Pagila setup info and files as well as many links to Pagila tutorials to various tasks such as building applications from Pagila data, using REST API, performing email validation, creating reports and building rails to legacy apps.</p><p>I have also scoured the internet to find all kinds of questions (with solutions in most cases) pertaining to Pagila and Sakila and compiled them into a group of Jupyter Notebooks. You can use these questions to test your abilities as well. Find them here:</p><p>I also created an Entity Relationship Diagram (ERD) using Pagila. You can find my tutorial for this here: <a href="https://jamesopacich.medium.com/creating-a-sql-entity-relationship-diagram-erd-ced5ad1239d0">Creating a SQL Entity Relationship Diagram</a> (ERD) and the actual ERD image for your reference below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42D6ZEMHTa_SviOUwnnAsw.png" /><figcaption>Pagila ERD generated by pgAdmin 4</figcaption></figure><p>Also, I garnered much of my information to perform this task from these sites:</p><ul><li><a href="https://github.com/devrimgunduz/pagila">Devrim Gündüz Github</a> Devrim is a major contributor to PostgreSQL. This is the database file I used in this tutorial.</li><li><a href="https://github.com/xzilla/pagila">The Pagila Project Page on Github</a> I found this one after I already started creating this tutorial but this is possibly the creator of Pagila. I’m not sure. But the creator of this project seems to be a major open-source contributor to a variety of projects.</li><li><a href="https://www.postgresqltutorial.com/connect-to-postgresql-database/">Connect to a PostgreSQL Database</a> This is the resource I used to connect to the PostgreSQL database. This site <a href="http://www.postgresqltutorial.com/">Postgresqltutorial.com </a>is also a helpful resource for other PostgreSQL information.</li><li><a href="https://www.postgresql.org/download/)">PostgresSQL Official Site</a> This is where I downloaded PostgresSQL.</li><li><a href="https://programmaticponderings.com/2019/08/09/getting-started-with-postgresql-using-amazon-rds-cloudformation-pgadmin-and-python/">Getting Started with PostgreSQL using Amazon RDS, CloudFormation, pgAdmin, and Python</a> This is a resource I didn’t use but something I want to use at some point. This tutorial combines PostgreSQL with Amazon AWS services to create a dual purpose learning experience.</li></ul><p>I hope you enjoyed this tutorial and it helped you get started with Postgres and Pagila. If you have any questions or spot anything that needs clarification please message me on Medium. You can also find much of this information on Github: <a href="https://github.com/JamesRonsonOp/SQL_Training_with_Pagila">SQL_Training_with_Pagila by James Opacich</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63784f7f37ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/simulating-a-real-world-sql-environment-63784f7f37ae">Simulating A Real-world SQL Environment</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a SQL Entity Relationship Diagram (ERD)]]></title>
            <link>https://medium.com/geekculture/creating-a-sql-entity-relationship-diagram-erd-ced5ad1239d0?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/ced5ad1239d0</guid>
            <category><![CDATA[entity-relationship]]></category>
            <category><![CDATA[postgressql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[erd]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Tue, 25 May 2021 23:55:59 GMT</pubDate>
            <atom:updated>2021-05-27T06:42:55.850Z</atom:updated>
            <content:encoded><![CDATA[<p>Using PostgreSQL and Pagila Database to practice creating and using ERDs</p><ol><li>Using pgAdmin 4 and PostgreSQL this article will demonstrate how to Create an Entity Relationship Diagram (ERD) of the Pagila Database to gain a greater understanding of the data you will be working with and to create a reference for which to work off of.</li><li>There will display two separate methods for ERD creation. One is manually done and is much more time intensive but a better learning experience, the other is automatically done by pgAdmin 4 and is orders of magnitude faster and easier for those that are just looking for an ERD to reference when using the Pagila Database.</li><li>There will be links to the necessary information, github repositories and completed ERD for your reference.</li></ol><h3>PRE-NOTE (If you want to create an ERD fast then read this)</h3><p>When I initially tried to create an ERD using pgAdmin 4 I clicked on the “New ERD Project” option in the Tools dropdown and it gave me a blank grid to work off of. Because of that I actually had to manually create each table, row, and constraint in the diagram and it took me hours. The next time I attempted to create an ERD I first right-clicked on the database I wanted to work with and instead chose “Generate ERD” and initially it still appeared that I had a blank ERD to start with but when I zoomed out I noticed that an ERD was already created for me and it included all of the accurate table names, row names, constraints and relationships. <strong>In the end what had previously taken me hours to complete now only took me 30 seconds.</strong></p><p>That being said, I found it very useful to create my own ERD manually. It got me thinking about the process, the data types, constraints, and relationships in a way that I felt further solidified my knowledge of SQL.</p><h3>PREREQUISITES</h3><p>This tutorial assumes you already have PostgreSQL, pgAdmin 4, and The Pagila Database installed and set-up. If you need instructions on setting this up please visit my previous article: <a href="https://jamesopacich.medium.com/simulating-a-real-world-sql-environment-63784f7f37ae">Simulating A Real-world SQL Environment.</a></p><p>Please have pgAdmin 4 open at this point and your database ready to use.</p><h3>STEPS FOR CREATING ERD AUTOMATICALLY</h3><h3>STEP 1: Generate ERD tool</h3><p>This is a Beta tool in pgAdmin 4 version 5.0.</p><h4>Generate ERD</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*no2QRoisIwd8wPgm4nUgTA.png" /><figcaption>Right-click on your database. I have called my database Pagila in this case. Then find the “Generate ERD” option on the drop down list.</figcaption></figure><p>This will open a new window in pgAdmin 4 located where the query window would normally be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YVi98WTGB9vdSWUXy3RKzg.png" /><figcaption>Here a new ERD window and tab are created. This is where the ERD will be created.</figcaption></figure><h3>STEP 2: Save and Name Your ERD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HlO7SLkCje2HPocPXbqZcA.png" /><figcaption>Step 1: Click on this icon to open up the save file browser/box</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*-m4A5-u_dgCLLhm5SGmANg.png" /><figcaption>Step 2: Name your ERD by typing your desired name into the end of the file path. Then click Create to save the named file. I decided to name my ERD pagila_erd3 for this exercise.</figcaption></figure><h3>STEP 3: Export Your ERD</h3><p>The ERD is a bit difficult to zoom in and move around within pgAdmin 4 so I found it more helpful to export it to an image file for easier referencing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*W2JjVTaE6eU1iBos734QFQ.png" /><figcaption>Click on the “Download Image” icon, it will bring up a file browser where you can name your new image file and save it to a desired file on your computer.</figcaption></figure><h3>MANUALLY CREATING YOUR OWN ERD</h3><p>To manually create your own ERD the very first step is different.</p><h3>STEP 1: CREATE NEW ERD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*hs_HuPhMm03sgICd7mnSGA.png" /><figcaption>Instead of clicking on the database name and then selecting to generate a new database you will instead click on the “Tools” dropdown at the top of the pgAdmin app window and select “Create New ERD.”</figcaption></figure><h3>STEP 2: Save and Name Your ERD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tqXkTGy1u4CCdjc-6sexQ.png" /><figcaption>You will see now that you will have a blank ERD Window to work from.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HlO7SLkCje2HPocPXbqZcA.png" /><figcaption>Step 1: Click on this icon to open up the save file browser/box</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*-m4A5-u_dgCLLhm5SGmANg.png" /><figcaption>Step 2: Name your ERD buy typing your desired name into the end of the file path. Then click Create to save the named file. I decided to name my ERD pagila_erd3 for this exercise.</figcaption></figure><h3>STEP 2: Create Your First Table</h3><p>In this step we will create the table diagrams for the ERD. These boxes contain the table, column, constraint and key information for each table in your database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*SCvII2uXSsGSN-VUTuuQRQ.png" /><figcaption>Click the plus-sign icon to add a table.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ts9K0vDklWLyWiLf5g6Rng.png" /><figcaption>Name your table and click on the column tab.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*noeiIoWEcyvh2ALLPDfKmw.png" /><figcaption>Click on plus sign to add column and constraints</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*m0k3aaT5nhW3FrpEWuQ2nQ.png" /><figcaption>Enter in your column names, data-types and basic constraints here and hit ok to create the table diagram. If you want to dive deeper into constraints then click on the pencil icon next to each column.</figcaption></figure><h4>IN CASE YOU WANT TO GET DEEPER WITH CONSTRAINTS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*_ymKlTH8SrryPR6Y64z1Wg.png" /><figcaption>There is a definitions tab although this doesn’t seem to add any additional functionality.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*ZvHDMellpfhWP5Rp173Xpg.png" /><figcaption>The constraints tab does seem to add a few more parameters to add to your diagram.</figcaption></figure><h3>STEP 3: Creating Relationships</h3><p>To complete your ERD you need to create relationships between tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*7oD2vojrM2hYBUsayNZ6kA.png" /><figcaption>To create a 1 to many relationship highlighting foreign key relationships click on the 1M icon. This will open a form for you to select columns corresponding to the tables and relationships you want to create.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*fNvwcYpNe-WC5R5DjAV1Ng.png" /><figcaption>To create a many-to-many relationship click the MM icon and a form will open allowing you to do the same as the previous picture.</figcaption></figure><p>You have now created an ERD. I recommend practicing by recreating from scratch the Pagila Database ERD. You can check your work by simply creating an automated ERD as outline above. I also have corralled a bunch of question sets here in my <a href="https://github.com/JamesRonsonOp/SQL_Training_with_Pagila/tree/main/pagila_question_sets"><strong>Pagila Questions Sets</strong></a><strong> repository </strong>that will help you fine-tune your querying skills.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ced5ad1239d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/creating-a-sql-entity-relationship-diagram-erd-ced5ad1239d0">Creating a SQL Entity Relationship Diagram (ERD)</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classification Metrics for Beginners]]></title>
            <link>https://jamesopacich.medium.com/classification-metrics-for-beginners-6e27a5eb4749?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e27a5eb4749</guid>
            <category><![CDATA[confusion-matrix]]></category>
            <category><![CDATA[sklearn]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[classification-metrics]]></category>
            <category><![CDATA[classification-algorithms]]></category>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 08:55:31 GMT</pubDate>
            <atom:updated>2021-02-09T08:58:47.777Z</atom:updated>
            <content:encoded><![CDATA[<h4>With a function to make it easier to produce and analyze them</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4LKhO9YXUFvzfAJ7vFMtw.jpeg" /></figure><p>With most classification problems a simple accuracy score just will not cut it. Because of this there are many different metrics available to data scientists who are looking to identify how well their model is working. There are benefits and drawbacks with having a plethora of measuring tools at your disposal. The good thing about this is that there is a score for pretty much every problem statement. The bad thing is that there are so many metrics it is often daunting and even confusing to choose them and figure out what they all mean. I will attempt to simplify that situation a bit.</p><p>I will detail many of the classification metrics I have come across as a new data scientist. In doing so I hope to define what each metric is measuring and identify a situation in which they would work well.</p><h4>THE CONFUSION MATRIX</h4><p>To get all of the metric scores you must start with calculating the Confusion Matrix. The name of this matrix is aptly named. It can be a bit bewildering sometimes to use it. That being said, it is fundamental to use this in data science. Also, rest assured, once you get the hang of it the confusion dissipates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*ZSf03SLrAzxvz-Irnmfu1Q.png" /></figure><p>Populating the Confusion Matrix is relatively easy and I like to have it charted out for me just for reference. This will be done with Scikit-Learn in a further step but I would like to give a rudimentary example of calculating the matrix first.</p><p>If we made 100 predictions on whether or not a coin flip was heads or tails this is how we would calculate the following:</p><p><strong>Positive (P)</strong>: Positive observation. | Heads</p><p><strong>Negative (N):</strong> Negative observation. | Tails</p><p><strong>True Positive (TP):</strong> Positive observation that is correctly predicted to be positive.</p><p><strong>False Positive/Type I Error (FP):</strong> Negative observation that was incorrectly predicted to be positive.</p><p><strong>True Negative (TN):</strong> Negative observation that was correctly predicted negative.</p><p><strong>False Negative/Type II Error (FN):</strong> Positive observation that was incorrectly predicted to be negative.</p><p>Let’s further our example and actually populate the matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*QtDhZBOzhIjoAUGqFCHpMw.png" /><figcaption>Actual Observations for Example Above. This is not a confusion matrix. We will produce the confusion matrix for these numbers below.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*lNjtvTlzCInuiWVefCKMYw.png" /><figcaption>Predicted Observations for Example Above. This is not a confusion matrix. We will produce the confusion matrix for these numbers below.</figcaption></figure><p><strong>Positive (P)</strong>: 60</p><p><strong>Negative (N):</strong> 40</p><p><strong>True Positive (TP):</strong> 45</p><p><strong>False Positive/Type I Error (FP):</strong> 0</p><p><strong>True Negative (TN):</strong> 40</p><p><strong>False Negative/Type II Error (FN):</strong> 15</p><p>These numbers would produce the following Confusion Matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*YNbF2baQZidUcn-Ve775cQ.png" /></figure><p><strong>Sklearn’s Confusion Matrix</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*xyVuBTqA4HGnFSh7kreTnQ.png" /><figcaption>imports for both the confusion matrix and the function that plots the confusion matrix. Note: you do not need to run confusion_matrix function in order to run plot_confusion_matrix function. You can just go right to plotting the confusion matrix. Sklearn <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html">confusion matrix documentation</a>.</figcaption></figure><p>Before you run the Confusion Matrix you need to do all the things you would normally do prior to running a model, run the model and then calculate the models predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*XRvlTMJWL3ng1qAOyYFJ4w.png" /><figcaption>Sklearn function that runs just the confusion matrix and returns an array.</figcaption></figure><p>To unpack the matrix in order to put it into a Pandas dataframe you must ravel() the matrix first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*EFsk03h4sW4b72OqUtm2DA.png" /><figcaption>Here we are doing a few things. We are unpacking the true positives, true negatives, false positives and false negatives and we have also raveled the matrix so that we can unpack these values from the tuples that they are contained in. If we do not ravel you will get a shape of 2 X 2 instead of 4 x 1 and you will not be able to unpack the values from the matrix.</figcaption></figure><p>You can also create a DataFrame from the matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*m4V2_S4JnkLPgnJo4P4b1g.png" /><figcaption>Creating a dataframe of confusion matrix values ends up looking a lot like an actual confusion matrix.</figcaption></figure><p>Lastly, you can plot the confusion matrix as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*mbdpcq-hyzwYxzN4CBFOqQ.png" /><figcaption>Confusion Matrix Plot from <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.plot_confusion_matrix.html#sklearn.metrics.plot_confusion_matrix">Sklearn</a>.</figcaption></figure><h4><strong>THE MOST POPULAR CLASSIFICATION METRICS</strong></h4><p><strong>Accuracy</strong></p><p>Accuracy is the most basic metric. It is the percentage of observations (all of the predictions) that were correctly predicted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6N-le455XDd6orvj5Uy4NA.png" /></figure><p><strong>Sklearn Accuracy Score</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*gkiLA-wCx6uk9TX3ngqcyA.png" /><figcaption>Code Example from <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html">Sklearn’s Documentation</a></figcaption></figure><p><strong>Misclassification Rate</strong></p><p>The amount of incorrect predictions among all observations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*L5VqHq8hBGlbm5N01hOu9Q.png" /></figure><p><strong>Sensitivity/Recall/True Positive Rate (TPR)</strong></p><p>This one has a lot of names. Be careful, it can get “confusing.” The ratio of actually positive instances that are correctly predicted to be positive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*l-DM-km7X2FN-SDdtdenWg.png" /></figure><p><strong>Sklearn Recall Score</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*Lg2bydSxLjDSO__cCjLEyQ.png" /><figcaption>Code Example From <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html?highlight=recall#sklearn.metrics.recall_score">Sklearn’s Documentation</a></figcaption></figure><p><strong>Precision/Positive Predictive Value</strong></p><p>the number of correct predictions among all observations that were predicted positive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*od8Nms_nfXdHr5PDsxRUBg.png" /></figure><p><strong>Sklearn Precision Score</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Q9dkIXJ_qd16h8IIr3E_qw.png" /><figcaption>Code Example From <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html?highlight=precision#sklearn.metrics.precision_score">Sklearn’s Documentation</a></figcaption></figure><p><strong>Specificity/True Negative Rate (TNR)</strong></p><p>How many were correctly predicted among all observations that were actually negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*WxE_0_Y7YRpqhcJ48_O6eA.png" /></figure><p><strong>F1 Score</strong></p><p>Typically when you report precision you also report recall because they are mutually important. So if someone tells you they got a higher precision for example, you should almost always ask them “at what recall?” Conversely, if someone tells you they increased recall then ask them how the precision score was affected. To make this situation simpler, however, there is a score called F1 score. It is the harmonic mean of precision and recall. You’re essentially combining precision and recall into a single metric. The harmonic mean gives much more weight to low values and as a result will only be high if both recall and precision are high.</p><p>Note: It is not always necessary to have both metrics scoring at a high level. Sometimes precision is the metric you most care about and at other times recall is the metric that is most important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*Wmy6bO99wbQRF0WQvgQ9jQ.png" /></figure><p><strong>Sklearn’s F1-Score</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*zHcjerkjLwR0dtNhuJjwAQ.png" /><figcaption>Code Example From <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html?highlight=f1%20score#sklearn.metrics.f1_score">Sklearn’s Documentation</a></figcaption></figure><p><strong>A Series of Functions Producing a DataFrame of Metrics</strong></p><p>Below is a function I created to ultimately produce a dataframe including all scores for multiple classifier models. Feel free to use and adapt it. I included a one more scores than what is detailed here. It is called the Balanced Accuracy Score. It can be computed like this in python.</p><p><strong>balanced_accuracy = 1/2 * (recall_score + (tn/total_pred))</strong></p><p>Step 1. Define your classifiers and compose them into a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*K9tmT5mqW1ni997Li4jkwA.png" /></figure><p>Step 2. Create the function to instantiate models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*wI4pgPKhzP61jOd23rzsuQ.png" /><figcaption>Fitting and Scoring the Classifiers on both Train and Test Sets.</figcaption></figure><p>The output will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*2lK2TKaeWtJbOo4Ju2ItyA.png" /><figcaption>Output of the above function</figcaption></figure><p>Step 3. Create Predictions on Test Data and form them into a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*P7Z5CJH4RjVQBcmvfErqDA.png" /><figcaption>Creating predictions on test data and forming into a list</figcaption></figure><p>Step 4. Create Metric Scorer Function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*gXLqvl8Mhrjyig4_AbgmDg.png" /><figcaption>Function that creates a dataframe of metrics for a variety of models that you choose. I calculated many of these scores manually using python but you can use the Sklearn functions for some of these as well.</figcaption></figure><p>Step 5. Call the function and analyze the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*AFY6ODirBrC2Fv5yK5Nnzg.png" /><figcaption>Dataframe detailing classification metrics for a variety of models of my choosing. This was ouputted from the custom function created above.</figcaption></figure><p>Step 6. I will not detail this step in this article but you will want to interpret the results and produce visuals like ROC AUC curves to further analyze your results.</p><p>I hope this helps and you enjoy my custom function. I know there are a million ways to do things and likely simpler ways than what I have created above so if you have tips please message me on medium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e27a5eb4749" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Display a Kepler.gl Map]]></title>
            <link>https://jamesopacich.medium.com/display-a-kepler-gl-map-69d807dae082?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/69d807dae082</guid>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 01:07:05 GMT</pubDate>
            <atom:updated>2021-02-09T19:01:36.729Z</atom:updated>
            <content:encoded><![CDATA[<h3>Display a Kepler.gl Map Using Jupyter Notebook</h3><h4>An interactive 3D geospatial tool</h4><p>At this point in the early stages of my career in data science I haven’t worked with geospatial data to a large degree. In fact, it almost appears to me that some data scientists try to avoid working with geospatial data with the intent of leaving it to GIS professionals who focus their life’s work toward understanding geospatial relationships and producing geospatial frameworks, models and visualizations for real world use. That being said, there are definitely moments in data science when the use of geospatial data is necessary and important. Insights detailing the blurred boundaries of data science, GIS and cartography can be found here: <a href="https://ui.adsabs.harvard.edu/abs/2019AbICA...1..403W/abstract">Towards Spatial Data Science</a> and <a href="https://carto.com/what-is-spatial-data-science/">What is Spatial Data Science?</a>.</p><p>Many libraries have been created to help data scientists specializing in fields outside of geospatial information to bridge the gap in understanding and implementation of geospatial relationship modeling and visualization. Geopandas and Shapely are among the many that are frequently piece-mealed together in Jupyter Notebooks to create good geospatial visualizations highlighting important geographical data. Some more libraries and frameworks are detailed here in this article, <a href="https://chrieke.medium.com/essential-geospatial-python-libraries-5d82fcc38731">Essential Geospatial Python Libraries</a> and this article as well <a href="https://gisgeography.com/python-libraries-gis-mapping/">10 Python Libraries for GIS and Mapping</a>. Yet, since the field is changing rapidly I think it is important to check out this Towards Data Science rip also. <a href="https://towardsdatascience.com/the-best-new-geospatial-data-science-libraries-in-2019-7f0174e2a0eb">The Best New Geospatial Data Science Libraries in 2019</a>. This article details one of my favorite new frameworks in all of data science, <strong>Kepler.gl.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*D2JsypSwJbaE5nukc6izbw.png" /><figcaption>An image detailing the many libraries and frameworks available for data scientists working with geospatial data. Note: This is not an exhaustive list. Image Source <a href="https://carto.com/what-is-spatial-data-science/">https://carto.com/what-is-spatial-data-science/</a></figcaption></figure><h4>KEPLER.GL (Geospatial Framework Made For Data Scientists)</h4><p>Very simply, Kepler.gl is a quick way to create 3D interactive maps using geospatial data. It is an open-source geo-analytics tool developed and maintained by Uber’s data science team. It piggybacks on top of the WebGL data visualization framework called Deck.gl. Similar to Deck.gl, Kepler.gl uses a layered approach to data visualization that hastens the pace at which you can garner insights and present your data.</p><p>Kepler.gl was developed specifically for use by data scientists, or anyone for that matter, that are not particularly focused on GIS. The visualization is a quick way for non-GIS data scientists and visualization professionals to create interactive maps from geospatial data. The use of Kepler.gl has made Exploratory Data Analysis all the more enjoyable for me.</p><h4>OPEN-SOURCE AND DEVELOPED BY UBER FOR REAL USE</h4><p>Kepler.gl was developed by Uber Data Scientists for real world use-cases. It is an open-source framework and is available as part of Uber’s <a href="https://vis.gl/">Vis.gl</a> suite of industrial-grade data visualization tools. You really don’t have to think about the other part of Uber’s visualization suite when working with Kepler.gl in a Python environment but it is helpful to know that you can easily embed it into React-Redux applications if you have the desire and aptitude to deploy it to the web.</p><p>Kepler is used at Uber for real applications. They use it as the map component in several of their dashboarding apps and allow their developers to manipulate Kepler and add other components based on their custom needs.</p><p>They have designed this framework knowing that Geo-analytics is usually highly domain-specific and abstract but with the goal of making this resource approachable for data visualization beginners and non-technical practitioners.</p><h4>BEYOND 2D</h4><p>Kepler.gl does something different than just the 2D x and y plane plots that data scientists are used to working with. It introduces a third dimension that adds depth to go with the highly interactive functionality of the tool. With height or altitude features enabled, users can more quickly identify outliers in the data.</p><h4>TWO WAYS TO USE KEPLER.GL</h4><ol><li><strong>Their Webpage at </strong><a href="http://kepler.gl/"><strong>Kepler.gl</strong></a></li></ol><p>Here you will find some quick links that can make you dangerous in short time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTxAnjsLIro5UpQRMTVIzA.png" /><figcaption>Kepler.gl grid plot with height attribute enabled</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*JjoXz3xPQdH_Up-4z-7Gmw.png" /><figcaption>Kepler.gl homepage. You can click on the Get Started link to upload data right to their web interface and start using. Or you can click on the documentation or User Guide for more advanced info. You will also find info on how to implement Kepler.gl in a Jupyter Notebook by clicking on the Documentation and User Guide. <a href="http://kepler.gl/">Kepler.gl</a></figcaption></figure><p><strong>2. Jupyter Notebook Library</strong></p><p>It is not the easiest task to find the Jupyter Notebook implementation of Kepler.gl on their site. To save you some time here is the link to it: Kepler.gl <a href="https://docs.kepler.gl/docs/keplergl-jupyter">Jupyter Notebook Documentation</a>.</p><p><strong>Geopandas and Geometry Objects Not Necessary</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*zvslNS6Q9yUde8AMsRxu_w.png" /><figcaption>Figure 1.0 — Layer Attributes</figcaption></figure><p>Initially I was under the impression that geopandas was a necessary import for the conversion of latitude and longitudinal coordinates to a geometry object but I was wrong. Kepler.gl works well, at least in my case, while using latitude and longitude. Kepler offers different layer attributes based on different source objects. Figure 1.0 details the layer attribute options available. With just one latitude and one longitudinal coordinate for each record you are able to do 3D Grids, 3D Hexbins, Clusters and Heatmaps. You can see in figure 1.2 the type of map that can be quickly created using the Hexbin layer and adjusting its height attribute. In figure 1.3 you can see how you can zoom in and look at statistics using a tooltip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*gAJsJQKu94a02NbF-Uos7Q.png" /><figcaption>Figure 1.2 — A 3D Hexbin Map of Accident Data in the State of California.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*bWND3syqndMs340x1z5ZBg.png" /><figcaption>Figure 1.3 — You can also zoom in and see individual bins. You can get quite a bit of details from these tooltips. Here I just have the total accident count for this bin displaying. The colors of the bins indicates mean accident severity for each bin.</figcaption></figure><p>With a geometry object you can do other types of layers. Figure 2.0 uses a polygon layer but you can also use geometry objects to create a trip map. In Figure 1.4 I use the polygon layer to highlight the accident data for the entire country. I didn’t play with this feature too much so I didn’t create a map color-coded state by state but it is possible. I just wanted to highlight again, the use of the tool-tip and the amount of data that can be included in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*g49zfIdV-PyZwohloS45BQ.png" /><figcaption>Figure 1.4</figcaption></figure><p>There are other types of data you can use as well. I haven’t played with them yet so I can’t provide too much info but I do know that you can add layers that include your own objects like 3D buildings and cars and If you have Hex Id information you can create H3 maps.</p><h4>CAUTION ON JUPYTER LAB IMPLEMENTATION</h4><p>There is some documentation regarding Jupyter Lab implementation but when I attempted to utilize Jupyter Lab I had no success. The visualizations would not render and display in Jupyter Lab. There may be work arounds that I am unaware of but once I stopped using Jupyter Lab and began using Jupyter Notebook the interactive maps worked seamlessly.</p><h4><strong>DATA FRIENDLY</strong></h4><p>Kepler will allow you to upload CSV, Json, GeoJSON or a saved map Json. There is also support for other file formats but they do not work with the same fluidity. These data options work for both the online user-interface and the Jupyter Notebook version. However, I think it’s best to use CSV files for Jupyter notebook because they are smallest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*K-JQbJhQyG8bFQXaRx5qrw.png" /></figure><h4><strong>CAUTION ON BIG DATA</strong></h4><p>Right on their front page Kepler.gl is advertised as a tool for use on large data sets. This is true but probably only to the extent of my own abilities, hardware and software. I was using the <a href="https://www.kaggle.com/sobhanmoosavi/us-accidents">U.S. Accident DataSet </a>housed on Kaggle. It has over 4 million records and is gigabytes of data large. When initially attempting to use Kepler.gl, and precisely because it was advertised to work on large data sets, I added the entire dataset into Kepler.gl within my Jupyter Notebook. This procedure was very computationally expensive and felt a bit like performing a moderately complex grid-search. It took somewhere around 30 to 40 minutes to complete. I did this two or three times with Jupyter Lab before figuring out that if I switch to Jupyter Notebook I would be able to actually succeed in displaying the map. Needless to say, it can be quite frustrating taking all this time just to get something up and running. For your sanity, attempt to work with a smaller dataset in the outset (which I should have done) as you are likely going to make some initial mistakes which will cost you some time. Kepler.gl works very well in a Jupyter Notebook environment using about 500,000 or less records or about 100MB of data. These models will display in your Jupyter Notebook and produce output html files that are about 50MB and will smoothly run locally hosted in your web browser. I haven’t yet truly attempted to implement these visualizations on the web but in the consideration of using StreamLit there may be some size limitation and other challenges there. Again, if you are familiar with React this can be done with that framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*JLIbXk4-YX2NfT5k2HTXeA.png" /><figcaption>A point plot and tool-tip detailing accident data</figcaption></figure><p><strong>JUPYTER NOTEBOOK WORKFLOW</strong></p><ol><li><strong>Imports</strong></li></ol><p>In addition to standard imports, you will also import Kepler.gl and if you need to convert any data to geometry objects you will import geopandas as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*bg61PbK-W8aXeA3VGcr9nQ.png" /><figcaption>Imports</figcaption></figure><p>2.<strong> Read In Data</strong></p><p>This is also a good time to limit your DataFrame to only columns you want to use. You need to slim down your data as much as possible to ensure the best operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*FOFe7Vd6twQu7cIR2cLRoA.png" /><figcaption>Read in Data</figcaption></figure><p>3. <strong>Convert to GeoDataFrame if you need a Geometry Object</strong></p><p>This is not necessary but if you want to highlight anything requiring a geometry object this is a necessary step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*_nJR4NTG-5ZAZvKl5la3Ew.png" /><figcaption>GeoDateFrame Conversion</figcaption></figure><p>4. <strong>Instantiate a Kepler.gl map object</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*ZamosofNJ_dKIUHLd8Q6-w.png" /><figcaption>Instantiating Kepler.gl Map Object</figcaption></figure><p>5. <strong>Add data to Kepler.gl map object</strong></p><p>The data parameter is taking in either the Pandas or Geopandas Dataframe you would like to visualize. The name parameter can be any name you would like to give your dataset. It will show up inside the map on the tool-tip.</p><p>Note: You can do this one time if your data is slim enough. This is the case in Example 1. ‘map_ca’ is the Kepler.gl map object that I instantiated above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*kvZlXDdeo7JgXHI59EnQCw.png" /><figcaption>Example 1. Adding Data to Kepler.gl Map Object</figcaption></figure><p>You can also add more data to the map like in Example 2. You can add data as many times as you like. Although, you will experience severe lag’s when using the interactivity and long loading times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*WsMt9xqVLbvYFQcMl6d4fQ.png" /><figcaption>Example 2. Adding Data multiple times to Kepler.gl Map Object. Be careful, too much data will make you wait and compromise fluidity of the interactive map.</figcaption></figure><p>6. <strong>Display Kepler.gl in Your Jupyter Notebook</strong></p><p>‘map_ca’ is the Kepler.gl map object that I then added data to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*j-tOVCdyUXBKsZN8nEy74g.png" /><figcaption>Displaying And Using Kepler.gl Within Jupyter Notebook</figcaption></figure><p>7. <strong>Save Configuration File</strong></p><p>If you want to save a configuration after playing with all the interactive features and their settings in order to preserve the state of the map as you created it you can copy the config file to your Jupyter Notebook and save it with your Kepler.gl html object that we will create in the next step.</p><p>Go the curly brackets, click on them and click copy. This will copy the json file. This step is circled in red below. After copying it, paste it into a cell in your Jupyter Notebook and save it to a variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*Ml00TdyZB8ojrZLTtSQkvA.png" /><figcaption>Copy Config File</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*IobC10BSlgW2KdXLhabCSA.png" /><figcaption>Creating a Variable to House Your Config JSON (Note: this will take up some space in the notebook) There are other options for doing this without taking up space in your notebook but this is the simplest.</figcaption></figure><p>8. <strong>Save Your Kepler.gl Map to HTML file.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*EeJINt3V8WtBUErDlQXjNg.png" /><figcaption>Saving Kepler.gl Map Object to HTML</figcaption></figure><p>Congratulations! After following these few steps you have quickly configured, displayed and saved a Kepler.gl map object in Jupyter Notebook. If you have any questions, suggestions for improvement or otherwise please feel free to message me on Medium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69d807dae082" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interpreting Scattertext: a seductive tool for plotting text]]></title>
            <link>https://medium.com/data-science/interpreting-scattertext-a-seductive-tool-for-plotting-text-2e94e5824858?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e94e5824858</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[scatter-plots]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[scattertext]]></category>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 00:58:16 GMT</pubDate>
            <atom:updated>2021-05-26T13:29:47.800Z</atom:updated>
            <content:encoded><![CDATA[<h3>Interpreting Scattertext: A seductive tool for plotting text</h3><blockquote>Scroll down to see how to interpret a plot created by a great tool for comparing two classes and their corpora.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdrqMURvbkj1oNZgbepGJg.png" /><figcaption>I will show you below how to interpret this. -image by author</figcaption></figure><p>There are a few good ways to visualize text data, but many good ways to visualize other forms of data. Text data is messy and requires a vast amount of cleaning before it can be analyzed and visualized. This isn’t all bad; there are a tremendous amount of decision-making opportunities to be had during the preprocessing phase. A wide variety of tools and techniques exist to keep you adaptable regarding the data you are working with. This variety can make an otherwise mundane process quite fun. However, once you begin to prepare visualizations on your corpus data, the options diminish pretty rapidly. In this stage you are often left with very few intuitive visualizations to analyze and present your data. This problem compounds particularly if you are presenting to a non-technical audience.</p><p>Luckily, as a relatively new student in the world of data science, I was able to stumble upon an extraordinarily useful tool for visualizing and analyzing text from a corpus. This tool is specifically meant to analyze data with 2 categories. <a href="https://arxiv.org/pdf/1703.00565.pdf"><strong>Scattertext</strong></a> is a tool developed on the back of Scatterplot, the age-old cartesian coordinated plotting tool used by many to visualize the relationship between two variables. Scattertext was created by <a href="https://github.com/JasonKessler/scattertext"><strong>Jason Kessler</strong></a> who has gained quite a bit of notoriety for his work in developing this resource. He abundantly demonstrates the capabilities of Scattertext to data interested audiences through many <a href="https://www.youtube.com/watch?v=H7X9CA2pWKo">trade shows</a> and video presentations. He also has created a detailed and easy to read <a href="https://arxiv.org/pdf/1703.00565.pdf">whitepaper</a> on the topic that I found to be quite helpful in understanding this tool and just how powerful it can be for a data professional to have in their tool kit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*hhsVg6zdmlR2rpHf6tQVDA.png" /><figcaption>A side note: I find it remarkable how new this resource is. This is a reddit post from Jason Kessler 3 years ago. He graciously responded to a comment and received no upvotes. Not enough people seemed to be paying attention to his creation at the time. Find the post <a href="https://www.reddit.com/r/LanguageTechnology/comments/5olmab/scattertext_a_tool_to_make_sexy_visualizations_of/">here</a>.</figcaption></figure><h3>Scattertext Plot (Example Below)</h3><p>Below is a Scattertext plot that I created to give you a quick idea of how beautiful this resource is. This plot details text pulled from two separate Subreddits: <a href="https://www.reddit.com/r/Homebrewing/">r/Homebrewing</a> and <a href="https://www.reddit.com/r/winemaking/">r/Winemaking</a>. The data was cleaned to remove null values, spammed ads, duplicate posts and entries where ‘[deleted]’ or ‘[removed]’ was a value in the post. The data was also preprocessed by removing symbols, numbers, whitespace and stop-words. Based on what I’ve read about Scattertext, many of these steps may not be necessary but I wanted to make sure I had good data going in and was using the data in a modeling process that needed good preprocessing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Buwu0MTutzW4mnFVoAIUew.png" /><figcaption>Figure 1: Scattertext Plot Detailing Words from Posts in <a href="https://www.reddit.com/r/winemaking/">r/Homebrewing</a> and <a href="https://www.reddit.com/r/Homebrewing/">r/Winemaking</a> subreddits. Note, as designed by Jason Kessler, this plot is normally interactive. In this instance I just supplied a screenshot. I will deploy an interactive version at some point in the future. You can view interactive Scatterplots on <a href="https://github.com/JasonKessler">Jason Kessler’s Github</a> page. There you will find <a href="https://github.com/JasonKessler/scattertext">Jupyter Notebooks </a>and <a href="https://github.com/JasonKessler/scattertext">Google Colab</a> notebooks containing code to deploy Scattertext. -image by author</figcaption></figure><h3>How to Interpret Scattertext Plots</h3><p>It helps first to understand the plot. Most of you reading this already know that this plot uses a two-dimensional cartesian coordinate system where each point is represented by two coordinates, one from x-axis and one from the y-axis. The coordinates for each of these points are derived from the term frequencies in each class. <strong>Term frequencies are word and phrase frequencies. T</strong>wo-word n-grams are included in Scattertext if you choose. <strong>The y-axis represents the term frequencies for the Winemaking class whereas the x-axis represents the term frequencies for the Homebrewing class. </strong>For instance, the word ‘sugar’ in the very top right of Figure 1 has a term frequency of 195 in the Winemaking class and 71 in the Homebrewing class. These frequencies are its plot coordinates (71, 195) where 71 is the x-coordinate and 195 is the y-coordinate. <strong>That very top right of the plot, where you see that the word ‘sugar’ is located, is an area where term frequency is high for both classes.</strong></p><p>There is more information to ascertain here so I will show a few more examples. Take a look at the word ‘stout’ in the lower right-hand corner of Figure 1. It is all the way at the bottom of the y-axis but far right on the x-axis. With coordinates of (65, 0) this word is strongly found in the beer class and not represented at all in the wine class. Conversely, the word ‘winemaking’ has coordinates of (0, 95). That word is not represented at all in the Homebrewing class.</p><h4>Precision</h4><p>In his whitepaper, Kessler states that:</p><blockquote>Precision is a “word’s discriminative power regardless of its frequency. A term that appears once in the categorized corpus will have perfect precision. This (and subsequent metrics) presuppose a balanced class distribution. <strong>Words close to the x and y-axis in Scattertext have high precision.”</strong></blockquote><p><strong>These term examples (‘stout’ and ‘winemaking’) have a high degree of precision</strong> and are good illustrations of the way Kessler allows us to show distinguishing characteristics in classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0ME-uF5ucClPu9KKYVXTQ.png" /><figcaption>Figure 2: A graphic created by me detailing areas of the plot that have high recall, high precision, high frequencies and high shared-word ratios. -image by author</figcaption></figure><h4><strong>Interpreting the Middle</strong></h4><p>The blue color representing Winemaking and the red color representing Homebrewing provides an easy to discern visual that allows the viewer to quickly identify where differences exist in the text. The yellow and orangish colors on the plot are an easy way to identify terms that are most shared among the two classes. <strong>In this case as you go toward the top-right of the chart you will find the most frequent of the most-shared terms and the bottom-left is where you will find the least frequent of the most-shared terms.</strong></p><h4>Recall</h4><p>Not surprisingly Kessler also highlights recall in his whitepaper. Almost as if they are harmoniously married together, precision often cannot be highlighted without recall being present. Kessler describes recall as the “frequency a word appears in a particular class, or <em>P(word|class).</em> <strong>He describes the relationship between precision’s variance and recall stating that variance usually decreases as we see an increase in recall.</strong> Another interesting note that was a great epiphany for me was his revelation that “extremely high recall words tend to be stop words.” This could do wonders for those needing to visualize the effectiveness of their stop words lists. <strong>Most importantly for the interpretation of this plot, however, is the fact that high recall words tend toward the top right corner of the chart (See figure ).</strong></p><p>Just with these few examples alone you can begin to see that a Scattertext plot is ‘plotted’ much like a scatterplot. <strong>What makes it so visually appealing is a technique Kessler uses that replaces the ‘jitter’ feature in scatterplot with a method in Scattertext that breaks ties based on an alphabetical algorithm. </strong>This method more efficiently and accurately uses whitespace in the plot to show the relationships between two classes.</p><p>As you can see with this plot you can interpret not only word frequency and corporal similarities in word frequency but you can also interpret metrics such as precision and recall. When you combine all of the features that are interpreted above it creates a lovely visual that is easy to read.</p><h3>Interactive Features</h3><p>When you implement Scattertext completely it will have interactive features. <strong>As you scroll over dots on the plane you will see a pop up with statistics.</strong> The statistics include the word frequency per 25,000 words for both classes. It also features a**Scaled F-Score**. The word frequency metric is really easy to discern. That metric is what Scattertext uses as the coordinates for each point. You can see that metric represented below with <em>195:71 per 25k words.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*H6JUCRNnKk4AKS77StOYoQ.png" /><figcaption>Figure 3: Pop-up when scrolling over points -image by author</figcaption></figure><p>The other metric here is <em>score: 0.06247. </em>This is called a “Scaled F-Score.” There is a bit of math involved in determining this score but Kessler describes the math and even highlights his reasoning behind the score in this <a href="https://github.com/JasonKessler/scattertext#understanding-scaled-f-score">Github Repo</a> and this <a href="https://nbviewer.jupyter.org/github/JasonKessler/GlobalAI2018/blob/master/notebook/Scaled-F-Score-Explanation.ipynb"><em>Jupyter Notebook (also found in repo)</em></a>. The most important thing to take away regarding interpretation of this score in relation to what you have plotted is this:</p><p><strong>The score is on a scale of -1 to 1. Scores that are near zero have word frequencies that are similar for both classes (these are the yellow and orange dots). Scores that are near 1 will have word frequencies dominated by the positive class (in blue). Scores that are near -1 will have word frequencies dominated by the negative class (in red). The darker the color of red or blue indicates the closer the score is to -1 or 1.</strong></p><h3>More Interactivity</h3><p>The scroll over feature is not the only piece of interactivity. There is another very satisfying feature to supplement your analysis while using Scattertext. There is a <strong>‘Search The Chart’ feature</strong> that can be utilized in two different ways. <strong>One way is using the query box provided either below the bottom left or next to the top right of the chart depending on how your browser is oriented. The other way is by simply clicking on the colored coordinate dot. </strong>It really doesn’t get more intuitive than this with plotting tools. This is a fantastic feature.</p><p>The output is really what makes this feature useful. <strong>When you use the query box or click on the word dot you are given metrics regarding frequency broken down by per-word-frequency (as seen in the pop-up), AND you can also see frequency per-1,000-docs (doc in this case is a reddit post)</strong>. But wait, there is more. You are additionally provided with a nicely formatted list of the docs/posts where the word was mentioned. This is an outstanding tool that I imagine data professionals can even deploy for novices or non-data science professionals to use for their own research or curious exploration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3RJpcqDSDOZ2lFd3MwVGA.png" /><figcaption>This is a shortened view of what is actually provided when you use the ‘Search the Chart’ feature. Keep in mind I removed stop words and did some preprocessing on the data so my posts are not very legible. This, however, does give you an idea of how useful this feature can be. -image by author</figcaption></figure><h3>Other Highlights of Scattertext</h3><p>As you have clearly seen Scattertext can be fairly easy to interpret and is an elegant visual to include in a variety of data related presentations. There is much more depth to discuss in regards to Scattertext and many of those items of interest can be found in Jason Kessler’s <a href="https://github.com/JasonKessler/scattertext">Github</a> and <a href="https://arxiv.org/pdf/1703.00565.pdf">Whitepaper</a>. There you will also find coding notebooks and demonstrations regarding use and implementation of Scattertext. I will also likely be publishing some more posts on Medium regarding this topic so follow me <a href="https://jamesopacich.medium.com/">@jamesopacich</a> or direct message me for more information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e94e5824858" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/interpreting-scattertext-a-seductive-tool-for-plotting-text-2e94e5824858">Interpreting Scattertext: a seductive tool for plotting text</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[Data Science Immersive and the Bandaid Paradox]]></title>
            <link>https://jamesopacich.medium.com/data-science-immersive-and-the-bandaid-paradox-9aba57c6161f?source=rss-faee93b62ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aba57c6161f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[band-aid]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science-immersive]]></category>
            <dc:creator><![CDATA[James Opacich]]></dc:creator>
            <pubDate>Sat, 28 Nov 2020 05:13:00 GMT</pubDate>
            <atom:updated>2020-11-28T17:48:20.141Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Science Immersive and the Bandaid Conundrum</h3><p>‘’Ouch!” my toddler son whined as I combed his jumbled tangles of thin but burgeoning hair. I painstakingly worked not to snag a curl, however, my efforts were in vain. His gentle whining created a question. Would he rather me “gently” struggle with this endeavor while causing modest pain for a longer duration? Or, would he rather me quickly comb through the entwinement causing greater pain that would disappear instantly? I’m sure parents would differ on how to approach this.</p><p>The above question is much like the Band-aid Conundrum (something I’m not quite sure exists but I think should). The Band-aid Conundrum references the moment where you can either slowly and gently pull off the band-aid while not causing too much pain or you can quickly deal with your pain while achieving your goal of band-aid removal at a hastened pace leaving pain an afterthought only a moment later.</p><p>As I wade through the challenges enveloping me in the early stages of a Data Science Immersive class at General Assembly I have few moments to think about anything other than Python, Pandas, data visualization, statistics and the like. But I still have time for my kids. My son (and of course my daughter) often inspire profound thoughts. It was this moment, however mundane it may seem, that made me realize why I chose such a path…</p><p>I think I’d rather have the bandaid pulled off fast.</p><p>That word, ‘fast,’ is a perfect word to describe the Data Science Immersive at General Assembly. In just two weeks my cohort will have completed two projects, three labs and a quiz. In this time we have covered expansive subjects that include but are not limited to Python, Pandas, exploratory data analysis, data visualization with Matplot Library and Seaborn. We have touched base on Numpy, probability statistics, presentation techniques and even ethics. By the end of it all we will be versed in machine learning algorithms, statistical modeling and even deployability using Amazon Web Services. This is an expedited pace that requires 8 hour live classes 5 days per week as well as an additional 20 plus hours to finish projects and other homework. Well, they tell you 20 hours but expect more like 30 plus hours most weeks. If you are a person with children, like myself, you should think this out long and hard and have your support network working hard behind you.</p><p>This class takes a painful learning process that normally would take a tremendous amount of time and makes it more painful so you can develop those skills at a faster pace. So, if you are considering a Data Science Immersive class consider which person you are. One who wants the bandaid pulled off fast, or slow and gently? With General Assembly you’ll get the bandaid pulled off quick but only after you’ve had proper time with a little Neosporin to quicken the healing process and leave no scars. Hopefully…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aba57c6161f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>