{"id":229685,"date":"2020-12-16T08:23:59","date_gmt":"2020-12-16T00:23:59","guid":{"rendered":"http:\/\/4563.org\/?p=229685"},"modified":"2020-12-16T08:23:59","modified_gmt":"2020-12-16T00:23:59","slug":"%e4%bd%bf%e7%94%a8%e6%9c%80%e7%bb%8f%e5%85%b8%e7%9a%84%e6%b3%b0%e5%9d%a6%e5%b0%bc%e5%85%8b%e6%95%b0%e6%8d%ae%e9%9b%86%e5%a6%82%e4%bd%95%e5%bf%ab%e9%80%9f%e6%b8%85%e6%b4%97%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=229685","title":{"rendered":"\u4f7f\u7528\u6700\u7ecf\u5178\u7684\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u96c6\u5982\u4f55\u5feb\u901f\u6e05\u6d17\u6570\u636e?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4f7f\u7528\u6700\u7ecf\u5178\u7684\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u96c6\u5982\u4f55\u5feb\u901f\u6e05\u6d17\u6570\u636e?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fanqieipnet <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u4f7f\u7528\u6700\u7ecf\u5178\u7684\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u96c6\u5982\u4f55\u5feb\u901f\u6e05\u6d17\u6570\u636e?\u4eca\u5929\u756a\u8304\u52a0\u901f\u5c31\u6765\u7ed9\u5927\u5bb6\u6f14\u793a\u4e00\u4e0b\u3002<\/p>\n<p>\u3000\u3000\u9996\u5148\u5bfc\u5165\u5305\uff1a<\/p>\n<p>\u3000\u3000 import numpy as np import pandas as pd import seaborn as snsimport matplotlib.pyplot as plt<\/p>\n<p>\u3000\u3000\u5bfc\u5165\u6570\u636e<\/p>\n<p>\u3000\u3000 df = pd.read_csv(&#8216;.\/kaggle-data\/titanic\/train.csv&#8217;)<\/p>\n<p>\u3000\u3000\u627e\u5230\u6240\u6709\u5217\u7684 None \u503c<\/p>\n<p>\u3000\u3000 df.isnull().sum()<\/p>\n<p>\u3000\u3000 PassengerId 0Survived 0Pclass 0Name 0Sex 0Age 177SibSp 0Parch 0Ticket 0Fare 0Cabin 687Embarked 2dtype: int64<\/p>\n<p>\u3000\u3000 Age \u5217\u8f83\u591a\uff0c\u4f7f\u7528\u5e73\u5747\u503c\u586b\u5145<\/p>\n<p>\u3000\u3000 df[&#8216;Age&#8217;] = df[&#8216;Age&#8217;].transform(lambda val: val.fillna(val.mean()))<\/p>\n<p>\u3000\u3000 sex \u5217\u6620\u5c04 male \u4e3a 0\uff0cfemale \u4e3a 1<\/p>\n<p>\u3000\u3000 df[&#8216;Sex&#8217;] = df[&#8216;Sex&#8217;].map({&#8216;male&#8217;: 0, &#8216;female&#8217;: 1})df = df.fillna(0)<\/p>\n<p>\u3000\u3000\u63a5\u4e0b\u6765\u5c31\u662f\u6700\u5173\u952e\u7684\uff0c\u4f7f\u7528 corr \u65b9\u6cd5\uff0c\u627e\u51fa\u5404\u4e2a\u53d8\u91cf\u95f4\u7684\u76f8\u5173\u7cfb\u6570\uff0c\u5e76\u4f7f\u7528 heatmap \u7ed8\u5236\u76f8\u5173\u6027\uff1a<\/p>\n<p>\u3000\u3000 plt.figure(figsize=(8,6), dpi=150)sns.heatmap(data=df.corr(), cmap=&#8217;coolwarm&#8217;, annot=True)<\/p>\n<p>\u3000\u3000\u627e\u51fa\u4e0e survived \u5217\u6700\u76f8\u5173\u7684\u51e0\u4e2a\u7279\u5f81\uff1a<\/p>\n<p>\u3000\u3000 np.abs(df.corr()[&#8216;Survived&#8217;]).sort_values().tail(6)<\/p>\n<p>\u3000\u3000\u53bb\u6389\u76f8\u5173\u4e0d\u5927\u7684\u5217\uff0c\u5f97\u5230\u5982\u4e0b\u5f71\u54cd survived \u6700\u5927\u7684\u7279\u5f81 DataFrame\uff1a<\/p>\n<p>\u3000\u3000 X = df.drop([&#8216;Survived&#8217;, &#8216;Cabin&#8217;, &#8216;Name&#8217;, &#8216;Embarked&#8217;, &#8216;Ticket&#8217;], axis=1)      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4711932\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sadfQED2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u73b0\u5728\u7684\u63a8\u5e7f\u8fde\u80cc\u666f\u90fd\u4e0d\u4ea4\u4ee3\u4e0b\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4711933\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GeruzoniAnsasu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8f6f\u6587\u5199\u5f97\u8fde\u8981\u63a8\u5e7f\u7684\u81ea\u5bb6\u4e1c\u897f\u90fd\u5fd8\u4e86\u653e\u8fdb\u53bb\u6211\u8fd8\u662f\u7b2c\u4e00\u6b21\u89c1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4711934\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c31\u662f\u554a\uff0c\u7f51\u5740\u5462\uff1f\u4f01\u4e1a\u540d\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u6700\u7ecf\u5178\u7684\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u96c6\u5982\u4f55\u5feb\u901f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/229685"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229685"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/229685\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229685"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}