Machine learning with logistic regression
You are familiar with the steps of training and testing a classifier. With logistic regression, we will do the following:
- Load data into feature and target arrays,
Xandy, respectively - Split the data into training and testing sets
- Train the logistic regression classifier on the training set
- Test the performance of the classifier on the test set
Getting ready
Define X, y – the feature and target arrays
Let's start predicting with scikit-learn's logistic regression. Perform the necessary imports and set the input variables X and the target variable y:
import numpy as np import pandas as pd X = all_data[feature_names] y = all_data['target']
How to do it...
Provide training and testing sets
- Import
train_test_splitto create testing and training sets for bothXandy: the inputs and target. Note thestratify=y, which stratifies the categorical variabley. This means that there are the same proportions of zeros and ones in bothy_trainandy_test:
from sklearn.model_selection...