3.3 编程实现对率回归,并给出西瓜数据集3.0alpha(89页表4.9)上的结果。
"""
Author: Victoria
Created on: 2017.9.14 11:00
"""
import matplotlib.pyplot as plt
import numpy as np
import xlrd
def sigmoid(x):
"""
Sigmoid function.
Input:
x:np.array
Return:
y: the same shape with x
"""
y =1.0 / ( 1 + np.exp(-x))
return y
def newton(X, y):
"""
Input:
X: np.array with shape [N, 3]. Input.
y: np.array with shape [N, 1]. Label.
Return:
beta: np.array with shape [1, 3]. Optimal params with newton method
"""
N = X.shape[0]
#initialization
beta = np.ones((1, 3))
#shape [N, 1]
z = X.dot(beta.T)
#log-likehood
old_l = <