Converting text into Vectors
Before converting the data into vectors, split it into train and test.
Python3
from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score from sklearn.linear_model import LogisticRegression x_train, x_test, y_train, y_test = train_test_split(data[ 'text' ], data[ 'class' ], test_size = 0.25 ) |
Now we can convert the training data into vectors using TfidfVectorizer.
Python3
from sklearn.feature_extraction.text import TfidfVectorizer vectorization = TfidfVectorizer() x_train = vectorization.fit_transform(x_train) x_test = vectorization.transform(x_test) |
Fake News Detection using Machine Learning
Fake news on different platforms is spreading widely and is a matter of serious concern, as it causes social wars and permanent breakage of the bonds established among people. A lot of research is already going on focused on the classification of fake news.
Here we will try to solve this issue with the help of machine learning in Python.
Before starting the code, download the dataset by clicking the link.