<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Patrick Pagni on Medium]]></title>
        <description><![CDATA[Stories by Patrick Pagni on Medium]]></description>
        <link>https://medium.com/@patrick.pagni1?source=rss-7949b828f4ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u378ueS1SytPsINT9RlOHw.jpeg</url>
            <title>Stories by Patrick Pagni on Medium</title>
            <link>https://medium.com/@patrick.pagni1?source=rss-7949b828f4ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:17:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patrick.pagni1/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[Salary Prediction based on jobs scraped from indeed.com]]></title>
            <link>https://medium.com/@patrick.pagni1/salary-prediction-based-on-jobs-scraped-from-indeed-com-eef8b7d3f8d8?source=rss-7949b828f4ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/eef8b7d3f8d8</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[job-hunting]]></category>
            <category><![CDATA[salary]]></category>
            <category><![CDATA[data-modeling]]></category>
            <dc:creator><![CDATA[Patrick Pagni]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 20:14:18 GMT</pubDate>
            <atom:updated>2022-02-22T20:14:18.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*sBcn9MgOiBCUPewbzTFwsg.png" /></figure><h3>Context</h3><p>This is an assignment that was given to me while studying at General Assembly.</p><p>The project was split into the following sub-tasks:<br>- <strong>Build a web scrape and scrape indeed.com</strong><br>Information scraped:<br>Title<br>Location<br>Company<br>Salary<br>- <strong>Clean and normalise scraped data<br>- Fit two different classifier models on cleaned data using only the location as a predictor<br>- Create more variables from scraped data to act as predictors<br>- Re-fit two different classifier models on data using new predictors<br>- Tune re-fitted models to optimise parameters<br>- Evaluate re-fitted models</strong></p><h3><strong>Web Scrape</strong></h3><p>Indeed is known for being difficult to scrape, and it is important to rotate through IP addresses to mask your identity otherwise they will give you a captcha. A captcha is a way of preventing bots from scraping their site because it presents the algorithm with a task that is challenging for computers to solve but solvable by humans (although they’re getting harder!). While it is possible to write a programme to solve the Captcha, it’s easier to just avoid the captcha altogether.</p><p>To avoid the captcha, I encrypted my connection using ExpressVPN, a paid VPN service provider. I also downloaded tor using the terminal command brew install tor and then ran it in my terminal during the scrape. This means my IP address is routed through several different tor nodes and re-assigned at each one, masking my computer’s IP address from Indeed. (Got to avoid that ban!) By connecting to the VPN first, it masks my traffic and identity both from my ISP and potentially malicious tor nodes, adding further security and privacy. Finally, I also updated the user-agent field I sent to indeed to that which my computer usually sends when I am accessing a website with my browser. If I don’t do this Indeed can see that it is a script running and can throw up a captcha.</p><p>I scraped through 21 cities: 16 in the UK, 5 in the US and 4 in the EU; and 3 job titles per city: data scientist, data analyst and data engineer. I reset my IP address for every city and if a captcha was thrown. In the case of captcha recurring after successive IP resets, the web scrape broke so I could manually investigate (this never happened). Finally, after scraping through a page, I delayed the scrape from accessing the next page for a random amount of time up to 20 seconds.</p><p>Finally, I deduplicated rows and dropped all rows without salary data, leaving a total of 1986 usable results for modelling. I saved this to a CSV.</p><h3>Data Cleaning</h3><p>I loaded the data from jobs.csv and did some clean up on the job_title column. This mostly involved using regex to pull job_titles from sentences detailing job descriptions, as well as some minor tweaks to formatting.</p><p>I also cleaned the location column to group the jobs into the nearest city of the cities I scraped.</p><p>For the salary column, I dropped all rows where the salary was not quoted in years. Then I analysed each string, and where a range was presented I converted this to the mean between the two values. Otherwise, I just converted the string to a number. Since there were multiple currencies pulled: EUR, GBP and USD, I converted all salaries to USD using the <em>forex_python.converter</em> library.</p><p>Finally, because we were creating a classifier model I analysed the salary target variable to identify which classes to define as target variables. I observed that the range of salaries was very high, so instead of two classes, I created four predictor classes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*nJ96mV84enc3evXa29cSPw.png" /></figure><p>I classified each row in the salary_band column.</p><p>I also calculated the baseline accuracy for the dataset. The baseline accuracy of the model is what accuracy we can expect if we always predict the largest group. We can use the baseline accuracy to identify if we are performing better than just guessing the largest category each time. The baseline accuracy for this dataset is 26.03% if you always predict the MID-LOW category.</p><h3>Location Only</h3><p>When predicting only the location, I used two models: Logistic Regression and Decision Tree Classifier.</p><p><strong>Logistic Regression<br></strong>After fitting this model, we received a mean cross-validation score of 0.4446. What this means is that of all the predictions the model made, it was right 44.46% of the time. This may not sound spectacular, but if you guess the largest group each time, you can only expect to be right 26.03% of the time. Therefore being correct 44.46% of the time is a large improvement on the baseline accuracy.</p><p>The top 5 most important coefficients for predicting each category are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*_wFKOmf7cNLAOwiGOeKVYw.png" /></figure><p><strong>Decision Tree Classifier</strong><br>For this model, we had a mean cross-validation score of 0.4484, translating to a model that accurately predicts the correct class 44.84% of the time. Again, against the baseline accuracy, this is a vast improvement and it is even a small improvement on the Logistic Regression model above.</p><p>The top 5 most important features for this model are:<br>New York<br>London<br>Austin<br>Chicago<br>Los Angeles</p><p>I have explained above by what criteria these features are ranked.</p><p><strong>Feature Engineering</strong><br>After fitting the above models for location only, we were tasked with identifying other variables for predicting salary bands.</p><p>I created four predictors:<br>Seniority_senior<br>Seniority_junior<br>Seniority_mid_level<br>Is_engineer</p><p>To create my seniority predictors, I compiled a dictionary with keys: senior, junior; which mapped to lists containing words that indicate if a job is senior or junior. To create my is_engineer predictor, I checked if the title had the word engineer in it, if it did the cell was 1, if not the cell became 0.</p><h3>Multi-featured models</h3><p><strong>Logistic Regression</strong><br>I fitted a new Logistic Regression model using the location and the new predictors as predictor variables, and salary_band the target once again. The mean cross-validation score for this model was 0.4943, meaning it predicted correctly 49.43% of the time. This was an improvement of approximately 5% on the first Logistic regression model.</p><p>The top 5 predictors for this model were:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5r7yR2n2y5W3-d9vSYgG_w.png" /></figure><p>After this, I used a Grid Search (a python class) to optimise my Logistic Regression hyperparameters. After tuning, the best model had a mean cross-validation score of 0.4836. This is lower than the model before tuning, but this is because it applies a penalty function to ensure the model doesn’t overfit the training data. (Overfitting is when the model cannot generalise to unseen data). It also has the advantage of zeroing out redundant columns, making it possible to prune the features in the model and make it run faster. This is important when running models at scale.</p><p><strong>Decision Tree Classifier</strong><br>For the Decision Tree Classifier, we got a mean cross-validation score of 0.4804. Again, this is an improvement on the location only classifier, and it has a comparable predictive ability as the Logistic Regression model above.</p><p>I tuned the model from the start, I did not fit a model without running it through Grid Search first.</p><p>The top 5 most important features according to this model are:<br>Seniority_senior<br>Location_new_york<br>Is_engineer<br>Location_chicago<br>Location_paris</p><h3>Model Evaluation</h3><p><strong>Logistic Regression</strong></p><p>The goal of this model is to predict the salary bands of a job given the location and job title. It is important, however, that the model does not predict the salary will be HIGH when it is not. If it does, this will undermine client trust, whereas if the model predicts LOW and the salary is HIGH, the client will be happy. The main metric that measures this is called precision. This can be defined as, for all the times the model predicts a certain class, how many of those predictions are correct.</p><p>The model initially had a HIGH precision of 0.6965, meaning that 69.65% of all cases where the model predicted HIGH were correct.</p><p>It is possible to tune this and change the threshold of certainty at which the model will predict whether the class is HIGH or not. I changed the model so that it would predict if the class was HIGH if the probability that it was was greater than 0.6. This raised the precision to 0.8221–82.21% of all predictions of HIGH are correct.</p><p>There is a trade-off here — another metric called recall measures of all the instances of a job actually having a HIGH salary, how many of those does the model correctly classify as having a HIGH salary. For the model without a threshold, the recall is 0.7035. This means that of all actual instances of a HIGH salary, the model correctly classifies 70.35% of them. After adjusting the threshold, though, the recall becomes 0.3367 — the model correctly classifies just 33.67% of all actual instances of HIGH salaries as HIGH. It is important to find the right balance between recall and precision to maximise consumer confidence in this model.</p><p><strong>Decision Tree Classifier</strong></p><p>This model I did not tune with a threshold, but I will still report on the precision and recall scores.</p><p>The precision for predicting HIGH for this model is 0.7253–72.53% of all predictions of HIGH are correct predictions. The recall for predicting HIGH for this model is 0.6834–68.34% of all instances of HIGH are correctly classified as HIGH.</p><p>If I had to pick one model, I would use the Decision Tree Classifier, as it is far more interpretable than a Logistic Regression. Especially for multiclass prediction.</p><p>Thanks for reading about the above web scraping and data modelling project I did. Let me know what you think!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eef8b7d3f8d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>