<?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 Ryan Reilly on Medium]]></title>
        <description><![CDATA[Stories by Ryan Reilly on Medium]]></description>
        <link>https://medium.com/@ryan-reilly?source=rss-8744d86e7e78------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g635BhAnLPq3x12XaVGJGA.jpeg</url>
            <title>Stories by Ryan Reilly on Medium</title>
            <link>https://medium.com/@ryan-reilly?source=rss-8744d86e7e78------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 02:10:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryan-reilly/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[Data Poisoning vs Facial Recognition Technologies]]></title>
            <link>https://ryan-reilly.medium.com/data-poisoning-vs-facial-recognition-technologies-9e192fee91f9?source=rss-8744d86e7e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e192fee91f9</guid>
            <dc:creator><![CDATA[Ryan Reilly]]></dc:creator>
            <pubDate>Sun, 11 Jul 2021 23:12:46 GMT</pubDate>
            <atom:updated>2021-07-11T23:12:46.253Z</atom:updated>
            <content:encoded><![CDATA[<p>This post provides an explanation of a research paper titled <a href="https://arxiv.org/abs/2106.14851#:~:text=Data%20Poisoning%20Won&#39;t%20Save%20You%20From%20Facial%20Recognition,-Evani%20Radiya%2DDixit&amp;text=Data%20poisoning%20has%20been%20proposed,trained%20on%20Web%2Dscraped%20pictures.&amp;text=Once%20perturbed%20pictures%20are%20scraped,defense%20irrevocably%20undermines%20users&#39;%20privacy.">Data Poisoning Won’t Save You From Facial Recognition</a> by Evani Radiya-Dixit and Florian Tramer who both work at Stanford University. This paper was submitted on June 28, 2021. The authors argue that poisoning-based methods for facial images uploaded online will not serve as a good defense in protecting user privacy.</p><h3>Context:</h3><p>Data poisoning is a situation where you alter (or perturb) your image before you post it online with the hopes that facial recognition models that are trained on web scraped pictures can’t detect who you are. Perturbing your pictures should theoretically safeguard your online privacy. That is unless the models that scrape the images are really good at facial recognition even when you perturb an image, which they are as I found out! The authors set up experiments, called poisoning attack games, between the user who uploads perturbed images and the model that detects them. They refer to the user as the attacker and the model as the defender (even though the defender is the one that is aiming to breach the online privacy of the attacker).</p><p>Defenses are actions taken by the defender to counter the attacker who poisoned the image. There were two defense strategies employed in the attack games, but first, let&#39;s look at how the authors poisoned the images for experimentation:</p><h3><strong>Attack methods</strong></h3><p>There are two facial recognition tools that were used for experimentation called <a href="http://sandlab.cs.uchicago.edu/fawkes/">Fawkes</a> and <a href="https://lowkey.umiacs.umd.edu/">LowKey</a>. Fawkes was created by scientists at the University of Chicago’s Sand Lab and Lowkey was created by a group of computer scientists who <a href="https://arxiv.org/abs/2101.07922">wrote a paper</a> to describe their work. While the technology behind the tools is a bit complicated, the goal of the two tools is the same: to prevent the images you post online from being used to track you. These tools were used as attacks on the facial recognition tool to see how well the pictures did at being undetected. An example of how images get poisoned is below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*V5isORp-mmupRkhlVYx7ng.png" /><figcaption>First row: Original images; Second row: Images protected with LowKey (medium); Third row: Images protected with LowKey (large)</figcaption></figure><h3>Defenses</h3><p><strong>Oblivious defense</strong>: The idea behind the oblivious defense is to wait until a new facial recognition model is invented that can better detect poisoned images using more advanced techniques and train your model on the images that were already scraped. Then employ your model on new images uploaded.</p><p>For an attacker to bypass this defense, the attacker will need to poison an image that fools not only today&#39;s facial recognition models but those that will be built in the future, which is nearly impossible! The facial recognition technology we have today is way more advanced than it was just a few years ago.</p><p><strong>Adaptive defense</strong>: This defense is when you can access how the poisoning of the image occurred, apply that to images, and then augment your dataset with perturbed and unperturbed images. So the defender is basically using the strategies employed by the attacker to create poisoned images to train the model. An adaptive model could also aim to detect whether a picture is perturbed or not. This would be useful because it can filter out perturbed images, and retain only unperturbed images of a user</p><p>The authors note there has not been an effective counterattack on this defense.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsUmrIfjFG21HVsSdWEdLQ.png" /><figcaption>Figure and comments below taken from the research paper</figcaption></figure><p>(1) Users perturb their pictures before posting them online.</p><p>(2) A model trainer continuously scrapes the Web for pictures.</p><p>(3–4)The model trainer builds a model from collected pictures and evaluates it on unperturbed pictures. With no defense strategy, the poisoned model fails to recognize users whose online pictures were perturbed. An “oblivious” model trainer can wait until a better facial recognition model is discovered and retroactively train it on past pictures to resist poisoning. An adaptive model trainer with black-box access to the attack employed by users can immediately train a robust model that resists poisoning.</p><h3><strong>Outcomes</strong></h3><p>To conclude, the authors state that <strong><em>“poisoning attacks against facial recognition will not lead to an “arms race”, where new attacks can continuously counteract new defenses. Since the perturbation applied to a picture cannot be changed once the picture is scraped, a successful poisoning attack has to remain effective against all future models, even models trained adaptively against the attack or models that use new techniques discovered only after the attack.”</em></strong></p><p>So are we doomed against safeguarding our online privacy? Well, I think the authors would argue that we are. The only way to not have your photos be tracked is if you never post a photo of yourself in the first place, which is highly unlikely in this age of social media. The only other thing that may help with privacy safeguards is if there is legislation passed that makes it illegal to use mass facial recognition software that in turn gets used by public and private entities.</p><h3>Why you should care about this</h3><p>There are major ethical questions that haunt facial recognition research. For a facial recognition model to work well, it needs to be trained and tested on tons of labeled images. This is usually done by scraping social media sites without asking for your permission and it is more than likely that your face is labeled in a database somewhere being used to build a product for profit that you know nothing about.</p><p>However, it&#39;s not all bad! Facial recognition technology can be used by police to identify a suspect in a crime, or used in airports to check travelers&#39; identities or to simply unlock your iPhone. Facial recognition is an awesome subject in data science, but like all new technologies, you have to think about the ethical consideration of the new technology and how that will impact users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e192fee91f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GridSearch + Pipelines of Multiple models on Multiclass Classification]]></title>
            <link>https://ryan-reilly.medium.com/gridsearch-pipelines-of-multiple-models-on-multiclass-classification-e9124b6ea2e3?source=rss-8744d86e7e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9124b6ea2e3</guid>
            <dc:creator><![CDATA[Ryan Reilly]]></dc:creator>
            <pubDate>Mon, 21 Jun 2021 03:57:55 GMT</pubDate>
            <atom:updated>2021-06-21T03:57:55.653Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous post, I talked about using pipelines from Scikit-learn to automate workflows and make the modeling process more streamlined using cleaner code. I also introduced the concept of using GridSearch in Scikit-learn. GridIn this tutorial, I am going to show you how to use Gridsearch in combination with pipelines for a multiclass classification dataset. This will allow you to not only streamline your model workflows but optimizing your hyperparameters within each model using Girdsearch.</p><h3><strong>Multiclass Classification Dataset</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*QB3iI05rkoyRs7H-1fQrIg.jpeg" /></figure><p>I will be using a dataset of phone features to predict a phone’s price range. There are 2000 rows in this dataset. Each row represents the features of a phone. The target column in the dataset is called price_range and has values from 0 to 3:</p><p><strong>0 </strong>(low cost)<br><strong>1</strong> (medium cost)<br><strong>2 </strong>(high cost)<br><strong>3 </strong>(very high cost)</p><p>There are a total of 20 features including the following:</p><p><strong>battery_power</strong>: Total energy a battery can store in one time measured in mAh<br><strong>blue</strong>: Has Bluetooth or not<br><strong>clock_speed</strong>: speed at which microprocessor executes instructions<br><strong>dual_sim</strong>: Has dual sim support or not<br><strong>fc</strong>: Front Camera mega pixels<br><strong>four_g</strong>: Has 4G or not<br><strong>touch_screen</strong>: Has touchscreen or not</p><p>Here is the output of df.info() method to see all the columns:</p><pre>#   Column         Non-Null Count  Dtype  <br>---  ------         --------------  -----  <br> 0   battery_power  2000 non-null   int64  <br> 1   blue           2000 non-null   int64  <br> 2   clock_speed    2000 non-null   float64<br> 3   dual_sim       2000 non-null   int64  <br> 4   fc             2000 non-null   int64  <br> 5   four_g         2000 non-null   int64  <br> 6   int_memory     2000 non-null   int64  <br> 7   m_dep          2000 non-null   float64<br> 8   mobile_wt      2000 non-null   int64  <br> 9   n_cores        2000 non-null   int64  <br> 10  pc             2000 non-null   int64  <br> 11  px_height      2000 non-null   int64  <br> 12  px_width       2000 non-null   int64  <br> 13  ram            2000 non-null   int64  <br> 14  sc_h           2000 non-null   int64  <br> 15  sc_w           2000 non-null   int64  <br> 16  talk_time      2000 non-null   int64  <br> 17  three_g        2000 non-null   int64  <br> 18  touch_screen   2000 non-null   int64  <br> 19  wifi           2000 non-null   int64  <br> 20  price_range    2000 non-null   int64  <br>dtypes: float64(2), int64(19)<br>memory usage: 328.2 KB</pre><h3>Libraries</h3><p>Below are the libraries I used to perform the analysis using gridsearch and pipelines. I have also provided links to the documentation of each item I loaded.</p><pre># Read in the data<br>import pandas as <a href="https://pandas.pydata.org/docs/">pd</a></pre><pre># Scale the data<br>from sklearn.preprocessing import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html">StandardScaler</a></pre><pre># Pipeline, Gridsearch, train_test_split<br>from sklearn.pipeline import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html">Pipeline</a><br>from sklearn.model_selection import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html">train_test_split</a>, <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html">GridSearchCV</a></pre><pre># Plot the confusion matrix at the end of the tutorial<br>from sklearn.metrics import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.plot_confusion_matrix.html">plot_confusion_matrix</a></pre><pre># Classification Models<br>from sklearn.linear_model import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html">LogisticRegression</a><br>from sklearn.neighbors import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html">KNeighborsClassifier</a><br>from sklearn.ensemble import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html">RandomForestClassifier</a><br>from sklearn.tree import <a href="https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html">DecisionTreeClassifier</a><br>from xgboost import <a href="https://xgboost.readthedocs.io/en/latest/index.html">XGBClassifier</a><br>from sklearn import <a href="https://scikit-learn.org/stable/modules/svm.html">svm</a></pre><p>First I am going to read in the data and perform a train test split. For the purposes of this tutorial, assume the data has already been cleaned.</p><pre>df = pd.read_csv(&#39;cell_phones.csv&#39;)</pre><pre># Set variables for the targets and features<br>y = df[&#39;price_range&#39;]<br>X = df.drop(&#39;price_range&#39;, axis=1)</pre><pre># Split the data into training test sets<br>X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=42)</pre><p>Now I am going to construct a pipeline of each type of model I want to train the dataset on. Below I am creating six different pipelines. Each pipeline is creating a workflow of two steps to be done. The first is to scale the data end the second is to instantiate the model to be fit on. I chose these six because these were the models we learned about in Phase 3 of our Bootcamp.</p><pre>pipe_lr = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                    (&#39;LR&#39;, LogisticRegression(random_state=42))])</pre><pre>pipe_dt = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                    (&#39;DT&#39;,DecisionTreeClassifier(random_state=42))])</pre><pre>pipe_rf = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                    (&#39;RF&#39;,RandomForestClassifier(random_state=42))])</pre><pre>pipe_knn = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                    (&#39;KNN&#39;, KNeighborsClassifier())])</pre><pre>pipe_svm = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                     (&#39;SVM&#39;, svm.SVC(random_state=42))])</pre><pre>pipe_xgb = Pipeline([(&#39;scl&#39;, StandardScaler()),<br>                     (&#39;XGB&#39;, XGBClassifier(random_state=42))])</pre><p>Great, so now we want to create the Grid Search parameters for each model. We are doing this so that we can pass these in the GridSearchCV function that will take a pipeline and test out each parameter value we pass through in the following parameter list. Before I created the grids for each, I created parameter values within lists so that I could pass in the lists, rather than hardcoded values.</p><pre>param_range = [1, 2, 3, 4, 5, 6]<br>param_range_fl = [1.0, 0.5, 0.1]<br>n_estimators = [50,100,150]<br>learning_rates = [.1,.2,.3]</pre><pre>lr_param_grid = [{&#39;LR__penalty&#39;: [&#39;l1&#39;, &#39;l2&#39;],<br>                   &#39;LR__C&#39;: param_range_fl,<br>                   &#39;LR__solver&#39;: [&#39;liblinear&#39;]}]</pre><pre>dt_param_grid = [{&#39;DT__criterion&#39;: [&#39;gini&#39;, &#39;entropy&#39;],<br>                   &#39;DT__min_samples_leaf&#39;: param_range,<br>                   &#39;DT__max_depth&#39;: param_range,<br>                   &#39;DT__min_samples_split&#39;: param_range[1:]}]</pre><pre>rf_param_grid = [{&#39;RF__min_samples_leaf&#39;: param_range,<br>                   &#39;RF__max_depth&#39;: param_range,<br>                   &#39;RF__min_samples_split&#39;: param_range[1:]}]</pre><pre>knn_param_grid = [{&#39;KNN__n_neighbors&#39;: param_range,<br>                   &#39;KNN__weights&#39;: [&#39;uniform&#39;, &#39;distance&#39;],<br>                   &#39;KNN__metric&#39;: [&#39;euclidean&#39;, &#39;manhattan&#39;]}]</pre><pre>svm_param_grid = [{&#39;SVM__kernel&#39;: [&#39;linear&#39;, &#39;rbf&#39;], <br>                    &#39;SVM__C&#39;: param_range}]</pre><pre>xgb_param_grid = [{&#39;XGB__learning_rate&#39;: learning_rates,<br>                    &#39;XGB__max_depth&#39;: param_range,<br>                    &#39;XGB__min_child_weight&#39;: param_range[:2],<br>                    &#39;XGB__subsample&#39;: param_range_fl,<br>                    &#39;XGB__n_estimators&#39;: n_estimators}]</pre><p>We are almost there. Now we can use the GridSearchCV function and pass in both the pipelines we created and the grid parameters we created for each model. In this function, we are also passing in cv = 3 for the gridsearch to perform cross-validation on our training set and scoring = ‘accuracy’ in order to get the accuracy score when we score on our test data.</p><pre>lr_grid_search = GridSearchCV(estimator=pipe_lr,<br>        param_grid=lr_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><pre>dt_grid_search = GridSearchCV(estimator=pipe_dt,<br>        param_grid=dt_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><pre>rf_grid_search = GridSearchCV(estimator=pipe_rf,<br>        param_grid=rf_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><pre>knn_grid_search = GridSearchCV(estimator=pipe_knn,<br>        param_grid=knn_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><pre>svm_grid_search = GridSearchCV(estimator=pipe_svm,<br>        param_grid=svm_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><pre>xgb_grid_search = GridSearchCV(estimator=pipe_xgb,<br>        param_grid=xgb_param_grid,<br>        scoring=&#39;accuracy&#39;,<br>        cv=3)</pre><p>So far we defined a lot of pipelines and grid searches, but we hav’nt fit anything yet. Here is where the cool part comes in. We first define a list of all the grid searches we just created called grids, then we create a for loof to fit all of them.</p><pre>grids = [lr_grid_search, dt_grid_search, rf_grid_search, knn_grid_search, svm_grid_search, xgb_grid_search]</pre><pre>for pipe in grids:<br>    pipe.fit(X_train,y_train)</pre><p>The above code took about 3 and 1/2 minutes to run. Your run time will vary depending on how many models you are fitting.</p><p>Lastly, we can see how each model performed by using .score at the end of the model and passing in the test data. The below code will first create a dictionary of classifier types to be used in the for loop. The for loop will then print out the accuracy of each model and the specific model parameters that worked best from the parameter grids we created above.</p><pre>grid_dict = {0: &#39;Logistic Regression&#39;, 1: &#39;Decision Trees&#39;, <br>             2: &#39;Random Forest&#39;, 3: &#39;K-Nearest Neighbors&#39;, <br>             4: &#39;Support Vector Machines&#39;, 5: &#39;XGBoost&#39;}</pre><pre>for i, model in enumerate(grids):<br>    print(&#39;{} Test Accuracy: {}&#39;.format(grid_dict[i],<br>    model.score(X_test,y_test)))<br>    print(&#39;{} Best Params: {}&#39;.format(grid_dict[i],          model.best_params_))</pre><p>Below is my output when I ran it. I have bolded the most accurate model. It looks like Support Vector Machines was the highest of .97 which is great! You can also see the best parameters to pass through the model give the list we provided.</p><pre>Logistic Regression Test Accuracy: 0.866<br>Logistic Regression Best Params: {&#39;LR__C&#39;: 1.0, &#39;LR__penalty&#39;: &#39;l1&#39;, &#39;LR__solver&#39;: &#39;liblinear&#39;}</pre><pre>Decision Trees Test Accuracy: 0.858<br>Decision Trees Best Params: {&#39;DT__criterion&#39;: &#39;entropy&#39;, &#39;DT__max_depth&#39;: 6, &#39;DT__min_samples_leaf&#39;: 1, &#39;DT__min_samples_split&#39;: 4}</pre><pre>Random Forest Test Accuracy: 0.86<br>Random Forest Best Params: {&#39;RF__max_depth&#39;: 6, &#39;RF__min_samples_leaf&#39;: 2, &#39;RF__min_samples_split&#39;: 5}</pre><pre>K-Nearest Neighbors Test Accuracy: 0.586<br>K-Nearest Neighbors Best Params: {&#39;KNN__metric&#39;: &#39;manhattan&#39;, &#39;KNN__n_neighbors&#39;: 6, &#39;KNN__weights&#39;: &#39;distance&#39;}</pre><pre><strong>Support Vector Machines Test Accuracy: 0.97</strong><br>Support Vector Machines Best Params: {&#39;SVM__C&#39;: 5, &#39;SVM__kernel&#39;: &#39;linear&#39;}</pre><pre>XGBoost Test Accuracy: 0.9<br>XGBoost Best Params: {&#39;XGB__learning_rate&#39;: 0.1, &#39;XGB__max_depth&#39;: 5, &#39;XGB__min_child_weight&#39;: 1, &#39;XGB__n_estimators&#39;: 150, &#39;XGB__subsample&#39;: 0.5}</pre><p>Below is the confusion matrix. You can see the SVM model did a really good job at predicting a cell phone’s price range by looking at the True positives on the diagonal.</p><pre>plot_confusion_matrix(svm_grid_search, X_test, y_test)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*pDJ54Ck2IlzbFAiQhpXM_g.png" /></figure><h3><strong>Conclusion</strong></h3><p>By now you should be able to see how you can test out many models using pipelines along with testing out many hyperparameter values within each model using gridsearch.</p><p>Keep in mind there can be some drawbacks to performing gridsearch with pipelines:</p><ol><li>The first drawback can be the size of your data, the full dataset I used was small (only 2,000 rows) so each model did not take that long to scale and train. For larger datasets, some of the models would not make sense or take an extremely long time to run.</li><li>The second drawback is related to how many grid parameters you pass in your parameter grid. The longer the list of hyperparameters you want to try, the longer it will take to fit on the girdsearchCV function. For instance in the XGBoost pipeline, because I used param_range (range of 6), param_range_fl(range of 3), n_estimators(range of 3), and learning_rates(range of 3), the total number of tests on the model was 6*3*3*3 = 162!</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9124b6ea2e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate your Workflows using Pipelines in Scikit-learn]]></title>
            <link>https://ryan-reilly.medium.com/automate-your-workflows-using-pipelines-in-scikit-learn-49a3d46083d4?source=rss-8744d86e7e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/49a3d46083d4</guid>
            <dc:creator><![CDATA[Ryan Reilly]]></dc:creator>
            <pubDate>Mon, 31 May 2021 23:44:56 GMT</pubDate>
            <atom:updated>2021-05-31T23:44:56.193Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the key skills we have learned at Flatiron during our data engineering phase is the ability to automate data processing through the use of loops and functions. Loops allow us to repeat workflows while functions allow us to build reusable code. This process of automation can be extended to thinking about the workflows involved in creating machine learning models. The Scikit-learn library provides a Pipeline module to do just that. It allows you to chain transformers and estimators together into a sequence that functions as one object in your code.</p><p>So what are transformers and estimators anyway?</p><p>A transformer<strong> </strong>is a way to “transform” your dataset into a desirable state to be used in a machine learning model. You can use the transform() method in your pipeline to clean your data, impute data, create or reduce the number of features, and even scale your data, among others.</p><p>An estimator refers to a machine learning model. Once you transform your data, you will need to fit() and predict() on the model of your choosing, depending on what you are trying to accomplish. You can see in the below chart that choosing the right model can be a daunting task, as there are many estimators to chose from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v9zD0TMI-eUNcahU.png" /><figcaption>Algorithm cheat sheet from <a href="https://scikit-learn.org/stable/tutorial/machine_learning_map/index.html">Scikit-learn</a></figcaption></figure><p>Once you choose your model, you can set up your code to allow all of your transformations and estimators to happen in one box of code, kind of like the pipeline box below. It shows a picture of both the testing and training data flow with the workflow(pipeline) structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*0TrDLlBujC_IS-1y.png" /><figcaption>Copywrite: <a href="https://nbviewer.jupyter.org/github/rasbt/python-machine-learning-book/blob/master/code/ch06/ch06.ipynb#Combining-transformers-and-estimators-in-a-pipeline">Sebastian Raschka</a></figcaption></figure><p>In the context of pipelines, both your transformers and your estimator are referred to as estimators, which are then passed into a list called estimators using key-value pairs where the string is the name of the step and the value is an estimator object. All estimators in a pipeline, except the last one, must be transformers. Below is a basic construction of pipeline objects in Scikit-learn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*Kmlv6FSozd00UjoPvQojPw.png" /><figcaption>Construction of a pipeline from <a href="https://scikit-learn.org/stable/modules/compose.html#pipeline">Sci-kit learn</a></figcaption></figure><p>Here is an example of comparing multiple models using Pipelines:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*LZFxx8nrAHnjM30FplnTGw.png" /><figcaption>Code was taken from the YouTube walkthrough at the bottom of this post under Resources</figcaption></figure><p>There are other benefits other than having your transformers and estimators in a nice sequential order. A common time-suck in fine-tuning machine learning models is updating the hyperparameters of the model. Using pipelines, along with the Grid search method, allows you to tune the hyperparameters of the entire pipeline including both transformers and estimators.</p><p>What are hyperparameters and GridSearch?</p><p>Model parameters are internal to a model and can be estimated from the data. Model hyperparameters are external to the model and must be set manually. Finding the correct hyperparameter value is done by setting different values for those hyperparameters in your model and deciding which ones work best by testing them. Performing a grid search is the process of scanning the data to configure optimal parameters for a given model. The Gridsearch tool allows you to apply this search for the optimal hyperparameter values on your pipeline at once.</p><h3>Alternative Pipeline tools</h3><p><a href="https://spark.apache.org/docs/2.0.0-preview/ml-guide.html">Spark ML</a>: MLlib fits into Spark’s APIs and interoperates with NumPy in Python<strong>. </strong>A description from the spark website: <em>“ The spark.ml package aims to provide a uniform set of high-level APIs built on top of </em><a href="https://spark.apache.org/docs/2.0.0-preview/sql-programming-guide.html#dataframes"><em>DataFrames</em></a><em> that help users create and tune practical machine learning pipelines. See the </em><a href="https://spark.apache.org/docs/2.0.0-preview/ml-guide.html#algorithm-guides"><em>algorithm guides</em></a><em> section below for guides on sub-packages of spark.ml, including feature transformers unique to the Pipelines API, ensembles, and more.”</em></p><p><a href="https://www.cs.waikato.ac.nz/ml/weka/">Weka</a>: Weka is another machine learning software that has its own tools for managing machine learning pipelines. Weka’s functionality can be accessed from Python using the <a href="https://github.com/fracpete/python-weka-wrapper3">Python Weka Wrapper</a>.</p><p><a href="http://epistasislab.github.io/tpot/">TPot</a>: Tpot was developed in the Computational Genetics Lab at the University of Pennsylvania. This tool was actually built on top of Scikit-learn learn and optimizes machine learning pipelines using genetic programming. A little more on genetic programming <a href="https://en.wikipedia.org/wiki/Genetic_programming">here</a>.</p><p><a href="https://pypi.org/project/mlblocks/">MLBlocks</a>: MLBlocks is a simple framework for composing end-to-end tunable Machine Learning Pipelines by seamlessly combining tools from any python library with a simple, common, and uniform interface.</p><p>These were just a few, there are many alternatives to sci-kit learn that have their own machine learning pipeline tool underneath the hood. Here was a <a href="https://www.g2.com/products/scikit-learn/competitors/alternatives">top 20 alternative list</a> I found from G2.</p><h3>History</h3><p>The Scikit-learn library was started in 2007 as a Google Summer of Code program. There were 13 students between 2007 and 2016 who were sponsored by Google to work on Sci-kit learn. It currently sits as an open-source community-driven project with a core list of contributors for development and maintenance. It is funded by institutional and private grants from big companies (Microsoft included). The <a href="https://github.com/scikit-learn/scikit-learn/blob/15a949460/sklearn/pipeline.py#L37">GitHub</a> repository for the pipeline module within Scikit-learn has 60 contributors.</p><h3>Resources</h3><p>Below are some resources for using pipelines in Ski-kit learn along with some simple tutorials:</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html#sklearn.pipeline.Pipeline">Pipeline Function</a>: This Scikit-learn page provides a simple example of using the pipeline function along with the various methods used with the function. There is also a list of links at the bottom that lead to more examples of where this is used.</p><p><a href="https://scikit-learn.org/stable/modules/compose.html#pipeline">Pipeline User Guide</a>: This is Scikit-learns a more comprehensive look at pipelines and how they can be used in conjunction with other tools during the transformation and training of your models.</p><p><a href="https://analyticsindiamag.com/hands-on-tutorial-on-machine-learning-pipelines-with-scikit-learn/">Basic Tutorial:</a> This post gives a really good overview of a basic pipeline implementation. The writer even shows you how you can easily stack multiple pipelines to find the best model along a tuning pipeline that helps you find the best hyperparameters in a given model.</p><p><a href="https://gist.github.com/amberjrivera/8c5c145516f5a2e894681e16a8095b5c">Basic Tutorial</a>: Here is another great tutorial that goes over a simple example of using a couple of transformations along with a classifier (estimator) to indicate if an email is considered spam or not. It also shows how you can create your own function to be used as a transformation step in a pipeline.</p><p><a href="https://www.kaggle.com/sermakarevich/sklearn-pipelines-tutorial">Advanced Tutorial</a>: This post in Kaggle is a little more advanced but it illustrates the other features that can be used with the pipeline module to make your machine learning models train and estimate more efficiently.</p><p><a href="https://www.youtube.com/watch?v=w9IGkBfOoic">Youtube walkthrough</a>: I found this video to be very helpful. When first hearing about pipelines, they sound very abstract, but this guy goes over how to use them in this short video and does a great job of clearly explaining how the code works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49a3d46083d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why did I decide to learn data science?]]></title>
            <link>https://ryan-reilly.medium.com/why-did-i-decide-to-learn-data-science-bdbdaf6ee64a?source=rss-8744d86e7e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdbdaf6ee64a</guid>
            <dc:creator><![CDATA[Ryan Reilly]]></dc:creator>
            <pubDate>Sat, 08 May 2021 14:20:41 GMT</pubDate>
            <atom:updated>2021-05-08T14:20:41.616Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Journey into Tech</h3><p>In college, I thought I was going to be a stockbroker on wall street. I loved taking classes like “Financial Markets &amp; Institutions”, “Portfolio Management”, and “Investment Practicum” and I really did enjoy learning about the stock market in a classroom setting with the hopes of making the big bucks once I graduated. Two things happened that really shifted my focus. First, I graduated in the middle of the Great Recession when it was hard to come by any job, let alone one on Wall Street which was in a free fall at the time. Secondly, shortly after graduating, I read a hilarious book by Michael Lewis called <a href="https://www.amazon.com/Liars-Poker-Norton-Paperback-Michael-ebook/dp/B003E20ZRY/ref=tmm_kin_swatch_0?_encoding=UTF8&amp;qid=1619883751&amp;sr=1-1">Liar’s Poker</a> that illustrated Michael’s life as a bond salesman in the 1980s at a now-defunct investment bank named Salomon Brothers. His description of the culture made me completely turned off to a job in that world. My next step logical step? Defer my college loans and move to Prague to teach English for a year.</p><p>Prague was fun, and I did a lot of traveling but knew from the start that teaching English as a foreign language wasn&#39;t for me. The cheap beer and the traveling were for me though. I came home and tried a few different jobs including as a valet (met some cool rock stars), an operations team member for a financial startup (answered a lot of phone calls), and as a loan officer (sold three loans the year I was there, two of which were to family members). After my illustrious career in mortgage lending, I landed a three-month contract for a tech start-up and it was during that time that I decided to take an online SQL course. Right away I was hooked. I was learning a new skill and it felt like every SELECT statement that ran without errors was magic! I immediately enrolled in a long-term continuing education program that would teach me even more skills in business intelligence in the evenings while I worked during the day.</p><h3>Finding out about data science</h3><p>While continuing to take business intelligence development classes learning about data analytics, I landed a contract at a big tech company supporting sales teams.</p><p>One day at my new role I came across a chart that looked like the one you see below from Gartner. It’s showing the maturity of analytics for an organization that handles lots of data. Having started taking classes, I was familiar with the first two boxes, but the words “Predictive” and “Prescriptive” in the last two boxes sounded cool and foreign to me. I realized my journey had just begun and I had a long way to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*elQ39mCXTEp2HUBdc2Pi1Q.png" /></figure><h3>What excites me in the field</h3><p>It’s been several years since discovering that chart and I feel like I am in a much more familiar place with data science, but still have a long way to go (there&#39;s a theme here). I have had a few roles as a Data Analyst and have completed a lot of cool online courses through Massive Open Online Courses (MOOCs). I have also completed a year-long course in R for statistical analysis that introduced me to machine learning concepts and how to go through the process from gathering data to eventually predicting outcomes with the data. I feel like I have come a long way from my first SELECT statement. That may be why I like the field so much because you can&#39;t afford to stop learning or you feel like you are being left behind.</p><p>I find myself fascinated by topics in data science that sound really hard to learn, particularly Deep Learning. I just think it’s the word “Deep”. It sounds difficult! I took a great series of courses online by a Stanford professor named Andrew Ng called <a href="https://www.coursera.org/specializations/deep-learning?utm_source=gg&amp;utm_medium=sem&amp;utm_campaign=17-DeepLearning-US&amp;utm_content=17-DeepLearning-US&amp;campaignid=904733485&amp;adgroupid=49070439496&amp;device=c&amp;keyword=neural%20network%20for%20machine%20learning&amp;matchtype=b&amp;network=g&amp;devicemodel=&amp;adpostion=&amp;creativeid=269507680276&amp;hide_mobile_promo&amp;gclid=Cj0KCQjw-LOEBhDCARIsABrC0TmmAlkwK_c7ahumZZ4u2DFwDEc3WuDAfeQl7AfWJa4-JPpC3bpg8sYaAjI6EALw_wcB">Deep Learning Specialization</a> and it humbled me quickly. Building and training neural networks is a specialty on its own and even learning the vocabulary of it can be intimidating (just thinking about the word “backpropagation” makes my head spin but in a good way!). It reinforced that I need to skill up to understand a lot of what Andrew is lecturing about and how deep learning is implemented using Python and a number of other tools.</p><h3>Finding Flatiron</h3><p>I realized that to skill up in the most efficient way, I should try a Bootcamp. I also found myself getting offered a lot of PM roles in areas that did not interest me so I felt like I needed a reset in my job search. I researched a few schools, but <a href="https://flatironschool.com/">Flatiron School</a> was the first school I talked to about the program, and just stuck with them until I was fortunately accepted into their Data Science Bootcamp. I figured I could try another school if it didn&#39;t work out, but everyone I met at Flatiron throughout the process was positive, informative, and passionate about what I wanted to accomplish.</p><h3>My hopes for now</h3><p>I think at the core of my interest in working with data is the satisfaction I get when I have figured out a solution for a data problem. It’s an awesome feeling and one that can happen multiple times in a day while you are working with data. I hope to continue to develop my Python programming and other data science skills to land a role in the future working on machine learning projects. It’s cool to know the last two boxes in the Gartner chart are feeling less foreign.</p><p>Careers in the tech industry can be really hard to navigate, but I have found what I am passionate about learning within the industry and I hope I am here to stay, that is unless Michael Lewis writes another account of his experience in the tech field that changes my mind…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdbdaf6ee64a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>