斯坦福ML课程——python转写(Week3—课程作业ex2_2)

利用python完成课程作业ex2的第二部分,第二部分的要求如下:

In this part of the exercise, you will implement regularized logistic regression to predict whether microchips from a fabrication plant passes quality assurance (QA). During QA, each microchip goes through various tests to ensure it is functioning correctly. Suppose you are the product manager of the factory and you have the test results for some microchips on two dierent tests. From these two tests, you would like to determine whether the microchips should be accepted or rejected. To help you make the decision, you have a dataset of test results on past microchips, from which you can build a logistic regression model.

在ex2_reg.m的代码中,我将其分为四个部分,每个部分分别如下:

Part 1: Plotting 
Part 2: Regularized Logistic Regression 
Part 3: Regularization and Accuracies 
Part 4: PLot Decision Boundary 
该算法的整体结构,实用性和可读性低,即部分是没有定义函数的,输出的时候也没有明确的指示,在完成整个作业之后会重新对算法进行进一步的修改。我的代码如下:

# -*- coding: utf-8 -*-
"""
Created on Wed Nov 13 09:55:27 2019

@author: Lonely_hanhan
"""
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as op
from mpl_toolkits.mplot3d import Axes3D

Data = np.loadtxt('D:\exercise\machine-learning-ex2\ex2\ex2data2.txt', delimiter=',')
X = Data[:,0:2]
[m,n] = X.shape
Y = Data[:,2] #此处读取的时一维数组,需转化为m维数组
Y = Y.reshape((m,1))

''' ==================== Part 1: Plotting ==================== '''

pos = np.where(Y == 1)
neg = np.where(Y == 0)

#由于Y为二维数组,所以where得到的值都为tuple类型,需提
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值