《机器学习(周志华)》习题11.1 参考答案

本文介绍了编程实现机器学习中的Relief算法,并对其在西瓜3.0数据集上的应用效果进行了分析。尽管算法在某些方面存在假设和局限,如依赖最近邻且可能不适于高维数据,但作为编程练习有助于深入理解算法原理。然而,作者在实践中对此算法并不倾向于使用。

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

试编程实现Relief算法,并考察其在西瓜3.0上的结果。

# coding: utf-8
import numpy as np 

input_path = "西瓜数据集3.csv"
file = open(input_path.decode('utf-8'))
filedata = [line.strip('\n').split(',') for line in file]
filedata = [[float(i) if '.' in i.decode('utf-8') else i for i in row ] for row in filedata] # change decimal from string to float 
filedata = filedata[1:]
X = [row[1:-1] for row in filedata] # attributes
Y = [row[-1] for row in filedata] # class label 
weight = np.zeros(len(X[0]))

# Normalise
for row in X:
	row[-2] = (row[-2]-0.243) / (0.774-0.243)
	row[-1] = (row[-1]-0.042) / (0.46-0.042)

def cal_dis(a, b):
	ret = 0
	for i in range(len(a)):
		ai = a[i]
		bi = b[i]
		if type(a[i]) == float:
			ret += np.abs(ai-bi)
		else:
			ret += 0 if ai==bi else 1
	return ret 


def fin
### 关于《机器学习周志华西瓜书课后习题解析 #### 不同节的习题特点与解决方法 对于不同节中的具体题目,解决方案各有侧重。例如,在第九中提到的内容涉及较为复杂的模型评估和技术应用[^1]。 #### 构建不剪枝决策树的具体案例分析 当处理特定的数据集如西瓜数据3.0α时,构建不剪枝决策树的过程不同于简单的决策桩。这里需要考虑更多的节点分裂标准以及如何全面地利用特征属性进行划分,而不是仅仅依赖单一条件做出判断[^2]。 #### 计算假设空间大小的方法探讨 针对西瓜分类问题中的假设空间计算,如果采用最多包含k个合取式的析合范式,则可以通过组合数学的方式估计可能存在的假设数量。这涉及到对给定条件下所有潜在模式的理解和量化[^3]。 #### 版本空间的概念及其求解过程说明 版本空间是指既能够解释已有观察又尽可能泛化到未见实例的一组假设集合。通过移除那些无法匹配已知正例或反而能解释负例的候选方案,可以逐步缩小这一范围直至找到最优解[^4]。 ```python def calculate_hypothesis_space_size(attributes, values_per_attribute): """ Calculate the size of hypothesis space given attributes and their possible value counts. :param attributes: List of attribute names :param values_per_attribute: Dictionary mapping each attribute to its number of distinct values :return: Total number of hypotheses in the space """ total_combinations = 1 for attr in attributes: if attr in values_per_attribute: total_combinations *= (values_per_attribute[attr] + 1) # Include wildcard '*' return total_combinations - 1 # Exclude completely wild card case '* * ...' # Example usage based on provided information from reference [3] attributes = ["色泽", "根蒂", "敲声"] value_counts = {"色泽": 2, "根蒂": 2, "敲声": 2} print(f"The estimated number of possible hypotheses is {calculate_hypothesis_space_size(attributes, value_counts)}") ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值