Supervised Learning — Logistic Regression
Model and estimate the probability of an even occurring depending on other independent variables.
Linear regression are often prone to errors caused by skewed data input (Outlier) that drastically change the linear regression model
Most of the real world example are non linear in nature, in most binary classification problem logistic regression is the best bet e.g. based on credit score if someone is going to get the loan approval or not.
Regression coefficients for logistic regression are computed using Maximum Likelihood Estimation (MLE)
Generic Steps of Modeling
Get the train and test data sets
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.33, random_state = 0)Rescale the data
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)Build the Regression Model
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state=0)
classifier.fit(x_train, y_train)Create the prediction set
y_pred = classifier.predict(x_test)check the Accuracy using Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
accuracy = accuracy_score(y_test, y_pred)