kNN.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:statistical-learning-methods-note 作者: ysh329 项目源码 文件源码
def plotScatter(self, xList, yList, saveFigPath):
        '''
        ?????? xList ???? yList ????????????
        ?????? saveFigPath ????
        :param xList: ????
        :param yList: ????
        :param saveFigPath: ????????
        :return:
        '''
        # ????????????
        # ??????????? 2
        # ???????? 2 ?????
        if len(xList[0]) >= 2:
            x1List = map(lambda x: x[0], xList)
            x2List = map(lambda x: x[1], xList)
        else:
            # 1 ? 2 ???????? 2 ?
            x1List = x2List = map(lambda x: x[0], xList)
        # ????
        scatterFig= plt.figure(saveFigPath)
        # ?????????
        colorDict = {-1: 'm', 1: 'r', 2: 'b', 3: 'pink', 4: 'orange'}
        # ?????
        map(lambda idx: \
                plt.scatter(x1List[idx], \
                            x2List[idx], \
                            marker='o', \
                            color=colorDict[yList[idx]], \
                            label=yList[idx]), \
            xrange(len(x1List)))
        # ?????????
        # ySet = set(yList)
        # map(lambda y: \
        #         plt.legend(str(y), \
        #                    loc='best'), \
        #     ySet)

        # ??????????????
        plt.title(saveFigPath)
        plt.xlabel(r'$x^1$')
        plt.ylabel(r'$x^2$')
        plt.grid(True)
        plt.savefig(saveFigPath)
        plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号