参考代码:
https://blog.csdn.net/zy1337602899/article/details/84777396
初次写机器学习的代码,大部分参照了链接文章中的代码,稍有改动
源代码
// An highlighted block
import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as opt
from sklearn.metrics import classification_report
import pandas as pd
from sklearn import linear_model
#获取原始数据
def raw_data(path):
data = pd.read_csv(path, names=['exam1','exam2','admit'])
return data
#绘制原始数据
def draw_data(data):
accept = data[data['admit'] == 1]
refuse = data[data['admit'] == 0]
plt.scatter(accept['exam1'], accept['exam2'], c='g', label='admit')
plt.scatter(refuse['exam1'], refuse['exam2'], c='r', label='refuse')
plt.title('admission')
plt.xlabel('exam1')
plt.ylabel('exam2')
return plt
#sigmoid函数
def sigmoid(z):
return 1/(