\n59\u5217\u6570\u636e\u4e2d\uff0c \u7b2c\u4e00\u5217\u4e3a\u89d2\u8272ID\uff0c\u6700\u540e\u4e00\u5217\u4e3a\u5206\u7c7b\u7ed3\u679c\uff0c\u5373label(0\u30011\u4e24\u79cd)\uff0c\u4e2d\u95f4\u768457\u5217\u4e3a\u89d2\u8272\u5bf9\u5e94\u768457\u79cd\u5c5e\u6027\u503c\uff1b<\/p>\n<\/li>\n<\/ul>\n
\u4e8c\u3001\u601d\u8def\u5206\u6790<\/h4>\n2.1 \u601d\u8def\u5206\u6790<\/h5>\n
\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u7ed3\u5408\u8bfe\u4e0a\u6240\u5b66\u5185\u5bb9\uff0c\u51b3\u5b9a\u91c7\u7528Logistic\u56de\u5f52\u7b97\u6cd5\u3002<\/p>\n
\u4e0e\u7ebf\u6027\u56de\u5f52\u7528\u4e8e\u9884\u6d4b\u4e0d\u540c\uff0cLogistic\u56de\u5f52\u5219\u5e38\u7528\u4e8e\u5206\u7c7b(\u901a\u5e38\u662f\u4e8c\u5206\u7c7b\u95ee\u9898)\u3002Logistic\u56de\u5f52\u5b9e\u8d28\u4e0a\u5c31\u662f\u5728\u666e\u901a\u7684\u7ebf\u6027\u56de\u5f52\u540e\u9762\u52a0\u4e0a\u4e86\u4e00\u4e2asigmoid\u51fd\u6570\uff0c\u628a\u7ebf\u6027\u56de\u5f52\u9884\u6d4b\u5230\u7684\u6570\u503c\u538b\u7f29\u6210\u4e3a\u4e00\u4e2a\u6982\u7387\uff0c\u8fdb\u800c\u5b9e\u73b0\u4e8c\u5206\u7c7b\uff08\u5173\u4e8e\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff0c\u53ef\u53c2\u8003\u4e0a\u4e00\u6b21\u4f5c\u4e1a\uff09\u3002<\/p>\n
\u5728\u635f\u5931\u51fd\u6570\u65b9\u9762\uff0cLogistic\u56de\u5f52\u5e76\u6ca1\u6709\u4f7f\u7528\u4f20\u7edf\u7684\u6b27\u5f0f\u8ddd\u79bb\u6765\u5ea6\u91cf\u8bef\u5dee\uff0c\u800c\u4f7f\u7528\u4e86\u4ea4\u53c9\u71b5(\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u7684\u76f8\u4f3c\u7a0b\u5ea6)\u3002
\u3000\u3000<\/p>\n
2.2 \u6570\u636e\u9884\u5904\u7406<\/h5>\n
\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6570\u636e\u7684\u9884\u5904\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u73af\uff0c\u80fd\u76f4\u63a5\u5f71\u54cd\u5230\u6a21\u578b\u6548\u679c\u7684\u597d\u574f\u3002\u672c\u6b21\u4f5c\u4e1a\u7684\u6570\u636e\u76f8\u5bf9\u7b80\u5355\u7eaf\u51c0\uff0c\u5728\u6570\u636e\u9884\u5904\u7406\u65b9\u9762\u5e76\u4e0d\u9700\u8981\u82b1\u592a\u591a\u7cbe\u529b\u3002<\/p>\n
\u9996\u5148\u662f\u7a7a\u503c\u5904\u7406(\u5c3d\u7ba1\u6ca1\u770b\u5230\u7a7a\u503c\uff0c\u4f46\u4e3a\u4e86\u4ee5\u9632\u4e07\u4e00\uff0c\u8fd8\u662f\u505a\u4e00\u4e0b)\uff0c\u6240\u6709\u7a7a\u503c\u75280\u586b\u5145(\u4e5f\u53ef\u4ee5\u7528\u5e73\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u7b49\uff0c\u89c6\u5177\u4f53\u60c5\u51b5\u800c\u5b9a)\u3002<\/p>\n
\u63a5\u7740\u5c31\u662f\u628a\u6570\u636e\u8303\u56f4\u5c3d\u91cfscale\u5230\u540c\u4e00\u4e2a\u6570\u91cf\u7ea7\u4e0a\uff0c\u89c2\u5bdf\u6570\u636e\u540e\u53d1\u73b0\uff0c\u591a\u6570\u6570\u636e\u503c\u4e3a0\uff0c\u975e0\u503c\u4e5f\u90fd\u57281\u9644\u8fd1\uff0c\u53ea\u6709\u5012\u6570\u7b2c\u4e8c\u5217\u548c\u5012\u6570\u7b2c\u4e09\u5217\u6570\u636e\u503c\u8f83\u5927\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e24\u5217\u5206\u522b\u9664\u4e0a\u6bcf\u5217\u7684\u5e73\u5747\u503c\uff0c\u628a\u6570\u503c\u8303\u56f4\u62c9\u52301\u9644\u8fd1\u3002<\/p>\n
\u7531\u4e8e\u5e76\u6ca1\u6709\u7ed9\u51fa\u8fd957\u4e2a\u5c5e\u6027\u5177\u4f53\u662f\u4ec0\u4e48\u5c5e\u6027\uff0c\u56e0\u6b64\u65e0\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u6316\u6398\u5e94\u7528\u3002<\/p>\n
\u4e0a\u8ff0\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u5c06\u8868\u683c\u7684\u7b2c2\u5217\u81f358\u5217\u53d6\u51fa\u4e3ax(shape\u4e3a4000X57)\uff0c\u5c06\u6700\u540e\u4e00\u5217\u53d6\u51fa\u505alabel y(shape\u4e3a4000X1)\u3002\u8fdb\u4e00\u6b65\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u9a8c\u8bc1\u96c6\uff0c\u5206\u522b\u53d6x\u3001y\u4e2d\u524d3500\u4e2a\u6837\u672c\u4e3a\u8bad\u7ec3\u96c6x_test(shape\u4e3a3500X57)\uff0cy_test(shape\u4e3a3500X1)\uff0c\u540e500\u4e2a\u6837\u672c\u4e3a\u9a8c\u8bc1\u96c6x_val(shape\u4e3a500X57)\uff0cy_val(shape\u4e3a500X1)\u3002<\/p>\n
\u6570\u636e\u9884\u5904\u7406\u5230\u6b64\u7ed3\u675f\u3002<\/p>\n
#\u6570\u636e\u7684\u9884\u5904\u7406<\/span>\n df=<\/span>pd.<\/span>read_csv(<\/span>'spam_train.csv'<\/span>)<\/span>#\u8bfb\u6587\u4ef6<\/span>\n df=<\/span>df.<\/span>fillna(<\/span>0<\/span>)<\/span>#\u7a7a\u503c\u75280\u586b\u5145<\/span>\n array=<\/span>np.<\/span>array(<\/span>df)<\/span>#\u8f6c\u5316\u4e3a\u5bf9\u8c61\uff084000\uff0c49\uff09<\/span>\n x=<\/span>array[<\/span>:<\/span>,<\/span>1<\/span>:<\/span>-<\/span>1<\/span>]<\/span>#\u629b\u5f03\u7b2c\u4e00\u5217\u548c\u6700\u540e\u4e00\u5217shape(4000,47)<\/span>\n y=<\/span>array[<\/span>:<\/span>,<\/span>-<\/span>1<\/span>]<\/span>#\u6700\u540e\u4e00\u5217label<\/span>\n #\u5c06\u5012\u6570\u7b2c\u4e8c\u5217\u548c\u7b2c\u4e09\u5217\u9664\u4ee5\u5e73\u5747\u503c<\/span>\n x[<\/span>:<\/span>,<\/span>-<\/span>1<\/span>]<\/span>=<\/span>x[<\/span>:<\/span>,<\/span>-<\/span>1<\/span>]<\/span>\/<\/span>np.<\/span>mean(<\/span>x[<\/span>:<\/span>,<\/span>-<\/span>1<\/span>]<\/span>)<\/span>\n x[<\/span>:<\/span>,<\/span> -<\/span>2<\/span>]<\/span> =<\/span> x[<\/span>:<\/span>,<\/span> -<\/span>2<\/span>]<\/span> \/<\/span> np.<\/span>mean(<\/span>x[<\/span>:<\/span>,<\/span> -<\/span>2<\/span>]<\/span>)<\/span>\n\n #\u5212\u5206\u6d4b\u8bd5\u96c6\u548c\u9a8c\u8bc1\u96c6<\/span>\n x_train=<\/span>x[<\/span>0<\/span>:<\/span>3500<\/span>,<\/span>:<\/span>]<\/span>\n y_train =<\/span> y[<\/span>0<\/span>:<\/span>3500<\/span>]<\/span>\n x_val=<\/span>x[<\/span>3500<\/span>:<\/span>4001<\/span>,<\/span>:<\/span>]<\/span>\n y_val=<\/span>y[<\/span>3500<\/span>:<\/span>4001<\/span>]<\/span>\n<\/code><\/pre>\n2.3 \u6a21\u578b\u5efa\u7acb<\/h4>\n2.3.1 \u7ebf\u6027\u56de\u5f52<\/h5>\n
\u5148\u5bf9\u6570\u636e\u505a\u7ebf\u6027\u56de\u5f52\uff0c\u5f97\u51fa\u6bcf\u4e2a\u6837\u672c\u5bf9\u5e94\u7684\u56de\u5f52\u503c\u3002\u4e0b\u5f0f\u4e3a\u5bf9\u7b2cn\u4e2a\u6837\u672c x n x^{n} <\/span><\/span>x<\/span><\/span>n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u7684\u56de\u5f52\uff0c\u56de\u5f52\u7ed3\u679c\u4e3a y n y^{n} <\/span><\/span>y<\/span><\/span>n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002<\/p>\n y n = \u2211 i = 1 57 w i x i n + b \\mathrm{y}^{n}=\\sum_{i=1}^{57} w_{i} x_{i}^{n}+b <\/span><\/span>y<\/span><\/span><\/span>n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>=<\/span><\/span><\/span><\/span><\/span>i<\/span>=<\/span>1<\/span><\/span><\/span><\/span><\/span>\u2211<\/span><\/span><\/span><\/span>5<\/span>7<\/span><\/span><\/span><\/span><\/span>\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>w<\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>x<\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>n<\/span><\/span><\/span><\/span><\/span>\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>+<\/span><\/span><\/span><\/span>b<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n2.3.2 sigmoid\u51fd\u6570\u538b\u7f29\u56de\u5f52\u503c<\/h5>\n
\u4e4b\u540e\u5c06\u56de\u5f52\u7ed3\u679c\u9001\u8fdbsigmoid\u51fd\u6570\uff0c\u5f97\u5230\u6982\u7387\u503c\u3002
p n = 1 1 + e \u2212 y n p^{n}=\\frac{1}{1+e^{-y^{n}}} <\/span>