STATS3DA3 K-NearestNeighbors(KNN)

news/2025/2/24 18:29:36/文章来源:https://www.cnblogs.com/tellingme/p/18734633

STATS 3DA3

Homework Assignment 3

Instruction

• Due before 10:00 PM on Friday, February 28, 2025.

•  Upload a PDF copy of your solutions to Avenue to Learn.  You do not need to rewrite the questions in your submission.

• Late Submission Penalty:  A 15% deduction per day will be applied to assignments submitted after the deadline.

• Late Submission Limit: Assignments submitted more than 72 hours late will receive a grade of zero.

• Grace Period for Accommodations: A 72-hour extension beyond the due date is granted for students with approved accommodations through SAS.

•  Your submission must follow the Assignment Standards listed below.

Assignment Standards

•  Include a title page with your name and student number.  Assignments without a title page will not be graded.

•  Use Quarto Jupyter Notebook for your work (strongly recommended).

•  Format your document with an 11-point font (Times or similar), 1.5 line spacing, and 1-inch margins on all sides.

•  Use a new page for the solution to each question (e.g., Question 1Question 2Question 3).

– Clearly number all solutions and sub-parts.

•  Do not include screenshots in your submission; they will not be accepted.

•  Ensure your writing and referencing are appropriate for the undergraduate level.

•  You may discuss homework problems with other students, but you must prepare and submit your own written work.

•  The originality of submitted work will be checked using various tools, including publicly available internet tools.

Assignment Policy on the Use of Generative AI

•  The use of Generative AI is not permitted in assignments, except for using GitHub Copilot as a coding assistant.

 If GitHub Copilot is used, you must clearly indicate this in the code comments.

•  In alignment with McMaster academic integrity policy, it “shall be an offence knowingly to submit academic work for assessment that was purchased or acquired from another source”. This includes work created by generative AI tools. Also state in the policy is the following, “Contract Cheating is the act of”outsourcing of student work to third parties” with or without payment.”  Using Generative AI tools is a form of contract cheating. Charges of academic dishonesty will be brought forward to the Office of Academic Integrity.

Question:

In this assignment, you will explore K-Nearest Neighbors (KNN) and Decision Tree classification algorithms.  You will apply both techniques to a dataset from the UCI Machine Learning Reposi-tory, gaining hands-on experience in data retrieval, preprocessing, model building, and evaluation. This exercise is designed to strengthen your understanding of classification methods and their ap- plications in real-world scenarios.

Dataset:

The dataset for this assignment is the Wine Quality Database, which includes 12 input attributes to predict the wine quality.  Your objective is to build classifiers that accurately predict the wine quality category based on these attributes.

•  Dataset Link: https://archive.ics.uci.edu/dataset/186/wine%2Bquality.

1)  How many observations (rows) and features (variables) are present in the dataset?

2)  What types of attributes are included in the dataset? Identify which attributes are numerical, categorical, or of other types.

3)  Which variable serves as the response (target) if our goal is to build a classifier to predict the wine quality?

4)  Are there any missing values in the dataset? If so, describe how you would handle them.

5)  Display five rows from the original dataset, 代写STATS 3DA3 K-Nearest Neighbors (KNN) which includes both predictors and the response variable.

Hint: You can access the predictors and response by using data.original in the fetched dataset.

6)  Is any transformation necessary for the response variable? Apply the transformation if needed. Additionally, how balanced is the dataset in terms of the response variable?

7)  Remove observations with quality scores of 3, 4, 8, and 9 from the original dataset.  Use this filtered data to complete questions 8 through 19.

Hint: Use isin([3, 4, 8, 9]) to identify the observations to drop.

8)  After filtering, how many unique quality scores remain in the dataset?

9)  Are there any potential outliers in the filtered dataset?  Describe the method(s) you would use to identify them.

Note: You do not need to handle the outliers, only describe how to detect them.

10)  Separate the predictors and the response variable from the filtered dataset.

11)  Are any data transformations necessary for the features before training a classification tree model? If so, explain the rationale and apply the transformation.

12)  Split the dataset (filtered in Part (10) and transformed in Part (11)) into training (80%) and testing (20%) subsets.

13)  Train a classification tree model using the training data and perform model selection through cross-validation (e.g., tuning tree depth). After identifying the best model based on validation performance, evaluate its final performance on the test data.

Hint: Use the Gini index to grow the tree and classification accuracy for model selection.

14)  Using the best classification tree model, identify the two most important features for predict- ing wine quality.

15)  Write at least one statement summarizing the classification tree model’s performance and its implications in the context of the dataset and the problem.

16)  Create copies of X_train and X_test from Part (12) and save them as X_train2 and X_test2.

17)  Is any additional data transformation necessary for features before training a KNN classifier model?  If so, write the rationale for the transformation and then apply the transformation to the features in X_train2 and X_test2.

Hint:  Explain why feature scaling may or may not be necessary for KNN and how it could affect model performance.

18)  Using the training data (X_train2, y_train), train a K-Nearest Neighbors (KNN) classifier  and perform model selection through cross-validation  (e.g., tuning the neighborhood size). After selecting the best model based on validation performance, evaluate its final performance  on the test data (X_test2, y_test).

Note:

1)  If any transformations were applied to X_train2 and X_test2 in Part 17, ensure those trans- formed datasets are used here.

2)  Begin tuning the neighborhood size for cross-validation starting from 2.

19)  Write at least one statement summarizing the KNN classifier model’s performance and its implications in the context of the dataset and the problem.

20)  Write at least two statements that compare and contrast classification and KNN classifers performance and interpretation of the model on the test set.

Grading scheme

1.

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

answer [1]

answer [1]

answer [1]

Codes and answer [2]

Codes [1]

Codes and answer [2]

Codes [1]

Codes and answer [1]

Codes and answer to detect outliers [2]

Codes [1]

Rationale and Codes [2]

Codes [1]

Codes for cross-validation [1], rationale for best model selection

[1], codes for test perfomance [1]

 

14.

15.

16.

17.

18.

Codes and write an answer [1]

1 statement [1]

Codes [1]

Rationale and Codes [2]

Codes for cross-validation [1], rationale for best model selection

[1], codes for test perfomance [1]

 

19.

20.

1 statement [1]

2 statemens to compare and contrast [2]

The maximum point for this assignment is 30. We will convert this to 100%.

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/889119.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【攻防世界】hit_the_core

core文件如果bin文件内容过多,可以用linux的strings命令辅助分析

【攻防世界】神奇的Modbus

ModBus是工业领域常用的设备之间通信的协议在modbus数据包中追踪字节流即可得到flag

kettle调度管理系统XXK-PDI,kettle调度好帮手

最近两天感冒了,而且莫名其妙的嗓子哑了好几天,心情很是不爽。周末两天啥也不想干,坐在电脑旁边继续手撕kettle调度系统。 1、其实之前有整理过kettle的调度方法,有很多种,根据自己的需求合理选择其中的一种,如下图所示:2、kettlePack 应该是深度集成kettle,将kettle的…

记录---Vue的scoped原理是什么?

🧑‍💻 写在开头 点赞 + 收藏 === 学会🤣🤣🤣前言还记得几年前我去找前端工作的时候,那时候才初入职场,有一次去面试,然后被面试官问过一个面试题,Vue中Scoped的原理是什么?幸好当时八股文面试题背的很多,我当时就说是在选择器加了一个唯一的属性实现的,那时候…

用链表实现队列

问题:链表和数组,哪个队列更快? 分析:队列是先进后出 数组是连续存储的,push很快,shift 很慢   链表是非连续存储,add 和 delete 都很快 结论:链表实现队列更快链表实现队列单向链表,要同时记录 head 和 tail 要从tail 入队,从head 出队 length要实时记录,不可遍历…

PLC及CNC数控机床设备运行状态工艺参数节拍产量采集焊接设备

序号 车间 产线 设备名称 设备数量 控制器 控制器型号 通讯接口 设备采集参数 增加转 类型 换模块1 焊洗 焊洗4线 压簧支柱焊接设备 1 PLC 三菱FX1N 串口 设备运行状态;节拍;产量 是2 焊洗 焊洗4线 机脚焊接设备 1 PLC 三菱FX3U 串口 设备运行状态;节拍;产量 是3 焊…

Unity UI框架总结

前言 目前国内手游的开发过程中,大部分业务玩法都是围绕着UI进行的。一个玩法业务不管是大型还是小型,UI上能占用40%-60%的工作量,不过当然也与玩法类型也有关系,玩法越偏3D,UI占有率越低,玩法越偏2D,UI占有率就越高,甚至能达到100%。博主作为一个3年多工作经验的U3D小…

战神电话app版本过低怎么办更新最新版本

您的App版本过低,已无法使用,请升级App,您的App版本过低,已经停止提供烧录等功能,并即将停用全部功能,请记录设备密码并及时升级App 战神电话app最新版本,战神电话app版本过低怎么办, 怎么更新到最新版本,版本过低有什么app可以代替,不能继续使用app的用户,可以联系升…

Language-only Efficient Training of Zero-shot Composed Image Retrieval

目录概LinCIR代码Gu G., Chun S., Kim W., Kang Y. and Yun S. Language-only efficient training of zero-shot composed image retrieval. CVPR, 2024.概 本文提出了一种仅在文本上训练的 Zero-Shot Composed Image Retrieval (ZS-CIR) 方法. LinCIR上图展示了一种最为常见的…

vue中接收接口数据控制svg图转动

前段时间做了svg图放到vue项目中项目,实时展示监控堆垛机、线体、告警等实时信息,还有暖通、废气、水处理、进料等系统的实时数据,直接展示在svg图上,并且部分系统设备能下发设备参数或者开关控制设备。在之前已经讲过《vue集成svg大图拖拽无限放大缩小》、《vue若依集成C#…

DeepSeek-R1 1.5b、7b、8b、14b、32b、70b、671b 都是什么鬼?

大家好,我是R哥。 你是不是被 DeepSeek-R1 1.5b、7b、8b、14b、32b、70b、671b 这些概念绕晕了? 如图所示:DeepSeek-R1 模型有好几种规格,比如 1.5b、7b、8b、14b、32b、70b、671b,后面的数字代表模型的参数量,而 b 则是指 “billion” 的意思,也就是十亿,表示这个模型…

北京智和信通:全方位智能 OLT、ONU 设备监控运维方案

北京智和信通OLT、ONU监控运维方案自动发现网络中不同品牌、型号的OLT设备,统一纳管,集中监控,动态呈现OLT、ONU设备的运行态势,通过对OLT、ONU设备的有效监控和管理,保障OLT、ONU设备的高效运行,及时发现并解决潜在问题,保障网络稳定。 随着网络技术的不断迭代与…