参考链接:https://blog.csdn.net/ziqu5721/article/details/88186629
假设函数:
代价函数:
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid",color_codes=True)
data = pd.read_csv('ex2data1.txt',header=None,names=['Exam 1','Exam 2','Admitted'])
print(data.head())
positive = data[data['Admitted'].isin([1])] #所有admitted为1的值归类
negative = data[data['Admitted'].isin([0])] #值为0的数据归类
fig,ax = plt.subplots(figsize=(10,6))
ax.scatter(positive['Exam 1'],positive['Exam 2'],s=50,c='b',marker='o',label='Admitted')
ax.scatter(negative['Exam 1'],negative['Exam 2'],s=50,c