{"id":1184892,"date":"2025-01-15T19:32:10","date_gmt":"2025-01-15T11:32:10","guid":{"rendered":""},"modified":"2025-01-15T19:32:19","modified_gmt":"2025-01-15T11:32:19","slug":"%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e9%a2%84%e6%b5%8bpython-%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1184892.html","title":{"rendered":"\u5982\u4f55\u8fdb\u884c\u9884\u6d4bpython \u4ee3\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25134212\/d40f2310-b6d4-4c78-9fe9-6b8360c8bd82.webp\" alt=\"\u5982\u4f55\u8fdb\u884c\u9884\u6d4bpython \u4ee3\u7801\" \/><\/p>\n<p><p> \u5728\u9884\u6d4b\u4efb\u52a1\u4e2d\uff0cPython \u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u62e5\u6709\u4e30\u5bcc\u7684\u5e93\u548c\u6846\u67b6\u6765\u5904\u7406\u5404\u79cd\u9884\u6d4b\u95ee\u9898\u3002<strong>\u8981\u8fdb\u884c\u9884\u6d4b Python \u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u5e93\u5982 scikit-learn\u3001TensorFlow\u3001Keras\u3001PyTorch \u7b49<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u5e93\u4e4b\u4e00\u662f scikit-learn\uff0c\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u73b0\u6210\u7684\u7b97\u6cd5\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u3002<strong>\u9996\u5148\u9700\u8981\u51c6\u5907\u6570\u636e\u3001\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u3001\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u3001\u8bad\u7ec3\u6a21\u578b\u3001\u8fdb\u884c\u6a21\u578b\u8bc4\u4f30\u548c\u9884\u6d4b<\/strong>\u3002\u8ba9\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51c6\u5907\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u4efb\u4f55\u9884\u6d4b\u4efb\u52a1\u4e4b\u524d\uff0c\u6570\u636e\u51c6\u5907\u662f\u5173\u952e\u7684\u7b2c\u4e00\u6b65\u3002\u6570\u636e\u901a\u5e38\u4ece\u6570\u636e\u5e93\u3001API\u3001CSV \u6587\u4ef6\u7b49\u591a\u79cd\u6765\u6e90\u83b7\u53d6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u52a0\u8f7d\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u52a0\u8f7d\u6570\u636e\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7 pandas \u5e93\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u6e05\u6d17<\/h4>\n<\/p>\n<p><p>\u6570\u636e\u901a\u5e38\u5305\u542b\u7f3a\u5931\u503c\u3001\u5f02\u5e38\u503c\u7b49\uff0c\u9700\u8981\u8fdb\u884c\u6e05\u6d17\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u53bb\u9664\u7f3a\u5931\u503c<\/p>\n<p>data.dropna(inplace=True)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u63cf\u8ff0<\/strong><\/h2>\n<p>print(data.describe())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b<\/h3>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u9884\u6d4b\u4efb\u52a1\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684\u6a21\u578b\uff0c\u4f8b\u5982\u7ebf\u6027\u56de\u5f52\u3001\u51b3\u7b56\u6811\u3001\u652f\u6301\u5411\u91cf\u673a\u7b49\u3002\u9009\u62e9\u6a21\u578b\u65f6\u9700\u8981\u8003\u8651\u6570\u636e\u7684\u6027\u8d28\u548c\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5206\u7c7b\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u76ee\u6807\u662f\u5206\u7c7b\uff0c\u53ef\u4ee5\u9009\u62e9\u903b\u8f91\u56de\u5f52\u3001\u51b3\u7b56\u6811\u3001\u968f\u673a\u68ee\u6797\u3001SVM \u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_test_split<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u7279\u5f81\u548c\u76ee\u6807<\/strong><\/h2>\n<p>X = data.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = data[&#39;target&#39;]<\/p>\n<h2><strong>\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<\/p>\n<h2><strong>\u9009\u62e9\u968f\u673a\u68ee\u6797\u5206\u7c7b\u5668<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<h2><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;\u6a21\u578b\u51c6\u786e\u7387: {accuracy}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u56de\u5f52\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u76ee\u6807\u662f\u56de\u5f52\uff0c\u53ef\u4ee5\u9009\u62e9\u7ebf\u6027\u56de\u5f52\u3001\u5cad\u56de\u5f52\u3001Lasso \u56de\u5f52\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.linear_model import LinearRegression<\/p>\n<p>from sklearn.metrics import mean_squared_error<\/p>\n<h2><strong>\u7279\u5f81\u548c\u76ee\u6807<\/strong><\/h2>\n<p>X = data.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = data[&#39;target&#39;]<\/p>\n<h2><strong>\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<\/p>\n<h2><strong>\u9009\u62e9\u7ebf\u6027\u56de\u5f52\u6a21\u578b<\/strong><\/h2>\n<p>model = LinearRegression()<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<h2><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>mse = mean_squared_error(y_test, y_pred)<\/p>\n<p>print(f&#39;\u5747\u65b9\u8bef\u5dee: {mse}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6570\u636e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u9884\u5904\u7406\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u91cd\u8981\u6b65\u9aa4\uff0c\u5305\u62ec\u6570\u636e\u6807\u51c6\u5316\u3001\u7279\u5f81\u9009\u62e9\u3001\u964d\u7ef4\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6807\u51c6\u5316<\/h4>\n<\/p>\n<p><p>\u6807\u51c6\u5316\u53ef\u4ee5\u4f7f\u6570\u636e\u7684\u5206\u5e03\u66f4\u5747\u5300\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import StandardScaler<\/p>\n<h2><strong>\u521b\u5efa\u6807\u51c6\u5316\u5bf9\u8c61<\/strong><\/h2>\n<p>scaler = StandardScaler()<\/p>\n<h2><strong>\u6807\u51c6\u5316\u6570\u636e<\/strong><\/h2>\n<p>X_train = scaler.fit_transform(X_train)<\/p>\n<p>X_test = scaler.transform(X_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7279\u5f81\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u9009\u62e9\u53ef\u4ee5\u51cf\u5c11\u7279\u5f81\u6570\u91cf\uff0c\u63d0\u9ad8\u6a21\u578b\u7684\u6548\u7387\u548c\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.feature_selection import SelectKBest, f_classif<\/p>\n<h2><strong>\u9009\u62e9\u6700\u4f73\u7279\u5f81<\/strong><\/h2>\n<p>selector = SelectKBest(score_func=f_classif, k=10)<\/p>\n<p>X_new = selector.fit_transform(X, y)<\/p>\n<h2><strong>\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=0.3, random_state=42)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6a21\u578b\u8bad\u7ec3<\/h3>\n<\/p>\n<p><p>\u8bad\u7ec3\u6a21\u578b\u662f\u6574\u4e2a\u9884\u6d4b\u8fc7\u7a0b\u7684\u6838\u5fc3\u90e8\u5206\uff0c\u6839\u636e\u9009\u62e9\u7684\u6a21\u578b\u548c\u9884\u5904\u7406\u540e\u7684\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8bad\u7ec3\u5206\u7c7b\u6a21\u578b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u968f\u673a\u68ee\u6797\u5206\u7c7b\u5668<\/p>\n<p>model = RandomForestClassifier(n_estimators=100, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train, y_train)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bad\u7ec3\u56de\u5f52\u6a21\u578b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u62e9\u7ebf\u6027\u56de\u5f52\u6a21\u578b<\/p>\n<p>model = LinearRegression()<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_train, y_train)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u6a21\u578b\u8bc4\u4f30\u548c\u9884\u6d4b<\/h3>\n<\/p>\n<p><p>\u8bad\u7ec3\u597d\u6a21\u578b\u540e\uff0c\u9700\u8981\u5bf9\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30\uff0c\u4ee5\u786e\u5b9a\u5176\u6027\u80fd\uff0c\u5e76\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6a21\u578b\u8bc4\u4f30<\/h4>\n<\/p>\n<p><p>\u6a21\u578b\u8bc4\u4f30\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u6307\u6807\uff0c\u5982\u51c6\u786e\u7387\u3001\u5747\u65b9\u8bef\u5dee\u3001\u53ec\u56de\u7387\u3001F1 \u5206\u6570\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.metrics import accuracy_score, mean_squared_error, classification_report<\/p>\n<h2><strong>\u5bf9\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;\u6a21\u578b\u51c6\u786e\u7387: {accuracy}&#39;)<\/p>\n<p>print(classification_report(y_test, y_pred))<\/p>\n<h2><strong>\u5bf9\u56de\u5f52\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>mse = mean_squared_error(y_test, y_pred)<\/p>\n<p>print(f&#39;\u5747\u65b9\u8bef\u5dee: {mse}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8fdb\u884c\u9884\u6d4b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u53ef\u4ee5\u5c06\u65b0\u6570\u636e\u8f93\u5165\u6a21\u578b\uff0c\u5f97\u5230\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u65b0\u6570\u636e<\/p>\n<p>new_data = [[value1, value2, value3, ...]]<\/p>\n<h2><strong>\u6807\u51c6\u5316\u65b0\u6570\u636e<\/strong><\/h2>\n<p>new_data = scaler.transform(new_data)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>prediction = model.predict(new_data)<\/p>\n<p>print(f&#39;\u9884\u6d4b\u7ed3\u679c: {prediction}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6a21\u578b\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u521d\u6b65\u7684\u6a21\u578b\u8bad\u7ec3\u548c\u8bc4\u4f30\u540e\uff0c\u53ef\u4ee5\u5bf9\u6a21\u578b\u8fdb\u884c\u8fdb\u4e00\u6b65\u4f18\u5316\uff0c\u4ee5\u63d0\u9ad8\u9884\u6d4b\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8d85\u53c2\u6570\u8c03\u6574<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574\u6a21\u578b\u7684\u8d85\u53c2\u6570\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import GridSearchCV<\/p>\n<h2><strong>\u5b9a\u4e49\u53c2\u6570\u7f51\u683c<\/strong><\/h2>\n<p>param_grid = {<\/p>\n<p>    &#39;n_estimators&#39;: [50, 100, 200],<\/p>\n<p>    &#39;max_depth&#39;: [None, 10, 20, 30],<\/p>\n<p>    &#39;min_samples_split&#39;: [2, 5, 10]<\/p>\n<p>}<\/p>\n<h2><strong>\u8fdb\u884c\u7f51\u683c\u641c\u7d22<\/strong><\/h2>\n<p>grid_search = GridSearchCV(model, param_grid, cv=5)<\/p>\n<p>grid_search.fit(X_train, y_train)<\/p>\n<h2><strong>\u6700\u4f73\u53c2\u6570<\/strong><\/h2>\n<p>print(f&#39;\u6700\u4f73\u53c2\u6570: {grid_search.best_params_}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4ea4\u53c9\u9a8c\u8bc1<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\uff0c\u51cf\u5c11\u8fc7\u62df\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import cross_val_score<\/p>\n<h2><strong>\u8fdb\u884c\u4ea4\u53c9\u9a8c\u8bc1<\/strong><\/h2>\n<p>cv_scores = cross_val_score(model, X, y, cv=5)<\/p>\n<p>print(f&#39;\u4ea4\u53c9\u9a8c\u8bc1\u8bc4\u5206: {cv_scores}&#39;)<\/p>\n<p>print(f&#39;\u5e73\u5747\u4ea4\u53c9\u9a8c\u8bc1\u8bc4\u5206: {cv_scores.mean()}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u6a21\u578b\u4fdd\u5b58\u548c\u52a0\u8f7d<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u901a\u5e38\u9700\u8981\u4fdd\u5b58\uff0c\u4ee5\u4fbf\u5728\u5c06\u6765\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 joblib \u6216 pickle \u5e93\u6765\u4fdd\u5b58\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import joblib<\/p>\n<h2><strong>\u4fdd\u5b58\u6a21\u578b<\/strong><\/h2>\n<p>joblib.dump(model, &#39;model.pkl&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u52a0\u8f7d\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u5728\u9700\u8981\u4f7f\u7528\u6a21\u578b\u65f6\uff0c\u53ef\u4ee5\u5c06\u5176\u52a0\u8f7d\u56de\u6765\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u52a0\u8f7d\u6a21\u578b<\/p>\n<p>model = joblib.load(&#39;model.pkl&#39;)<\/p>\n<h2><strong>\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>prediction = model.predict(new_data)<\/p>\n<p>print(f&#39;\u9884\u6d4b\u7ed3\u679c: {prediction}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5b8c\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u9884\u6d4b\u4efb\u52a1\u3002<strong>\u4ece\u6570\u636e\u51c6\u5907\u3001\u6a21\u578b\u9009\u62e9\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bad\u7ec3\u3001\u6a21\u578b\u8bc4\u4f30\u5230\u6a21\u578b\u4f18\u5316\u548c\u4fdd\u5b58<\/strong>\uff0c\u6bcf\u4e00\u6b65\u90fd\u81f3\u5173\u91cd\u8981\u3002<strong>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8fd8\u9700\u8981\u6839\u636e\u5177\u4f53\u95ee\u9898\u8fdb\u884c\u8c03\u6574\u548c\u4f18\u5316<\/strong>\u3002Python \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e93\u548c\u5de5\u5177\uff0c\u4f7f\u5f97\u8fd9\u4e00\u8fc7\u7a0b\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u548c\u4fbf\u6377\u3002\u65e0\u8bba\u662f\u5206\u7c7b\u95ee\u9898\u8fd8\u662f\u56de\u5f52\u95ee\u9898\uff0c\u90fd\u53ef\u4ee5\u627e\u5230\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0d\u65ad\u5b9e\u8df5\u548c\u4f18\u5316\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u9884\u6d4b\u6027\u80fd\uff0c\u4e3a\u5b9e\u9645\u4e1a\u52a1\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u4f60\u5728\u9884\u6d4b\u4efb\u52a1\u4e2d\u53d6\u5f97\u6210\u529f\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u9884\u6d4b\u6a21\u578b\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684\u9884\u6d4b\u6a21\u578b\u53d6\u51b3\u4e8e\u591a\u4e2a\u56e0\u7d20\uff0c\u5305\u62ec\u6570\u636e\u7684\u7c7b\u578b\u3001\u9884\u6d4b\u7684\u76ee\u6807\u4ee5\u53ca\u53ef\u7528\u7684\u8ba1\u7b97\u8d44\u6e90\u3002\u5bf9\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528ARIMA\u6216\u5b63\u8282\u6027\u5206\u89e3\u6a21\u578b\u3002\u5982\u679c\u6570\u636e\u662f\u5206\u7c7b\u6027\u8d28\u7684\uff0c\u903b\u8f91\u56de\u5f52\u3001\u51b3\u7b56\u6811\u6216\u968f\u673a\u68ee\u6797\u53ef\u80fd\u66f4\u4e3a\u9002\u5408\u3002\u5728\u8fdb\u884c\u9009\u62e9\u65f6\uff0c\u786e\u4fdd\u5bf9\u4e0d\u540c\u6a21\u578b\u7684\u5047\u8bbe\u548c\u4f18\u7f3a\u70b9\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u5e76\u53ef\u4ee5\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u6765\u6bd4\u8f83\u5b83\u4eec\u7684\u6027\u80fd\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u7f3a\u5931\u6570\u636e\u4ee5\u63d0\u9ad8\u9884\u6d4b\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u5904\u7406\u7f3a\u5931\u6570\u636e\u662f\u63d0\u9ad8\u9884\u6d4b\u51c6\u786e\u6027\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u4e2d\u7684<code>fillna()<\/code>\u65b9\u6cd5\u6765\u586b\u8865\u7f3a\u5931\u503c\uff0c\u5e38\u89c1\u7684\u586b\u5145\u65b9\u5f0f\u5305\u62ec\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u6216\u4f7f\u7528\u524d\u540e\u503c\u586b\u5145\u3002\u6b64\u5916\uff0c\u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c\u4e5f\u662f\u4e00\u79cd\u65b9\u6cd5\uff0c\u5c3d\u7ba1\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u91cf\u51cf\u5c11\u3002\u786e\u4fdd\u5728\u586b\u8865\u7f3a\u5931\u503c\u4e4b\u524d\u5206\u6790\u6570\u636e\u7684\u6027\u8d28\uff0c\u4ee5\u9009\u62e9\u6700\u9002\u5408\u7684\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bc4\u4f30\u9884\u6d4b\u6a21\u578b\u7684\u6027\u80fd\uff1f<\/strong><br \/>\u8bc4\u4f30\u9884\u6d4b\u6a21\u578b\u7684\u6027\u80fd\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u6307\u6807\u6765\u5b9e\u73b0\u3002\u5e38\u89c1\u7684\u8bc4\u4f30\u6307\u6807\u5305\u62ec\u5747\u65b9\u8bef\u5dee\uff08MSE\uff09\u3001\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee\uff08MAE\uff09\u548cR\u00b2\u503c\u7b49\u3002\u4f7f\u7528Scikit-learn\u5e93\u4e2d\u7684<code>mean_squared_error<\/code>\u548c<code>r2_score<\/code>\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba1\u7b97\u8fd9\u4e9b\u6307\u6807\u3002\u6b64\u5916\uff0c\u7ed8\u5236\u9884\u6d4b\u7ed3\u679c\u4e0e\u5b9e\u9645\u7ed3\u679c\u7684\u5bf9\u6bd4\u56fe\u4e5f\u662f\u4e00\u79cd\u76f4\u89c2\u7684\u8bc4\u4f30\u65b9\u5f0f\uff0c\u6709\u52a9\u4e8e\u8bc6\u522b\u6a21\u578b\u7684\u4e0d\u8db3\u4e4b\u5904\u3002\u786e\u4fdd\u5728\u8bc4\u4f30\u65f6\u4f7f\u7528\u72ec\u7acb\u7684\u6d4b\u8bd5\u96c6\uff0c\u4ee5\u83b7\u53d6\u66f4\u51c6\u786e\u7684\u6027\u80fd\u8bc4\u4f30\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u9884\u6d4b\u4efb\u52a1\u4e2d\uff0cPython \u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u62e5\u6709\u4e30\u5bcc\u7684\u5e93\u548c\u6846\u67b6\u6765\u5904\u7406\u5404\u79cd\u9884\u6d4b\u95ee\u9898\u3002\u8981\u8fdb\u884c\u9884\u6d4b Pytho [&hellip;]","protected":false},"author":3,"featured_media":1184903,"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\/1184892"}],"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=1184892"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184892\/revisions"}],"predecessor-version":[{"id":1184910,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184892\/revisions\/1184910"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1184903"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1184892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1184892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1184892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}