A logistic regression model can be created by importing scikit-learn's LogisticRegression method. We load the packages as we did previously for creating a linear regression model:
import pandas as pdimport numpy as npfrom sklearn import preprocessingimport matplotlib.pyplot as pltfrom sklearn.linear_model import LogisticRegression
We will use the dataset of an HR department that has the list of employees who have attrited in the past along with the employees who are continuing in the job:
hr_data = pd.read_csv('data/hr.csv', header=0)hr_data.head()hr_data = hr_data.dropna()print(hr_data.shape)print(list(hr_data.columns))
The output of the preceding code is as follows:
The dataset has ...