{"id":78562,"date":"2026-02-27T22:29:04","date_gmt":"2026-02-27T14:29:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78562.html"},"modified":"2026-02-27T22:29:04","modified_gmt":"2026-02-27T14:29:04","slug":"%e3%80%90lr%e9%80%bb%e8%be%91%e5%9b%9e%e5%bd%92%e3%80%91%e5%8e%9f%e7%90%86%e4%bb%a5%e5%8f%8atensorflow%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78562.html","title":{"rendered":"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0"},"content":{"rendered":"<p>LR \u5c06\u6240\u6709\u8f93\u5165\u7279\u5f81\u8fdb\u884c\u7ebf\u6027\u7ec4\u5408&#xff0c;\u901a\u8fc7 Sigmoid \u51fd\u6570\u5c06\u7ed3\u679c\u538b\u7f29\u5230 (0, 1)\u00a0\u533a\u95f4&#xff0c;\u8f93\u51fa\u6982\u7387<\/p>\n<p><img decoding=\"async\" alt=\"$\\\\hat{y} &#061; \\\\sigma\\\\left(w_0 &#043; \\\\sum_{i&#061;1}^n w_i x_i\\\\right)$\" class=\"mathcode\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260227142902-69a1aa2ef289b.png\" \/><\/p>\n<p><img decoding=\"async\" alt=\"$\\\\sigma(z) &#061; \\\\frac{1}{1 &#043; e^{-z}}$\" class=\"mathcode\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260227142903-69a1aa2f0e53c.png\" \/><\/p>\n<p>LR \u4ec5\u505a\u4e86\u4e00\u9636\u7279\u5f81\u7684\u7ebf\u6027\u52a0\u6743&#xff0c;\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684<\/p>\n<p>import numpy as np<br \/>\nimport tensorflow as tf<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.preprocessing import StandardScaler<\/p>\n<p># 1. \u6a21\u62df\u751f\u6210\u63a8\u8350\u573a\u666f\u7684\u70b9\u51fb\u6570\u636e<br \/>\ndef generate_mock_data(n_samples&#061;5000, n_features&#061;20):<br \/>\n    # \u968f\u673a\u751f\u6210\u7279\u5f81\u77e9\u9635 X<br \/>\n    X &#061; np.random.randn(n_samples, n_features)<br \/>\n    # \u6a21\u62df\u4e00\u4e2a\u771f\u5b9e\u7684\u7ebf\u6027\u5173\u7cfb\u52a0\u4e0a\u4e00\u70b9\u968f\u673a\u6270\u52a8<br \/>\n    # \u5047\u8bbe\u771f\u5b9e\u7684\u6743\u91cd\u662f\u56fa\u5b9a\u7684&#xff0c;y &#061; sigmoid(X * weights &#043; bias)<br \/>\n    true_weights &#061; np.random.randn(n_features, 1)<br \/>\n    logits &#061; np.dot(X, true_weights) &#043; 0.5<br \/>\n    # \u5c06\u8fde\u7eed\u503c\u8f6c\u4e3a 0\/1 \u6807\u7b7e&#xff08;\u70b9\u51fb\u6216\u672a\u70b9\u51fb&#xff09;<br \/>\n    y &#061; (1 \/ (1 &#043; np.exp(-logits)) &gt; 0.5).astype(int)<br \/>\n    return X, y<\/p>\n<p># &#8212; \u51c6\u5907\u6570\u636e &#8212;<br \/>\nX, y &#061; generate_mock_data()<br \/>\n# \u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6&#xff08;80% \u8bad\u7ec3&#xff0c;20% \u6d4b\u8bd5&#xff09;<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.2)<\/p>\n<p># \u7279\u5f81\u6807\u51c6\u5316&#xff08;\u5de5\u7a0b\u5fc5\u5907&#xff1a;\u8ba9\u68af\u5ea6\u4e0b\u964d\u66f4\u5e73\u7a33&#xff09;<br \/>\nscaler &#061; StandardScaler()<br \/>\nX_train &#061; scaler.fit_transform(X_train)<br \/>\nX_test &#061; scaler.transform(X_test)<\/p>\n<p># 2. \u6784\u5efa\u6a21\u578b (The &#034;Body&#034;)<br \/>\nmodel &#061; tf.keras.Sequential([<br \/>\n    # input_shape \u5bf9\u5e94\u7279\u5f81\u7ef4\u5ea6<br \/>\n    tf.keras.layers.Dense(units&#061;1, activation&#061;&#039;sigmoid&#039;, input_shape&#061;(20,))<br \/>\n])<br \/>\n#unit\u4e3a\u8f93\u51fa\u7684\u8282\u70b9\u6570&#xff0c;w\u7684\u5f62\u72b6\u4e3a&#xff08;20&#xff0c;1&#xff09;<\/p>\n<p># 3. \u7f16\u8bd1\u6a21\u578b (The &#034;Soul&#034;)<br \/>\nmodel.compile(<br \/>\n    optimizer&#061;tf.keras.optimizers.Adam(learning_rate&#061;0.01),<br \/>\n    loss&#061;&#039;binary_crossentropy&#039;,<br \/>\n    metrics&#061;[&#039;accuracy&#039;, tf.keras.metrics.AUC(name&#061;&#039;auc&#039;)]<br \/>\n)<\/p>\n<p># 4. \u542f\u52a8\u8bad\u7ec3 (The &#034;Action&#034;)<br \/>\n# fit \u51fd\u6570\u4f1a\u8ba9\u6570\u636e\u5728\u8ba1\u7b97\u56fe\u4e2d\u5faa\u73af\u8fd0\u884c<br \/>\nprint(&#034;&#8212; \u5f00\u59cb\u8bad\u7ec3 &#8212;&#034;)<br \/>\nhistory &#061; model.fit(<br \/>\n    X_train, y_train,<br \/>\n    epochs&#061;20,           # \u6574\u4e2a\u6570\u636e\u96c6\u8dd1 20 \u904d<br \/>\n    batch_size&#061;32,       # \u6bcf\u6b21\u5582 32 \u6761\u6570\u636e\u8fdb\u884c\u68af\u5ea6\u66f4\u65b0<br \/>\n    validation_split&#061;0.1 # \u4ece\u8bad\u7ec3\u96c6\u91cc\u62bd 10% \u505a\u5b9e\u65f6\u76d1\u63a7<br \/>\n)<\/p>\n<p># 5. \u6d4b\u8bd5\u4e0e\u8bc4\u4f30 (The &#034;Audit&#034;)<br \/>\nprint(&#034;\\\\n&#8212; \u6d4b\u8bd5\u96c6\u8bc4\u4f30 &#8212;&#034;)<br \/>\nresults &#061; model.evaluate(X_test, y_test)<br \/>\nprint(f&#034;\u6d4b\u8bd5\u96c6\u51c6\u786e\u7387: {results[1]:.4f}, AUC: {results[2]:.4f}&#034;)<\/p>\n<p># 6. \u9884\u6d4b (The &#034;Prediction&#034;)<br \/>\n# \u6a21\u62df\u5bf9\u524d 5 \u4e2a\u65b0\u7528\u6237\u8fdb\u884c\u70b9\u51fb\u7387\u9884\u6d4b<br \/>\nsample_preds &#061; model.predict(X_test[:5])<br \/>\nprint(&#034;\\\\n\u524d5\u4e2a\u6837\u672c\u7684\u70b9\u51fb\u9884\u6d4b\u6982\u7387&#xff1a;\\\\n&#034;, sample_preds)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LR \u5c06\u6240\u6709\u8f93\u5165\u7279\u5f81\u8fdb\u884c\u7ebf\u6027\u7ec4\u5408&#xff0c;\u901a\u8fc7 Sigmoid \u51fd\u6570\u5c06\u7ed3\u679c\u538b\u7f29\u5230 (0, 1)\u00a0\u533a\u95f4&#xff0c;\u8f93\u51fa\u6982\u7387LR \u4ec5\u505a\u4e86\u4e00\u9636\u7279\u5f81\u7684\u7ebf\u6027\u52a0\u6743&#xff0c;\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684import numpy as np<br \/>\nimport tensorflow as tf<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.preprocessing import StandardScal<\/p>\n","protected":false},"author":2,"featured_media":78560,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3677,427,3407],"topic":[],"class_list":["post-78562","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-tensorflow","tag-427","tag-3407"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/78562.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"LR \u5c06\u6240\u6709\u8f93\u5165\u7279\u5f81\u8fdb\u884c\u7ebf\u6027\u7ec4\u5408&#xff0c;\u901a\u8fc7 Sigmoid \u51fd\u6570\u5c06\u7ed3\u679c\u538b\u7f29\u5230 (0, 1)\u00a0\u533a\u95f4&#xff0c;\u8f93\u51fa\u6982\u7387LR \u4ec5\u505a\u4e86\u4e00\u9636\u7279\u5f81\u7684\u7ebf\u6027\u52a0\u6743&#xff0c;\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684import numpy as np import tensorflow as tf from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScal\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78562.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-27T14:29:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260227142902-69a1aa2ef289b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78562.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78562.html\",\"name\":\"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-27T14:29:04+00:00\",\"dateModified\":\"2026-02-27T14:29:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78562.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78562.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78562.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/78562.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"LR \u5c06\u6240\u6709\u8f93\u5165\u7279\u5f81\u8fdb\u884c\u7ebf\u6027\u7ec4\u5408&#xff0c;\u901a\u8fc7 Sigmoid \u51fd\u6570\u5c06\u7ed3\u679c\u538b\u7f29\u5230 (0, 1)\u00a0\u533a\u95f4&#xff0c;\u8f93\u51fa\u6982\u7387LR \u4ec5\u505a\u4e86\u4e00\u9636\u7279\u5f81\u7684\u7ebf\u6027\u52a0\u6743&#xff0c;\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684import numpy as np import tensorflow as tf from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScal","og_url":"https:\/\/www.wsisp.com\/helps\/78562.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-27T14:29:04+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260227142902-69a1aa2ef289b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78562.html","url":"https:\/\/www.wsisp.com\/helps\/78562.html","name":"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-27T14:29:04+00:00","dateModified":"2026-02-27T14:29:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78562.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78562.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78562.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010LR\u903b\u8f91\u56de\u5f52\u3011\u539f\u7406\u4ee5\u53catensorflow\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=78562"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78562\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/78560"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78562"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}