{"id":426,"date":"2023-04-11T01:55:59","date_gmt":"2023-04-11T01:55:59","guid":{"rendered":"https:\/\/yunshangtulv.com.cn\/?p=426"},"modified":"2023-04-11T01:55:59","modified_gmt":"2023-04-11T01:55:59","slug":"r%e8%af%ad%e8%a8%80%e5%9f%ba%e7%a1%80%e7%bb%9f%e8%ae%a1%e7%a4%ba%e4%be%8b%e5%a4%9a%e9%87%8d%e7%ba%bf%e6%80%a7%e5%9b%9e%e5%bd%92","status":"publish","type":"post","link":"https:\/\/yunshangtulv.com.cn\/?p=426","title":{"rendered":"R\u8bed\u8a00\u57fa\u7840\u7edf\u8ba1\u793a\u4f8b:\u591a\u91cd\u7ebf\u6027\u56de\u5f52"},"content":{"rendered":"<p>\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u662f\u4e00\u79cd\u7edf\u8ba1\u65b9\u6cd5\uff0c\u7528\u4e8e\u63a2\u7a76\u591a\u4e2a\u81ea\u53d8\u91cf\u4e0e\u56e0\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5728R\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>lm()<\/code>\u51fd\u6570\u8fdb\u884c\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u7ec6\u7684\u89e3\u91ca\u548c\u5e94\u7528\u5b9e\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<h3>\u793a\u4f8b\u6570\u636e\u96c6\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528R\u4e2d\u5185\u7f6e\u7684<code>mtcars<\/code>\u6570\u636e\u96c6\uff0c\u8be5\u6570\u636e\u96c6\u5305\u542b32\u8f86\u4e0d\u540c\u578b\u53f7\u6c7d\u8f66\u7684\u4fe1\u606f\u3002\u6211\u4eec\u5c06\u63a2\u8ba8\u9a6c\u529b\uff08hp\uff09\u3001\u91cd\u91cf\uff08wt\uff09\u548c\u6c14\u7f38\u6570\u91cf\uff08cyl\uff09\u4e0e\u6bcf\u52a0\u4ed1\u884c\u9a76\u82f1\u91cc\u6570\uff08mpg\uff09\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<ol start=\"2\">\n<li>\n<h3>\u6570\u636e\u9884\u89c8\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u52a0\u8f7d\u5e76\u67e5\u770b\u6570\u636e\u96c6\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u67e5\u770bmtcars\u6570\u636e\u96c6<\/span><br \/>\nhead<span class=\"hljs-punctuation\">(<\/span>mtcars<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"3\">\n<li>\n<h3>\u6784\u5efa\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u4f7f\u7528<code>lm()<\/code>\u51fd\u6570\u6784\u5efa\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u503c\u7ed9<code>model<\/code>\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u6784\u5efa\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u6a21\u578b<\/span><br \/>\nmodel <span class=\"hljs-operator\">&lt;-<\/span> lm<span class=\"hljs-punctuation\">(<\/span>mpg <span class=\"hljs-operator\">~<\/span> hp <span class=\"hljs-operator\">+<\/span> wt <span class=\"hljs-operator\">+<\/span> cyl<span class=\"hljs-punctuation\">,<\/span> data <span class=\"hljs-operator\">=<\/span> mtcars<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"4\">\n<li>\n<h3>\u67e5\u770b\u6a21\u578b\u6458\u8981\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u4f7f\u7528<code>summary()<\/code>\u51fd\u6570\u67e5\u770b\u6a21\u578b\u6458\u8981\uff0c\u5305\u62ec\u7cfb\u6570\u3001R\u5e73\u65b9\u3001\u8c03\u6574R\u5e73\u65b9\u7b49\u4fe1\u606f\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u67e5\u770b\u6a21\u578b\u6458\u8981<\/span><br \/>\nsummary<span class=\"hljs-punctuation\">(<\/span>model<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"5\">\n<li>\n<h3>\u8bc4\u4f30\u6a21\u578b\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u4ece\u6a21\u578b\u6458\u8981\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a\u81ea\u53d8\u91cf\u7684\u7cfb\u6570\u3001\u6807\u51c6\u8bef\u5dee\u3001t\u503c\u548cp\u503c\u3002p\u503c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u81ea\u53d8\u91cf\u5bf9\u56e0\u53d8\u91cf\u7684\u5f71\u54cd\u662f\u5426\u663e\u8457\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u67e5\u770bR\u5e73\u65b9\u548c\u8c03\u6574R\u5e73\u65b9\uff0c\u4ee5\u8bc4\u4f30\u6a21\u578b\u7684\u62df\u5408\u7a0b\u5ea6\u3002<\/p>\n<ol start=\"6\">\n<li>\n<h3>\u9884\u6d4b\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u4f7f\u7528<code>predict()<\/code>\u51fd\u6570\u8fdb\u884c\u9884\u6d4b\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b<\/span><br \/>\npredictions <span class=\"hljs-operator\">&lt;-<\/span> predict<span class=\"hljs-punctuation\">(<\/span>model<span class=\"hljs-punctuation\">,<\/span> newdata <span class=\"hljs-operator\">=<\/span> mtcars<span class=\"hljs-punctuation\">)<\/span><\/p>\n<p><span class=\"hljs-comment\"># \u67e5\u770b\u9884\u6d4b\u503c<\/span><br \/>\nhead<span class=\"hljs-punctuation\">(<\/span>predictions<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ol start=\"7\">\n<li>\n<h3>\u6a21\u578b\u8bca\u65ad\uff1a<\/h3>\n<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u6b8b\u5dee\u56fe\u3001QQ\u56fe\u7b49\uff0c\u68c0\u67e5\u6a21\u578b\u662f\u5426\u6ee1\u8db3\u7ebf\u6027\u56de\u5f52\u7684\u5047\u8bbe\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plot()<\/code>\u51fd\u6570\u7ed8\u5236\u6a21\u578b\u7684\u6b8b\u5dee\u56fe\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u7ed8\u5236\u6a21\u578b\u7684\u6b8b\u5dee\u56fe<\/span><br \/>\nplot<span class=\"hljs-punctuation\">(<\/span>model<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u4f60\u5e94\u8be5\u5bf9\u5982\u4f55\u5728R\u8bed\u8a00\u4e2d\u8fdb\u884c\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u5206\u6790\u6709\u4e86\u4e00\u4e2a\u57fa\u672c\u4e86\u89e3\u3002\u4e0d\u8fc7\uff0c\u8981\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u548c\u9700\u6c42\u8c03\u6574\u6a21\u578b\uff0c\u53ef\u80fd\u8fd8\u9700\u8981\u6df1\u5165\u5b66\u4e60\u548c\u5b9e\u8df5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u662f\u4e00\u79cd\u7edf\u8ba1\u65b9\u6cd5\uff0c\u7528\u4e8e\u63a2\u7a76\u591a\u4e2a\u81ea\u53d8\u91cf\u4e0e\u56e0\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5728R\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528lm()\u51fd\u6570\u8fdb\u884c\u591a\u91cd\u7ebf\u6027 [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-426","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426"}],"version-history":[{"count":0,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/426\/revisions"}],"wp:attachment":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}