Logistic regression is a standard method of performing binary classification, which matches your task here. Categorical variables can be dealt with, depending on the model you choose.
You can see from the Scikit-Learn documentation on logistic regression, that your data only really needs to be of a certain shape: (num_samples, num_features)
. It might ignore the columns that are non-numerical, so you should convert e.g. strings to class IDs (e.g. integers) - see below.
Computing the correlation can make sense for categorical values, but to compute these, you need to provide numerical values; strings like "bbc.com" or "US" won't work.
You can map each of the values to a numerical value and make a new column with that data using pd.factorize
like this:
df["Country_id"] = pd.factorize(df.Country)[0] # taking the first return element: the ID values
df["Name_id"] = pd.factorize(df.Name)[0]
You don't need to do it really for the approved
and political
columns, because they hold boolean
values, which are seen by Python as 0
and 1
for False
and True
, respectively.
Now you can do something like this to see a correlation plot:
import matplotlib.pyplot as plt # plotting library: pip install matplotlib
# compute the correlation matrix
corr_mat = df[["Name_id", "Country_id", "approved", "political"]].corr()
# plot it
plt.matshow(corr_mat)
plt.show()