Policy Information
ML之LoR:利用LoR二分类之非线性决策算法案例应用之划分正负样本
目录
1、对数据集进行特征映射
2、正则化 → 正则化 → 过度正则化
- import numpy as np
- import matplotlib.pyplot as plt
- from sklearn.preprocessing import PolynomialFeatures
- from scipy.optimize import minimize
-
- 加正则化项的损失函数
- def costFunctionReg(theta, reg, *args):
- m = y.size
- h = sigmoid(XX.dot(theta))
-
- J = -1*(1/m)*(np.log(h).T.dot(y)+np.log(1-h).T.dot(1-y)) + (reg/(2*m))*np.sum(np.square(theta[1:]))
-
- if np.isnan(J[0]):
- return(np.inf)
- return(J[0])
评论