单层决策树分类函数 Parameters: dataMatrix - 数据矩阵 dimen - 第dimen列,也就是第几个特征 threshVal - 阈值 threshIneq - 标志 Returns: retArray - 分类结果
(dataMatrix,dimen,threshVal,threshIneq)
| 53 | plt.show() |
| 54 | |
| 55 | def stumpClassify(dataMatrix,dimen,threshVal,threshIneq): |
| 56 | """ |
| 57 | 单层决策树分类函数 |
| 58 | Parameters: |
| 59 | dataMatrix - 数据矩阵 |
| 60 | dimen - 第dimen列,也就是第几个特征 |
| 61 | threshVal - 阈值 |
| 62 | threshIneq - 标志 |
| 63 | Returns: |
| 64 | retArray - 分类结果 |
| 65 | """ |
| 66 | retArray = np.ones((np.shape(dataMatrix)[0],1)) #初始化retArray为1 |
| 67 | if threshIneq == 'lt': |
| 68 | retArray[dataMatrix[:,dimen] <= threshVal] = -1.0 #如果小于阈值,则赋值为-1 |
| 69 | else: |
| 70 | retArray[dataMatrix[:,dimen] > threshVal] = -1.0 #如果大于阈值,则赋值为-1 |
| 71 | return retArray |
| 72 | |
| 73 | |
| 74 | def buildStump(dataArr,classLabels,D): |
no outgoing calls
no test coverage detected