首页 > 编程语言 >Python代码编写辅导:CSC411 Digit Classification

Python代码编写辅导:CSC411 Digit Classification

时间:2022-10-26 18:23:34浏览次数:77  
标签:Digit Classification dh Python args len dx dy norm

全文链接:tecdat.cn/?p=29674

Requirement

In this assignment, you will compare the characteristics and performance of different classifiers, namely logistic regression, k-nearest neighbours and naive Bayes. You will experiment with these extensions and extend the provided code. Note that you should understand the code first instead of using it as a black box.
Python versions of the code have been provided. You are free to work with whichever you wish.

Analysis

作为Machine Learning的三大基础算法

  1. Logistic regression,也就是logistic回归,常用于数据挖掘,疾病自动诊断,经济预测等领域
  2. K-nearest neighbours,也就是K邻近算法,常用于数据挖掘,以及分类,对未知事物的识别等领域
  3. Naive Bayes,也就是朴素贝叶斯,常用于分类器,文本分类识别

本题给出了以上三大算法的基本实现,但是需要根据测试框架的调度逻辑,实现未完成的测试函数。
本题偏重工程性质,在不断的调试中,会加深对算法的理解。

Tips

下面是check_grad函数的实现

def check_grad(func, X, epsilon, *args):
  if len(X.shape) != 2 or X.shape[1] != 1:
    raise ValueError("X must be a vector")

  y, dy, = func(X, *args)[:2]         # get the partial derivatives dy
  dh = np.zeros((len(X), 1))

  for j in xrange(len(X)):
    dx = np.zeros((len(X), 1))
    dx[j] += epsilon
    y2 = func(X+dx, *args)[0]
    dx = -dx
    y1 = func(X+dx, *args)[0]
    dh[j] = (y2 - y1)/(2*epsilon)

  print np.hstack((dy, dh))          # print the two vectors
  d = LA.norm(dh-dy)/LA.norm(dh+dy)  # return norm of diff divided by norm of sum

  return d
复制代码

标签:Digit,Classification,dh,Python,args,len,dx,dy,norm
From: https://www.cnblogs.com/tecdat/p/16829508.html

相关文章

  • python进程
    1、进程概念进程是一个执行中的程序,资源分配的最小单位。每个进程都拥有自己的地址空间、内存、数据栈以及其他用于跟踪执行的辅助数据。在单核CPU系统中的多进程,内存中可......
  • Python基础21
    今日内容概要第三方模块的下载与使用网络爬虫模块值requests模块网络爬虫实战之爬取链家二手房数据自动化办公领域之openpyxl模块今日内容详细第三方模块的下载与......
  • 转 python 自动监控表空间,并自动添加数据文件
    侯志清-江西南昌 python自动监控表空间,并自动添加数据文件#!/usr/bin/pythonimportosimporttimeimportlinecache#定义记录日志文件defrlog(log)......
  • python进程
    1、概念进程是一个执行中的程序,资源分配的最小单位。每个进程都拥有自己的地址空间、内存、数据栈以及其他用于跟踪执行的辅助数据。在单核CPU系统中的多进程,内存中可以有......
  • python切片数组越界?
    1.在对list进行切片时,如x[9:12],若len(x)=10,只会返回x[9],而不会像其他语言直接数组越界错误。x=[iforiinrange(10)]print(x)foriinrange(0,10,3):print(x[i:i+3]......
  • 图像处理:opencv-python给图像加文字
    1.起因计算机视觉中常常会需要在图片上加文字,这样可以增强图像数据的可读性。2.工具opencv-python3.方法importmatplotlib.pyplotaspltfromPILimportImag......
  • python3 使用位图排序
    代码frombitmapimportBitMapa=[1,5,3,4,7,8,15,6,9]print(a)bm=BitMap(max(a))#print(dir(bm))print(bm.tostring())foriina:bm.set(i)print(bm......
  • 哈夫曼树及python实现
    3.1基本概念路径和路径长度:树中一个结点到另一个结点之间的分支构成这两个结点之间的路径;路径上的分枝数目称作路径长度,它等于路径上的结点数减1.结点的权和带权路径长度......
  • python的优雅退出
    #!/usr/bin/envpython#-*-coding:utf-8-*-importosimportsignalimportsysfromconcurrentimportfuturesimportloggingfromloguruimportloggerimpor......
  • 刷题——Python篇(0)Hello World
    前言刷题对语言的初学者是很有帮助的。在刷题过程中,可以查漏补缺,巩固知识点。此外对将来的招聘,这也是一种提前的练习。有很多刷题的网站:CSDN的学习版块​​​牛客网​​​:......