Machine Learning vs. Traditional Programming

Mayank Sharma
Sep 7, 2018 · 2 min read

Example: Analyzing the sentiment of a popular media outlet and classifying that sentiment as positive or negative.

Traditional programming approach

The algorithm may first look for particular words associated with a negative or positive sentiment.

With conditional statements, the algorithm would classify articles as positive or negative based on the words that it knows are positive or negative.

// pseudocode
let positive = [
"happy",
"thankful",
"amazing"
];
let negative = [
"can't",
"won't",
"sorry",
"unfortunately"
];

These are arbitrarily chosen by the programmer. Once we have the list of positive and negative examples, one simple algorithm is to simply count up the occurrences of each type of word in a given article. Then, the article can be classified as positive or negative based on which word count is higher, the positive examples or the negative examples.

Machine learning approach

The algorithm analyzes given media data and learns the features that classify what a negative article looks like versus a positive article.

With what it has learned, the algorithm can then classify new articles as positive or negative. As a machine learning programmer in this case, you won’t be explicitly specifying the words for the algorithm to recognize. Instead, the algorithm will “learn” that certain words are positive or negative based on labels given to each article it examines.

// pseudocode
let articles = [
{
label: "positive",
data: "The lizard movie was great! I really liked..."
},
{
label: "positive",
data: "Awesome lizards! The color green is my fav..."
},
{
label: "negative",
data: "Total disaster! I never liked..."
},
{
label: "negative",
data: "Worst movie of all time!..."
}
];
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade