top of page

Confused about AI? Scared of Machine Learning? Understand the Key Differences with Examples

The Southern Tech Lady blog image (Ashely Kelly)

I know that you have probably heard the term "AI" lately. Maybe you have heard conversations surrounding the fears of "AI" taking our jobs or computers taking over the world. You probably heard it from people on the news, on social media, in discussions with family and friends or maybe even overhearing a conversation at the grocery store (Ok, maybe that was just me being nosy last week.😉). Recently, these conversations have made me start to think about how terms like "AI" (which is short for artificial intelligence) are actually used in place of "ML" (which is short for machine learning). Depending on whether or not you're actually into tech or data science, you probably have never even heard of "ML" before, but ML is a subset of AI. While they are related concepts, they represent distinct approaches to achieving intelligent behavior in machines. In this blog post, I wanted to talk about the similarities and differences between AI and machine learning, and give some Python examples too.


Understanding AI and Machine Learning

Artificial Intelligence (AI) encompasses a broad spectrum of techniques aimed at enabling computers to perform tasks that typically require human intelligence. These tasks may include reasoning, problem-solving, perception, understanding natural language, and more. The overarching purpose of AI systems is to mimic human cognitive abilities to varying degrees.


Machine Learning (ML), on the other hand, is a subset of AI that focuses on the development of algorithms that allow the computers to learn patterns and make decisions based on data without being explicitly programmed. It emphasizes the utilization of statistical techniques to enable machines to improve their performance on a task through experience.


Differentiating Between AI and Machine Learning

While AI is a broader concept encompassing various approaches to mimic human intelligence, machine learning is a specific technique employed within AI to facilitate learning from data. To illustrate this difference, let's consider two Python examples—one demonstrating AI and the other showcasing machine learning.


AI: The Foundation of Chatbot Intelligence

Since chatbots are all the rage now, I decided to use a simple chatbot as an example. It operates on predefined rules and patterns.

# AI Chatbot Example
def chatbot_response(user_input):
    # Simulated AI logic to generate responses
    if "hello" in user_input.lower():
        return "Hello! How can I assist you today?"
    elif "weather" in user_input.lower():
        return "The weather forecast for today is sunny with a high of 75°F."
    elif "thanks" in user_input.lower():
        return "You're welcome! Feel free to ask if you need further assistance."
    else:
        return "I'm sorry, I didn't understand that. Can you please rephrase?"

# Main loop for interacting with the chatbot
while True:
    user_input = input("You: ")
    response = chatbot_response(user_input)
    print("Chatbot:", response)

This chatbot is based on predefined rules or patterns (if-else statements) to respond to user inputs. It is a simple decision tree that follows a specific set of rules to determine exactly what to say next. Think about how you use a vending machine. There are a set number of items inside, and the amount of money and code that you put in correspond to a specific item in the machine. If you press a button that is not programmed to a specific item in the vending machine, then you get, well, nothing.


Within the scope of a chatbot, while effective within its (limited) scope, this approach lacks adaptability and fails to handle any nuance in user queries beyond its programmed capabilities. The main idea that I want you to understand here is that the outcomes are already known. You can't even paraphrase one of the given inputs and expect to get a response from this algorithm. The algorithm is not learning or coming up with outcomes as the user inputs more. The output will be "I'm sorry, I didn't understand that. Can you please rephrase?" for any input outside of the three pre-defined options that the programmer thought to add above. In this case, the responses will not improve over time. If the algorithm is unaware of something, then it will never know it unless a real person adds to the list of inputs and outputs.


ML: Enhancing Chatbot Intelligence through Learning

As our journey progresses, our chatbot evolves, incorporating machine learning techniques to enhance its intelligence. Inspired by the need for adaptability and self-improvement, our chatbot ventures into the realm of ML for further development.

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split

# Load dataset containing user queries and corresponding responses
conversation_data = pd.read_csv("conversation_data.csv")

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(conversation_data['user_query'],                                                    conversation_data['response'], test_size=0.2, random_state=42)

# Feature extraction using CountVectorizer
vectorizer = CountVectorizer()
X_train_vectors = vectorizer.fit_transform(X_train)
X_test_vectors = vectorizer.transform(X_test)

# Train a Naive Bayes classifier
classifier = MultinomialNB()
classifier.fit(X_train_vectors, y_train)

# Evaluate the classifier
accuracy = classifier.score(X_test_vectors, y_test)
print("Accuracy:", accuracy)

# Main loop for interacting with the ML-enhanced chatbot
while True:
    user_input = input("You: ")
    user_input_vector = vectorizer.transform([user_input])
    response = classifier.predict(user_input_vector)
    print("Chatbot:", response[0])

In this ML example, the chatbot does not have predefined responses for every possible input. For example, the input file (conversation_data.csv) may look something like this:

user_query, response
"Hi, how are you?","I'm doing well, thank you."
"What's the weather like today?","The weather forecast for today is sunny with a high of 75°F."
"Can you help me with something?","Of course! What do you need help with?"
"Thank you for your assistance.","You're welcome! Feel free to ask if you need further assistance."
"Tell me a joke.","Why don't scientists trust atoms? Because they make up everything!"
"What's the capital of France?","The capital of France is Paris."
"How do I cook pasta?","To cook pasta, bring a pot of water to a boil, add salt, and then add the pasta. Cook until al dente, then drain and serve with your favorite sauce."
"Goodbye.","Goodbye! Have a great day!"

You may notice that there are still only a finite number of query options in this file as well. The major difference lies in the code though. In this example, the Multinomial Naive Bayes algorithm is used to help the chatbot adapt to user input patterns by analyzing the patterns in the data and predicting the appropriate responses based on the input from the user. Unlike the AI example above, the algorithm will give you a response almost every time because it is looking for the most appropriate response. This chatbot iteratively refines its intelligence as it gets more data and it can improve over time. So, the algorithm is actually learning from itself. Hence the term, machine learning.


Machine Learning is actually what is being referred to (vs AI) when you hear mentions of tools like Chat GPT or even MidJourney. You always get a response. You may not like the response, but it's up to the user to have enough knowledge to know whether or not the output is useful. In this example I use a really small file to show you what's going on, but in most cases this data is being pulled from one or more sources on the internet. It is important to note that data is still finite. So, an actual person is still required to essentially add data to the database (in most cases that exist today).


Conclusion: Uniting AI and ML for Intelligent Systems and Responsible Innovation

As our chabot discussion above demonstrates, general AI and ML are very similar yet distinct in their approaches. AI provides the foundational principles for mimicking human intelligence, while ML teaches systems to learn and adapt from data, fostering intelligence augmentation. By building on both of these concepts, we pave the way for the development of intelligent systems capable of navigating complex and time-sensitive tasks and interactions. As more people with certain morals and standards understand this, then both AI and ML can ultimately reshape the technological landscape for the better.


While concerns about AI's potential risks persist, it's essential to recognize the ethical imperative guiding our advancements. Artificial Intelligence offers promising solutions, and the integration of Machine Learning fosters responsible intelligence. By prioritizing transparency, accountability, and inclusivity in our AI endeavors, we mitigate potential harms and ensure that our technological innovations serve humanity's collective well-being.

62 views0 comments

Comentários


bottom of page