One of the most popular projects in General Assembly’s Data Science Immersive is centered around reddit.
One of the most popular projects in General Assembly’s Data Science Immersive is centered around reddit. Your objective: pick two subreddits, collect a thousand posts from each, and build a model to classify the posts back to their correct subreddits from the title. It’s easy to see why this is such a popular project, it comes in at #3 of 5, so we’re starting to get comfortable with our new skillset, and we get to pick our own subreddits, so we can really have some fun with it as well. It’s a good taste of the powerful technology that’s right at the fingertips of data scientists.
For my implementation, I chose two subreddits in a subject that I have a fair amount of domain knowledge in — gaming! I’ve been a gamer from at least the day I was born (rumored but unverified), so I was pretty excited to be able to find my own insights into the gaming world. I chose two subreddits with similar, but distinct subjects, r/gaming and r/pcgaming.
If the difference between these two subreddits isn’t immediately obvious, one of them deals with gaming in general, which can include any of the home consoles, mobile, even board games. The other subreddit deals specifically with gaming on computers, which is not just about the games themselves, but the hardware, software, peripherals, and much more that tends to be a unique experience when gaming on a computer. Of course, there is a lot of overlap between the two subreddits, which is exactly why this makes a great problem to work on!
I recently decided to take some time and run through the project again, not just to collect more data, but also to try implementing some of the improvements I hadn’t gotten around to originally. I have definitely grown as a programmer, so there were plenty of changes I knew I wanted to make even from an efficiency and readability standpoint. Cycling through projects isn’t just a chance to improve the ML training, but a great time to improve your code!Data Collection
As always, the first step is to actually get the data that you’re going to be working with. Originally I had just written the code to make the pulls and left it at that. This time, I wanted to turn it into a real function, so I could continue to make the pulls and not clog up the notebook with big copied code blocks.
def reddit_puller(url, params, user_agent, pulls, post_list): # adapting code from Boom Devahastin Na Ayudhya for pull_num in range(int(pulls)): # stating which pull is being attempted print("Pulling data attempted", pull_num+1, "times") # establishing the request code res = requests.get(url, headers=user_agent, params=params) # pull the correct data if the code is good if res.status_code == 200: json_data = res.json() # Pull JSON post_list.extend(json_data['data']['children']) # Get posts and extend the `posts` list # updating url with the id of the last post in the pull # next pull will grab the following entries after = json_data['data']['after'] params["after"] = after else: print("There has been an error. The code is: ", res.status_code) break # sleeping the func so we aren't locked out time.sleep(2)
When I first pulled the posts from each subreddit, a large amount of what came back ended up being duplicates, and that remained true the second time around. At the end of the second scrape, there were about 2400 unique entries in total.Cleaning and Analysis
The cleaning steps I had originally taken went largely unchanged with the addition of new data. There were a few more cross-posts (posts showing up in both subreddits) and outliers (titles with just emojis/emoticons), so where I had previously addressed these issues manually, I wrote some new scalable code that wouldn’t have to be changed each time the data changes.
# saving the cross-posts as new dfs gaming_cross_posts = gaming_df[gaming_df["title"].isin(pcgaming_df["title"]) == True] pc_cross_posts = pcgaming_df[pcgaming_df["title"].isin(gaming_df["title"]) == True] # dropping all the cross-posts gaming_df.drop(gaming_cross_posts.index, inplace=True) pcgaming_df.drop(pc_cross_posts.index, inplace=True)
I also created a new column from the last iteration, a count of the number of words in each title. I had already made a feature of the total character length, but I wanted to add another dimension to the information. It not only helps to gain insight into the data and the subreddits themselves, but it can be useful as a predictor in the modeling phase later on. Visualizing the data on a histogram, I could clearly see a large amount of overlap in the lengths of the titles, as well as the distinct shift in the length of titles for posts in r/pcgaming compared to r/gaming.
The fact that more posts have titles in the 10–15 word range signals that there may be a higher complexity in what is being discussed in r/pcgaming. From a modeling standpoint, this could mean that a title that is longer may be more likely to be from r/pcgaming than r/gaming, but the effectiveness remains to be seen.
I also took a deeper look into the words themselves, to get a better idea of what types of language make up the targets. I ran the data through a simple
CountVectorizer to find which words were the most common. Then through several iterations, I decided to use
PorterStemmer to simplify the words, and identified typical stopwords to remove, including some additional ones that were specific to this data.
With my new data, I had to go through this process a few more times, identifying even more stopwords to add to my list. In the end, about half of the top words from r/gaming were different this time around, with fewer changes for r/pcgaming, where the top words held a much higher lead.
When going through the lifecycle of a data science project, it may be tempting to get your new data and just jump right back into the modeling phase, but EDA is an important step. Not every situation is the same, so maybe adding a few thousand entries to a dataset that is already in the millions may not make a huge difference, but in this case, I doubled my data so there was a potential for big changes.Modeling
The first time around, modeling was already a fairly complex process. I had significant issues with highly overfit models, but ended up with an
AdaBoostClassifier that had low variance and an accuracy in the high 70s. I had combined the vectorization step with the model training in a
GridSearchCV, to be able to fully optimize each type of classifying algorithm.
This time I made some changes. Since I wanted to add my engineered features — the word and character counts of the titles — I knew I couldn’t just keep my old pipeline in place. I had also found that using
TfidfVectorizer was giving me better results than
CountVectorizer, so I decided to make it a permanent change, and shift it to the preprocessing step as opposed to a part of the grid search (This may not have been the best idea, but I’ll get back to that). So with my words vectorized (and now a sparse matrix), I transformed them and my additional numeric columns into arrays and stacked them together to get my new training data.
I ran through all of my old models again (Logistic Regression, Random Forest, and more), and the first thing I noticed was a large drop in the overfit that had previously been seen in these models. However, there did not seem to be much impact on the accuracy scores (in either direction). Since I had come across more types of algorithms since I had first done the project, I also wanted to try something new that might work even better with this NLP problem. I added a Support Vector Classifier to my lineup and hoped for an amazing result.
I didn’t get one. I pulled up the metrics for all my models — I was going with accuracy for this project because the classes were well balanced, and there was no greater detriment to false positives or false negatives — and compared them. While the SVC was at the top of my list, it actually had a somewhat similar performance to the Logistic Regression model.
So in picking the “best” model of the bunch, it was basically down to those two models, since they seemed to give the best bias/variance balance (unlike KNN or Random Forest). In the end, I chose the SVC as the “best” because it minimized the variance more than the logistic regression improved the performance. However, since the SVC is something of a “black box” model, I wanted to still utilize the logistic regression for its interpretability. Matching the coefficients up with the features, I was able to find what was most important in making the decision for the model.
We can see that the words we had seen in the EDA did end up being very important in the modeling process — “Steam”, “trailer”, and “release” were the same top 3 used words in r/pcgaming. On the other side, having words like “happy” and “friend” meant that a post was very unlikely to be from r/pcgaming. I don’t think I want to dig into what that might say about PC gamers, but I do know that it was very helpful for the model. I also noted that the two extra features I made did not appear anywhere near the top of the coefficients list, which was somewhat disappointing.Wrapping Up
So, what did this new and improved iteration (with fresh data, features, and models) actually get me? Not much, as it turns out. I didn’t make a large impact on the performance (I was already in the 78% accurate range), but I was able to further decrease my variance, which honestly was not huge to begin with.
What happened? There are a few possibilities I’ve thought of. One is that I haven’t given enough new information — maybe 2400 posts just isn’t enough to effectively train a model on this problem — but this feels like a cop-out since you can almost always say that you “need more data”, and I’ve seen fairly consistent performance between both iterations. Another is that I didn’t do enough feature engineering — maybe I need to dig deeper and add data about how many comments there are, or another aspect of these posts hidden in the original JSON files that were pulled. I may also be approaching this too simplistically, and it requires more advanced NLP, like with Word2Vec and using embeddings instead of a “bag of words”.
The other big issue I saw was in my modeling. In the original version, I was testing and optimizing different vectorizers as part of a grid searching/pipeline function. This time around, I added separately engineered features, and I decided to reconfigure my pre-processing to make that easier. In doing so, I removed the ability to optimize the vectorization in conjunction with the new features — maybe with this added information there was a different set of parameters for TF-IDF that would improve the accuracy of certain models, or maybe CVEC was actually the way to go. I recently learned about ScitKit-Learn’s
ColumnTransformer for exactly this kind of combination of different feature transformations into a pipeline, so I think next time around I will be adapting my code to use it
This was absolutely worth coming back to after the GA course and offered a good lesson in what it’s like to go through multiple cycles of a project (and tempering expectations). Of course, you always go back to something with the intent of improving it, but sometimes you don’t make much of an impact. Either way, it’s a chance to learn and grow, so don’t let that pass you by.
As always, thanks for taking this ride on the data science train, and let me know your thoughts on the project — is the SVC really the best model? Should I not engineer more features? Comment below!
Please check out the full project repo here.
Learn Data Science | How to Learn Data Science for Free. In this post, I have described a learning path and free online courses and tutorials that will enable you to learn data science for free.
The average cost of obtaining a masters degree at traditional bricks and mortar institutions will set you back anywhere between $30,000 and $120,000. Even online data science degree programs don’t come cheap costing a minimum of $9,000. So what do you do if you want to learn data science but can’t afford to pay this?
I trained into a career as a data scientist without taking any formal education in the subject. In this article, I am going to share with you my own personal curriculum for learning data science if you can’t or don’t want to pay thousands of dollars for more formal study.
The curriculum will consist of 3 main parts, technical skills, theory and practical experience. I will include links to free resources for every element of the learning path and will also be including some links to additional ‘low cost’ options. So if you want to spend a little money to accelerate your learning you can add these resources to the curriculum. I will include the estimated costs for each of these.
The first part of the curriculum will focus on technical skills. I recommend learning these first so that you can take a practical first approach rather than say learning the mathematical theory first. Python is by far the most widely used programming language used for data science. In the Kaggle Machine Learning and Data Science survey carried out in 2018 83% of respondents said that they used Python on a daily basis. I would, therefore, recommend focusing on this language but also spending a little time on other languages such as R.
Before you can start to use Python for data science you need a basic grasp of the fundamentals behind the language. So you will want to take a Python introductory course. There are lots of free ones out there but I like the Codeacademy ones best as they include hands-on in-browser coding throughout.
I would suggest taking the introductory course to learn Python. This covers basic syntax, functions, control flow, loops, modules and classes.
Next, you will want to get a good understanding of using Python for data analysis. There are a number of good resources for this.
To start with I suggest taking at least the free parts of the data analyst learning path on dataquest.io. Dataquest offers complete learning paths for data analyst, data scientist and data engineer. Quite a lot of the content, particularly on the data analyst path is available for free. If you do have some money to put towards learning then I strongly suggest putting it towards paying for a few months of the premium subscription. I took this course and it provided a fantastic grounding in the fundamentals of data science. It took me 6 months to complete the data scientist path. The price varies from $24.50 to $49 per month depending on whether you pay annually or not. It is better value to purchase the annual subscription if you can afford it.
If you have chosen to pay for the full data science course on Dataquest then you will have a good grasp of the fundamentals of machine learning with Python. If not then there are plenty of other free resources. I would focus to start with on scikit-learn which is by far the most commonly used Python library for machine learning.
When I was learning I was lucky enough to attend a two-day workshop run by Andreas Mueller one of the core developers of scikit-learn. He has however published all the material from this course, and others, on this Github repo. These consist of slides, course notes and notebooks that you can work through. I would definitely recommend working through this material.
Then I would suggest taking some of the tutorials in the scikit-learn documentation. After that, I would suggest building some practical machine learning applications and learning the theory behind how the models work — which I will cover a bit later on.
SQL is a vital skill to learn if you want to become a data scientist as one of the fundamental processes in data modelling is extracting data in the first place. This will more often than not involve running SQL queries against a database. Again if you haven’t opted to take the full Dataquest course then here are a few free resources to learn this skill.
Codeacamdemy has a free introduction to SQL course. Again this is very practical with in-browser coding all the way through. If you also want to learn about cloud-based database querying then Google Cloud BigQuery is very accessible. There is a free tier so you can try queries for free, an extensive range of public datasets to try and very good documentation.
To be a well-rounded data scientist it is a good idea to diversify a little from just Python. I would, therefore, suggest also taking an introductory course in R. Codeacademy have an introductory course on their free plan. It is probably worth noting here that similar to Dataquest Codeacademy also offers a complete data science learning plan as part of their pro account (this costs from $31.99 to $15.99 per month depending on how many months you pay for up front). I personally found the Dataquest course to be much more comprehensive but this may work out a little cheaper if you are looking to follow a learning path on a single platform.
It is a good idea to get a grasp of software engineering skills and best practices. This will help your code to be more readable and extensible both for yourself and others. Additionally, when you start to put models into production you will need to be able to write good quality well-tested code and work with tools like version control.
There are two great free resources for this. Python like you mean it covers things like the PEP8 style guide, documentation and also covers object-oriented programming really well.
The scikit-learn contribution guidelines, although written to facilitate contributions to the library, actually cover the best practices really well. This covers topics such as Github, unit testing and debugging and is all written in the context of a data science application.
For a comprehensive introduction to deep learning, I don’t think that you can get any better than the totally free and totally ad-free fast.ai. This course includes an introduction to machine learning, practical deep learning, computational linear algebra and a code-first introduction to natural language processing. All their courses have a practical first approach and I highly recommend them.
Whilst you are learning the technical elements of the curriculum you will encounter some of the theory behind the code you are implementing. I recommend that you learn the theoretical elements alongside the practical. The way that I do this is that I learn the code to be able to implement a technique, let’s take KMeans as an example, once I have something working I will then look deeper into concepts such as inertia. Again the scikit-learn documentation contains all the mathematical concepts behind the algorithms.
In this section, I will introduce the key foundational elements of theory that you should learn alongside the more practical elements.
The khan academy covers almost all the concepts I have listed below for free. You can tailor the subjects you would like to study when you sign up and you then have a nice tailored curriculum for this part of the learning path. Checking all of the boxes below will give you an overview of most elements I have listed below.
Calculus is defined by Wikipedia as “the mathematical study of continuous change.” In other words calculus can find patterns between functions, for example, in the case of derivatives, it can help you to understand how a function changes over time.
Many machine learning algorithms utilise calculus to optimise the performance of models. If you have studied even a little machine learning you will probably have heard of Gradient descent. This functions by iteratively adjusting the parameter values of a model to find the optimum values to minimise the cost function. Gradient descent is a good example of how calculus is used in machine learning.
What you need to know:
Many popular machine learning methods, including XGBOOST, use matrices to store inputs and process data. Matrices alongside vector spaces and linear equations form the mathematical branch known as Linear Algebra. In order to understand how many machine learning methods work it is essential to get a good understanding of this field.
What you need to learn:
Vectors and spaces
Here is a list of the key concepts you need to know:
The third section of the curriculum is all about practice. In order to truly master the concepts above you will need to use the skills in some projects that ideally closely resemble a real-world application. By doing this you will encounter problems to work through such as missing and erroneous data and develop a deep level of expertise in the subject. In this last section, I will list some good places you can get this practical experience from for free.
“With deliberate practice, however, the goal is not just to reach your potential but to build it, to make things possible that were not possible before. This requires challenging homeostasis — getting out of your comfort zone — and forcing your brain or your body to adapt.”, Anders Ericsson, Peak: Secrets from the New Science of Expertise
Machine learning competitions are a good place to get practice with building machine learning models. They give access to a wide range of data sets, each with a specific problem to solve and have a leaderboard. The leaderboard is a good way to benchmark how good your knowledge at developing a good model actually is and where you may need to improve further.
The UCI machine learning repository is a large source of publically available data sets. You can use these data sets to put together your own data projects this could include data analysis and machine learning models, you could even try building a deployed model with a web front end. It is a good idea to store your projects somewhere publically such as Github as this can create a portfolio showcasing your skills to use for future job applications.
One other option to consider is contributing to open source projects. There are many Python libraries that rely on the community to maintain them and there are often hackathons held at meetups and conferences where even beginners can join in. Attending one of these events would certainly give you some practical experience and an environment where you can learn from others whilst giving something back at the same time. Numfocus is a good example of a project like this.
In this post, I have described a learning path and free online courses and tutorials that will enable you to learn data science for free. Showcasing what you are able to do in the form of a portfolio is a great tool for future job applications in lieu of formal qualifications and certificates. I really believe that education should be accessible to everyone and, certainly, for data science at least, the internet provides that opportunity. In addition to the resources listed here, I have previously published a recommended reading list for learning data science available here. These are also all freely available online and are a great way to complement the more practical resources covered above.
Thanks for reading!
When we talk about data processing, Data Science vs Big Data vs Data Analytics are the terms that one might think of and there has always been a confusion between them. In this article on Data science vs Big Data vs Data Analytics, I will understand the similarities and differences between them
When we talk about data processing, Data Science vs Big Data vs Data Analytics are the terms that one might think of and there has always been a confusion between them. In this article on Data science vs Big Data vs Data Analytics, I will understand the similarities and differences between them
We live in a data-driven world. In fact, the amount of digital data that exists is growing at a rapid rate, doubling every two years, and changing the way we live. Now that Hadoop and other frameworks have resolved the problem of storage, the main focus on data has shifted to processing this huge amount of data. When we talk about data processing, Data Science vs Big Data vs Data Analytics are the terms that one might think of and there has always been a confusion between them.
In this article on Data Science vs Data Analytics vs Big Data, I will be covering the following topics in order to make you understand the similarities and differences between them.
Introduction to Data Science, Big Data & Data AnalyticsWhat does Data Scientist, Big Data Professional & Data Analyst do?Skill-set required to become Data Scientist, Big Data Professional & Data AnalystWhat is a Salary Prospect?Real time Use-case## Introduction to Data Science, Big Data, & Data Analytics
Let’s begin by understanding the terms Data Science vs Big Data vs Data Analytics.
It also involves solving a problem in various ways to arrive at the solution and on the other hand, it involves to design and construct new processes for data modeling and production using various prototypes, algorithms, predictive models, and custom analysis.
Big Data refers to the large amounts of data which is pouring in from various data sources and has different formats. It is something that can be used to analyze the insights which can lead to better decisions and strategic business moves.
Data Analytics is the science of examining raw data with the purpose of drawing conclusions about that information. It is all about discovering useful information from the data to support decision-making. This process involves inspecting, cleansing, transforming & modeling data.
[Source: ibm.com]What Does Data Scientist, Big Data Professional & Data Analyst Do?
Data Scientists perform an exploratory analysis to discover insights from the data. They also use various advanced machine learning algorithms to identify the occurrence of a particular event in the future. This involves identifying hidden patterns, unknown correlations, market trends and other useful business information.
Roles of Data Scientist
The responsibilities of big data professional lies around dealing with huge amount of heterogeneous data, which is gathered from various sources coming in at a high velocity.
Roles of Big Data Professiona
Data analysts translate numbers into plain English. Every business collects data, like sales figures, market research, logistics, or transportation costs. A data analyst’s job is to take that data and use it to help companies to make better business decisions.
Roles of Data AnalystSkill-Set Required To Become Data Scientist, Big Data Professional, & Data Analyst What Is The Salary Prospect?
The below figure shows the average salary structure of **Data Scientist, Big Data Specialist, **and Data Analyst.A Scenario Illustrating The Use Of Data Science vs Big Data vs Data Analytics.
Now, let’s try to understand how can we garner benefits by combining all three of them together.
Let’s take an example of Netflix and see how they join forces in achieving the goal.
First, let’s understand the role of* Big Data Professional* in Netflix example.
Netflix generates a huge amount of unstructured data in forms of text, audio, video files and many more. If we try to process this dark (unstructured) data using the traditional approach, it becomes a complicated task.
Approach in Netflix
Traditional Data Processing
Hence a Big Data Professional designs and creates an environment using Big Data tools to ease the processing of Netflix Data.
Big Data approach to process Netflix data
Now, let’s see how Data Scientist Optimizes the Netflix Streaming experience.
Role of Data Scientist in Optimizing the Netflix streaming experience
User behavior refers to the way how a user interacts with the Netflix service, and data scientists use the data to both understand and predict behavior. For example, how would a change to the Netflix product affect the number of hours that members watch? To improve the streaming experience, Data Scientists look at QoE metrics that are likely to have an impact on user behavior. One metric of interest is the rebuffer rate, which is a measure of how often playback is temporarily interrupted. Another metric is bitrate, that refers to the quality of the picture that is served/seen — a very low bitrate corresponds to a fuzzy picture.
How do Data Scientists use data to provide the best user experience once a member hits “play” on Netflix?
One approach is to look at the algorithms that run in real-time or near real-time once playback has started, which determine what bitrate should be served, what server to download that content from, etc.
For example, a member with a high-bandwidth connection on a home network could have very different expectations and experience compared to a member with low bandwidth on a mobile device on a cellular network.
By determining all these factors one can improve the streaming experience.
A set of big data problems also exists on the content delivery side.
The key idea here is to locate the content closer (in terms of network hops) to Netflix members to provide a great experience. By viewing the behavior of the members being served and the experience, one can optimize the decisions around content caching.
Another approach to improving user experience involves looking at the quality of content, i.e. the video, audio, subtitles, closed captions, etc. that are part of the movie or show. Netflix receives content from the studios in the form of digital assets that are then encoded and quality checked before they go live on the content servers.
In addition to the internal quality checks, Data scientists also receive feedback from our members when they discover issues while viewing.
By combining member feedback with intrinsic factors related to viewing behavior, they build the models to predict whether a particular piece of content has a quality issue. Machine learning models along with natural language processing (NLP) and text mining techniques can be used to build powerful models to both improve the quality of content that goes live and also use the information provided by the Netflix users to close the loop on quality and replace content that does not meet the expectations of the users.
So this is how Data Scientist optimizes the Netflix streaming experience.
Now let’s understand how Data Analytics is used to drive the Netflix success.
Role of Data Analyst in Netflix
The above figure shows the different types of users who watch the video/play on Netflix. Each of them has their own choices and preferences.
So what does a Data Analyst do?
Data Analyst creates a user stream based on the preferences of users. For example, if user 1 and user 2 have the same preference or a choice of video, then data analyst creates a user stream for those choices. And also –
Orders the Netflix collection for each member profile in a personalized way.We know that the same genre row for each member has an entirely different selection of videos.Picks out the top personalized recommendations from the entire catalog, focusing on the titles that are top on ranking.By capturing all events and user activities on Netflix, data analyst pops out the trending video.Sorts the recently watched titles and estimates whether the member will continue to watch or rewatch or stop watching etc.
I hope you have *understood *the *differences *& *similarities *between Data Science vs Big Data vs Data Analytics.
Python Programming & Data Handling
Students will be able to know various commands include:
Python Basic Programming
string,if else,Range, for loop, while loop, making functions, tuple, dictionary etc
Download files from Web, Exceptional Handling etc
Get data from files create , read, write, delete.
IMAGE PROCESSING: (NEW DEVELOPING ART)
Image transformation , Image crop , edit and much more
Listener should know how about very basic C Language basic commands to understand Python Language
What will you learn
I will more update if any student want need to add more skills related to python