Logistic Regression

  • Even with the name containing 'regression' keyword, it is a classification model.
  • It is not necessary to apply feature scaling while preparing this model because it is inbuilt in the model definition, but still scaling the data as part of pre-processing makes it even more effective.
# FEATURE SCALING
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# MODEL TRAINING
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)
classifier.predict(X_test)

# PREDICTING ON A CUSTOM FEATURES
classifier.predict(sc.transform([[col_1_val, col_2_val, ...]]))
# CONFUSION MATRIX
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)

# ACCURACY SCORE
from sklearn.metrics import accuract_score
accuract_score(y_test, y_pred)