《机器学习实战》——2.k-近邻算法(KNN )函数总结

本文是对《机器学习实战》中KNN算法实现过程涉及的Python函数进行的总结,包括str.strip()、ndarray.shape、axis、numpy.argsort()、numpy.tile()、range()、dict.get()、dict.items()、sorted()、operator.itemgetter()以及IO的read(), readline(), readlines()等,详述了它们的功能和用法。" 133227609,20037308,FastJSP框架:打造高效后端开发,"['Java', 'Web开发', '框架', 'JSP', '后端框架']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在《机器学习实战》第二章中,使用了KNN算法改进约会网站配对效果。本文为在实现过程中使用到的一些函数 基本用法的总结。


1. str.strip()方法

语法:str.strip([chars])
功能:返回移除字符串头尾指定字符后生成的新字符串
参数: chars 需要移除字符串头尾的指定字符(默认是空格)
官方文档描述: Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped

示例

>>>comment_string = '#....... Section 3.2.1 Issue #32 .......'
>>>comment_string.strip('.#! ')
'Section 3.2.1 Issue #32'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值