This is a beginner-friendly program that can tell whether a piece of text is positive or negative. It's perfect for learning the basics of machine learning using Python and scikit-learn.
This program reads text and decides if the message is positive or negative.
The program uses three main parts:
- A tool to convert words into numbers that the computer can understand
- A simple learning model that learns patterns from examples
- A friendly interface where you can type sentences and get results
You need Python installed on your computer and two extra packages:
First package: pandas (for handling data) Second package: scikit-learn (for machine learning)
To install these, open your command prompt or terminal and type:
pip install pandas scikit-learn
The program learns from a file called "sentiment_dataset.csv". This file should be like a spreadsheet with two columns:
- A column called "text" with example messages
- A column called "label" that says if each message is positive or negative
- First, make sure you have installed everything needed
- Put the "sentiment_dataset.csv" file in the same folder as the program
- Open your command prompt or terminal
- Go to the folder containing the program
- Type: python text_classification.py
- The program will start and ask you to type a message
- Type any message you want to analyze
- To stop the program, just type "exit" or "quit"
When you run the program, it works like this:
Program: "Enter a sentence to analyze sentiment:"
You type: "I really enjoyed this movie"
Program tells you: "Predicted sentiment: positive"
Program: "Enter a sentence to analyze sentiment:"
You type: "This was a terrible experience"
Program tells you: "Predicted sentiment: negative"
This is a basic version meant for learning. If you want to make it better, you could:
- Add more training examples
- Use more advanced text processing
- Add ways to check how accurate the program is
- Try different types of learning models
- Make the program handle more complex sentences