Member-only story
Andrew Ng’s Machine Learning Course in Python (Logistic Regression)
Continuing from the series, this will be python implementation of Andrew Ng’s Machine Learning Course on Logistic Regression.
Logistic regression is used in classification problems where the labels are a discrete number of classes as compared to linear regression, where labels are continuous variables.
Same as usual, we start with importing of libraries and the dataset. This dataset contains 2 different test score of students and their status of admission into the university. We are asked to predict if a student gets admitted into a university based on their test scores.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pddf=pd.read_csv("ex2data1.txt",header=None)
Making sense of the data
df.head()
df.describe()
Plotting of the data
pos , neg = (y==1).reshape(100,1) , (y==0).reshape(100,1)
plt.scatter(X[pos[:,0],0],X[pos[:,0],1],c="r",marker="+")
plt.scatter(X[neg[:,0],0],X[neg[:,0],1],marker="o",s=10)
plt.xlabel("Exam 1 score")
plt.ylabel("Exam 2 score")…