{"id":1078856,"date":"2025-01-08T12:15:27","date_gmt":"2025-01-08T04:15:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1078856.html"},"modified":"2025-01-08T12:15:30","modified_gmt":"2025-01-08T04:15:30","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e6%a0%87%e5%87%86%e5%8c%96%e5%a4%84%e7%90%86-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1078856.html","title":{"rendered":"Python\u5982\u4f55\u505a\u6807\u51c6\u5316\u5904\u7406"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182201\/d3617bc5-ead8-42b7-bebb-0107d0808a06.webp\" alt=\"Python\u5982\u4f55\u505a\u6807\u51c6\u5316\u5904\u7406\" \/><\/p>\n<p><p> <strong>Python\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528StandardScaler\u3001MinMaxScaler\u3001RobustScaler\u7b49\u65b9\u6cd5\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\uff0c\u5e76\u7279\u522b\u8be6\u7ec6\u4ecb\u7ecdStandardScaler\u7684\u4f7f\u7528\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u6807\u51c6\u5316\u5904\u7406\u7684\u91cd\u8981\u6027<\/h3>\n<\/p>\n<p><p>\u6807\u51c6\u5316\u5904\u7406\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u91cd\u8981\u6b65\u9aa4\u4e4b\u4e00\uff0c\u5176\u76ee\u7684\u662f\u5c06\u4e0d\u540c\u7279\u5f81\u7684\u6570\u636e\u8fdb\u884c\u8f6c\u6362\uff0c\u4f7f\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u91cf\u7eb2\u6216\u8303\u56f4\uff0c\u4ece\u800c\u63d0\u9ad8<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002<strong>\u5e38\u7528\u7684\u6807\u51c6\u5316\u5904\u7406\u65b9\u6cd5\u5305\u62ecZ-score\u6807\u51c6\u5316\u3001Min-Max\u6807\u51c6\u5316\u3001Robust\u6807\u51c6\u5316\u7b49\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001Z-score\u6807\u51c6\u5316\uff08StandardScaler\uff09<\/h3>\n<\/p>\n<p><p>Z-score\u6807\u51c6\u5316\uff0c\u4e5f\u79f0\u4e3a\u96f6\u5747\u503c\u6807\u51c6\u5316\uff0c\u662f\u4e00\u79cd\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u8fc7\u7a0b\u3002\u5b83\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<\/p>\n<p><p>[ Z = \\frac{X &#8211; \\mu}{\\sigma} ]<\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c(X)\u662f\u539f\u59cb\u6570\u636e\uff0c(\\mu)\u662f\u6570\u636e\u7684\u5747\u503c\uff0c(\\sigma)\u662f\u6570\u636e\u7684\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><h4>1\u3001StandardScaler\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sklearn.preprocessing<\/code>\u6a21\u5757\u4e2d\u7684<code>StandardScaler<\/code>\u8fdb\u884cZ-score\u6807\u51c6\u5316\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import StandardScaler<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>data = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])<\/p>\n<h2><strong>\u521d\u59cb\u5316StandardScaler<\/strong><\/h2>\n<p>scaler = StandardScaler()<\/p>\n<h2><strong>\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406<\/strong><\/h2>\n<p>standardized_data = scaler.fit_transform(data)<\/p>\n<p>print(&quot;\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\uff1a\\n&quot;, standardized_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165<code>StandardScaler<\/code>\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u636e\u96c6\u3002\u63a5\u7740\uff0c\u6211\u4eec\u521d\u59cb\u5316<code>StandardScaler<\/code>\u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528<code>fit_transform<\/code>\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\u3002\u6700\u540e\uff0c\u8f93\u51fa\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8be6\u7ec6\u4ecb\u7ecdStandardScaler\u7684\u53c2\u6570\u548c\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p><code>StandardScaler<\/code>\u9664\u4e86<code>fit_transform<\/code>\u65b9\u6cd5\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u91cd\u8981\u7684\u65b9\u6cd5\u548c\u53c2\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>fit(X, y=None)<\/code>: \u8ba1\u7b97\u6570\u636e\u7684\u5747\u503c\u548c\u6807\u51c6\u5dee\uff0c\u4f46\u4e0d\u8fdb\u884c\u8f6c\u6362\u3002<\/li>\n<li><code>transform(X)<\/code>: \u4f7f\u7528\u5148\u524d\u8ba1\u7b97\u7684\u5747\u503c\u548c\u6807\u51c6\u5dee\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\u3002<\/li>\n<li><code>inverse_transform(X)<\/code>: \u5c06\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\u8fd8\u539f\u4e3a\u539f\u59cb\u6570\u636e\u3002<\/li>\n<li><code>with_mean<\/code>: \u662f\u5426\u5c06\u6570\u636e\u7684\u5747\u503c\u8bbe\u4e3a0\uff0c\u9ed8\u8ba4\u503c\u4e3a<code>True<\/code>\u3002<\/li>\n<li><code>with_std<\/code>: \u662f\u5426\u5c06\u6570\u636e\u7684\u6807\u51c6\u5dee\u8bbe\u4e3a1\uff0c\u9ed8\u8ba4\u503c\u4e3a<code>True<\/code>\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001Min-Max\u6807\u51c6\u5316\uff08MinMaxScaler\uff09<\/h3>\n<\/p>\n<p><p>Min-Max\u6807\u51c6\u5316\u662f\u5c06\u6570\u636e\u7f29\u653e\u5230\u4e00\u4e2a\u7279\u5b9a\u7684\u8303\u56f4\uff0c\u901a\u5e38\u662f[0, 1]\u3002\u5176\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<\/p>\n<p><p>[ X_{norm} = \\frac{X &#8211; X_{min}}{X_{max} &#8211; X_{min}} ]<\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c(X_{min})\u548c(X_{max})\u5206\u522b\u662f\u6570\u636e\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001MinMaxScaler\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sklearn.preprocessing<\/code>\u6a21\u5757\u4e2d\u7684<code>MinMaxScaler<\/code>\u8fdb\u884cMin-Max\u6807\u51c6\u5316\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import MinMaxScaler<\/p>\n<h2><strong>\u521d\u59cb\u5316MinMaxScaler<\/strong><\/h2>\n<p>scaler = MinMaxScaler()<\/p>\n<h2><strong>\u8fdb\u884cMin-Max\u6807\u51c6\u5316\u5904\u7406<\/strong><\/h2>\n<p>minmax_data = scaler.fit_transform(data)<\/p>\n<p>print(&quot;Min-Max\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\uff1a\\n&quot;, minmax_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001Robust\u6807\u51c6\u5316\uff08RobustScaler\uff09<\/h3>\n<\/p>\n<p><p>Robust\u6807\u51c6\u5316\u901a\u8fc7\u4e2d\u4f4d\u6570\u548c\u56db\u5206\u4f4d\u8303\u56f4\uff08IQR\uff09\u6765\u7f29\u653e\u6570\u636e\uff0c\u5bf9\u4e8e\u542b\u6709\u566a\u58f0\u548c\u79bb\u7fa4\u503c\u7684\u6570\u636e\u96c6\u7279\u522b\u6709\u6548\u3002\u5176\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<\/p>\n<p><p>[ X_{robust} = \\frac{X &#8211; \\text{median}}{\\text{IQR}} ]<\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c\u4e2d\u4f4d\u6570\u548c\u56db\u5206\u4f4d\u8303\u56f4\u5206\u522b\u662f\u6570\u636e\u7684\u4e2d\u4f4d\u6570\u548c\u56db\u5206\u4f4d\u8ddd\u79bb\u3002<\/p>\n<\/p>\n<p><h4>1\u3001RobustScaler\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sklearn.preprocessing<\/code>\u6a21\u5757\u4e2d\u7684<code>RobustScaler<\/code>\u8fdb\u884cRobust\u6807\u51c6\u5316\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import RobustScaler<\/p>\n<h2><strong>\u521d\u59cb\u5316RobustScaler<\/strong><\/h2>\n<p>scaler = RobustScaler()<\/p>\n<h2><strong>\u8fdb\u884cRobust\u6807\u51c6\u5316\u5904\u7406<\/strong><\/h2>\n<p>robust_data = scaler.fit_transform(data)<\/p>\n<p>print(&quot;Robust\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\uff1a\\n&quot;, robust_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u9009\u62e9\u6807\u51c6\u5316\u65b9\u6cd5\u7684\u6280\u5de7<\/h3>\n<\/p>\n<p><p><strong>\u5728\u9009\u62e9\u6807\u51c6\u5316\u65b9\u6cd5\u65f6\uff0c\u5e94\u6839\u636e\u6570\u636e\u7684\u7279\u6027\u548c\u6a21\u578b\u7684\u9700\u6c42\u6765\u8fdb\u884c\u9009\u62e9\u3002<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>Z-score\u6807\u51c6\u5316<\/strong>\u9002\u7528\u4e8e\u6570\u636e\u5206\u5e03\u63a5\u8fd1\u9ad8\u65af\u5206\u5e03\u7684\u60c5\u51b5\uff0c\u4e14\u5bf9\u79bb\u7fa4\u503c\u654f\u611f\u3002<\/li>\n<li><strong>Min-Max\u6807\u51c6\u5316<\/strong>\u9002\u7528\u4e8e\u6570\u636e\u8303\u56f4\u5df2\u77e5\u4e14\u5e0c\u671b\u5c06\u6570\u636e\u7f29\u653e\u5230\u7279\u5b9a\u8303\u56f4\u7684\u60c5\u51b5\uff0c\u4f46\u5bf9\u79bb\u7fa4\u503c\u540c\u6837\u654f\u611f\u3002<\/li>\n<li><strong>Robust\u6807\u51c6\u5316<\/strong>\u9002\u7528\u4e8e\u542b\u6709\u566a\u58f0\u548c\u79bb\u7fa4\u503c\u7684\u6570\u636e\u96c6\uff0c\u80fd\u6709\u6548\u51cf\u5c11\u79bb\u7fa4\u503c\u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u6807\u51c6\u5316\u5904\u7406\u901a\u5e38\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u7b2c\u4e00\u6b65\uff0c\u5c24\u5176\u5728\u4f7f\u7528\u68af\u5ea6\u4e0b\u964d\u7b97\u6cd5\u7684\u6a21\u578b\uff08\u5982\u7ebf\u6027\u56de\u5f52\u3001\u903b\u8f91\u56de\u5f52\u3001\u795e\u7ecf\u7f51\u7edc\u7b49\uff09\u4e2d\uff0c\u6807\u51c6\u5316\u5904\u7406\u53ef\u4ee5\u52a0\u5feb\u6a21\u578b\u7684\u6536\u655b\u901f\u5ea6\uff0c\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6807\u51c6\u5316\u5904\u7406\u5728\u673a\u5668\u5b66\u4e60\u7ba1\u9053\u4e2d\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u5c06\u6807\u51c6\u5316\u5904\u7406\u96c6\u6210\u5230\u673a\u5668\u5b66\u4e60\u7ba1\u9053\u4e2d\uff0c\u4ee5\u786e\u4fdd\u5728\u8bad\u7ec3\u548c\u9884\u6d4b\u8fc7\u7a0b\u4e2d\u5e94\u7528\u4e00\u81f4\u7684\u6570\u636e\u5904\u7406\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.pipeline import Pipeline<\/p>\n<p>from sklearn.linear_model import LogisticRegression<\/p>\n<h2><strong>\u521b\u5efa\u673a\u5668\u5b66\u4e60\u7ba1\u9053<\/strong><\/h2>\n<p>pipeline = Pipeline([<\/p>\n<p>    (&#39;scaler&#39;, StandardScaler()),  # \u6807\u51c6\u5316\u5904\u7406<\/p>\n<p>    (&#39;classifier&#39;, LogisticRegression())  # \u903b\u8f91\u56de\u5f52\u6a21\u578b<\/p>\n<p>])<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>pipeline.fit(X_tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n, y_train)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>y_pred = pipeline.predict(X_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u6807\u51c6\u5316\u5904\u7406\u548c\u903b\u8f91\u56de\u5f52\u6a21\u578b\u7684\u673a\u5668\u5b66\u4e60\u7ba1\u9053\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u786e\u4fdd\u5728\u8bad\u7ec3\u548c\u9884\u6d4b\u8fc7\u7a0b\u4e2d\u5e94\u7528\u4e00\u81f4\u7684\u6570\u636e\u5904\u7406\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4e0d\u540c\u6807\u51c6\u5316\u65b9\u6cd5\u7684\u6027\u80fd\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u6807\u51c6\u5316\u65b9\u6cd5\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b9e\u9a8c\u6bd4\u8f83\u4e0d\u540c\u65b9\u6cd5\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u5f71\u54cd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u6bd4\u8f83StandardScaler\u548cMinMaxScaler\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u5f71\u54cd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u5206\u5272\u6570\u636e\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u4f7f\u7528StandardScaler\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406<\/strong><\/h2>\n<p>scaler = StandardScaler()<\/p>\n<p>X_train_standard = scaler.fit_transform(X_train)<\/p>\n<p>X_test_standard = scaler.transform(X_test)<\/p>\n<h2><strong>\u8bad\u7ec3\u548c\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>model = LogisticRegression()<\/p>\n<p>model.fit(X_train_standard, y_train)<\/p>\n<p>y_pred_standard = model.predict(X_test_standard)<\/p>\n<p>print(&quot;\u4f7f\u7528StandardScaler\u7684\u51c6\u786e\u7387\uff1a&quot;, accuracy_score(y_test, y_pred_standard))<\/p>\n<h2><strong>\u4f7f\u7528MinMaxScaler\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406<\/strong><\/h2>\n<p>scaler = MinMaxScaler()<\/p>\n<p>X_train_minmax = scaler.fit_transform(X_train)<\/p>\n<p>X_test_minmax = scaler.transform(X_test)<\/p>\n<h2><strong>\u8bad\u7ec3\u548c\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train_minmax, y_train)<\/p>\n<p>y_pred_minmax = model.predict(X_test_minmax)<\/p>\n<p>print(&quot;\u4f7f\u7528MinMaxScaler\u7684\u51c6\u786e\u7387\uff1a&quot;, accuracy_score(y_test, y_pred_minmax))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u53ef\u4ee5\u6bd4\u8f83\u4f7f\u7528\u4e0d\u540c\u6807\u51c6\u5316\u65b9\u6cd5\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u5f71\u54cd\uff0c\u4ece\u800c\u9009\u62e9\u6700\u9002\u5408\u7684\u6807\u51c6\u5316\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u6807\u51c6\u5316\u5904\u7406\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u91cd\u8981\u6b65\u9aa4\uff0c\u5176\u76ee\u7684\u662f\u5c06\u4e0d\u540c\u7279\u5f81\u7684\u6570\u636e\u8fdb\u884c\u8f6c\u6362\uff0c\u4f7f\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u91cf\u7eb2\u6216\u8303\u56f4\uff0c\u4ece\u800c\u63d0\u9ad8\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u5728Python\u4e2d\uff0c\u5e38\u7528\u7684\u6807\u51c6\u5316\u5904\u7406\u65b9\u6cd5\u5305\u62ecZ-score\u6807\u51c6\u5316\uff08StandardScaler\uff09\u3001Min-Max\u6807\u51c6\u5316\uff08MinMaxScaler\uff09\u3001Robust\u6807\u51c6\u5316\uff08RobustScaler\uff09\u7b49\u3002\u5728\u9009\u62e9\u6807\u51c6\u5316\u65b9\u6cd5\u65f6\uff0c\u5e94\u6839\u636e\u6570\u636e\u7684\u7279\u6027\u548c\u6a21\u578b\u7684\u9700\u6c42\u6765\u8fdb\u884c\u9009\u62e9\uff0c\u5e76\u901a\u8fc7\u5b9e\u9a8c\u6bd4\u8f83\u4e0d\u540c\u65b9\u6cd5\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u5f71\u54cd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u4ec0\u4e48\u662f\u6807\u51c6\u5316\u5904\u7406\uff0c\u4e3a\u4ec0\u4e48\u5728Python\u4e2d\u4f7f\u7528\u5b83\uff1f<\/strong><br \/>\u6807\u51c6\u5316\u5904\u7406\u662f\u6570\u636e\u9884\u5904\u7406\u4e2d\u7684\u4e00\u79cd\u5e38\u89c1\u6280\u672f\uff0c\u65e8\u5728\u5c06\u7279\u5f81\u503c\u8f6c\u6362\u4e3a\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u5206\u5e03\u3002\u901a\u8fc7\u6807\u51c6\u5316\uff0c\u53ef\u4ee5\u6d88\u9664\u4e0d\u540c\u7279\u5f81\u7684\u91cf\u7eb2\u5f71\u54cd\uff0c\u4f7f\u6a21\u578b\u8bad\u7ec3\u66f4\u52a0\u7a33\u5b9a\u548c\u9ad8\u6548\u3002\u5728Python\u4e2d\uff0c\u6807\u51c6\u5316\u901a\u5e38\u901a\u8fc7\u5e93\u5982scikit-learn\u5b9e\u73b0\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5b9e\u65bd\u6807\u51c6\u5316\u5904\u7406\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b9e\u65bd\u6807\u51c6\u5316\u5904\u7406\u901a\u5e38\u4f7f\u7528<code>StandardScaler<\/code>\u7c7b\u3002\u9996\u5148\uff0c\u9700\u8981\u5bfc\u5165\u8be5\u7c7b\u5e76\u521b\u5efa\u5b9e\u4f8b\u3002\u63a5\u7740\uff0c\u901a\u8fc7\u8c03\u7528<code>fit()<\/code>\u65b9\u6cd5\u8ba1\u7b97\u8bad\u7ec3\u6570\u636e\u7684\u5747\u503c\u548c\u6807\u51c6\u5dee\uff0c\u968f\u540e\u4f7f\u7528<code>transform()<\/code>\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u3002\u5b8c\u6574\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nscaled_data = scaler.fit_transform(data)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6570\u636e\u5c31\u88ab\u6807\u51c6\u5316\u4e3a\u96f6\u5747\u503c\u548c\u5355\u4f4d\u65b9\u5dee\u7684\u5206\u5e03\u3002<\/p>\n<p><strong>\u6807\u51c6\u5316\u5904\u7406\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u6548\u679c\u5982\u4f55\uff1f<\/strong><br \/>\u6807\u51c6\u5316\u5904\u7406\u5728\u8bb8\u591a\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u4e2d\u975e\u5e38\u6709\u6548\uff0c\u5c24\u5176\u662f\u90a3\u4e9b\u4f9d\u8d56\u4e8e\u8ddd\u79bb\u7684\u7b97\u6cd5\uff0c\u5982K\u8fd1\u90bb\u548c\u652f\u6301\u5411\u91cf\u673a\u3002\u5bf9\u4e8e\u7ebf\u6027\u56de\u5f52\u3001\u903b\u8f91\u56de\u5f52\u7b49\u6a21\u578b\uff0c\u6807\u51c6\u5316\u53ef\u4ee5\u52a0\u901f\u6536\u655b\uff0c\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u6811\u6a21\u578b\uff08\u5982\u51b3\u7b56\u6811\u3001\u968f\u673a\u68ee\u6797\uff09\uff0c\u6807\u51c6\u5316\u5904\u7406\u7684\u6548\u679c\u5e76\u4e0d\u660e\u663e\uff0c\u56e0\u4e3a\u6811\u6a21\u578b\u4e0d\u4f9d\u8d56\u4e8e\u7279\u5f81\u7684\u5c3a\u5ea6\u3002\u56e0\u6b64\uff0c\u9009\u62e9\u662f\u5426\u8fdb\u884c\u6807\u51c6\u5316\u65f6\uff0c\u5e94\u8003\u8651\u6240\u4f7f\u7528\u7684\u7b97\u6cd5\u7279\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528StandardScaler\u3001MinMaxScaler\u3001Rob [&hellip;]","protected":false},"author":3,"featured_media":1078863,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1078856"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1078856"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1078856\/revisions"}],"predecessor-version":[{"id":1078865,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1078856\/revisions\/1078865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1078863"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1078856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1078856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1078856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}