{"id":9418,"date":"2025-06-10T19:21:16","date_gmt":"2025-06-10T11:21:16","guid":{"rendered":"\/?p=9418"},"modified":"2025-06-10T19:21:16","modified_gmt":"2025-06-10T11:21:16","slug":"scikit-learn%ef%bc%88sklearn%ef%bc%89%e5%af%b9%e6%af%94","status":"publish","type":"post","link":"\/?p=9418","title":{"rendered":"Scikit-learn\uff08sklearn\uff09\u5bf9\u6bd4"},"content":{"rendered":"<p><strong>\u5b89\u88c5\uff1a<\/strong><code>pip install scikit-learn<\/code><\/p>\n<p>\u4ee5\u4e0b\u662f\u5173\u4e8eScikit-learn\uff08sklearn\uff09\u4e0ePyTorch\/TensorFlow\u7684\u6838\u5fc3\u533a\u522b\u53ca\u9002\u7528\u573a\u666f\u7684\u5168\u9762\u5206\u6790\uff0c\u7ed3\u5408\u6280\u672f\u7279\u6027\u548c\u5b9e\u9645\u5e94\u7528\u573a\u666f\u8fdb\u884c\u5bf9\u6bd4\uff1a<\/p>\n<hr \/>\n<h3>\ud83d\udcca <strong>\u6838\u5fc3\u5b9a\u4f4d\u5bf9\u6bd4<\/strong><\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u7ef4\u5ea6<\/strong><\/th>\n<th><strong>Scikit-learn<\/strong><\/th>\n<th><strong>PyTorch<\/strong><\/th>\n<th><strong>TensorFlow<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u6838\u5fc3\u529f\u80fd<\/strong><\/td>\n<td>\u4f20\u7edf\u673a\u5668\u5b66\u4e60\uff08\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\uff09\ud83d\udcca<\/td>\n<td>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff08CNN\u3001RNN\u3001Transformer\uff09\ud83e\udde0<\/td>\n<td>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff08\u5de5\u4e1a\u7ea7\u90e8\u7f72\uff09\ud83c\udfed<\/td>\n<\/tr>\n<tr>\n<td><strong>\u8bbe\u8ba1\u76ee\u6807<\/strong><\/td>\n<td>\u5feb\u901f\u5b9e\u73b0\u7ecf\u5178\u7b97\u6cd5\uff0c\u7b80\u5316\u6570\u636e\u9884\u5904\u7406<\/td>\n<td>\u7814\u7a76\u5bfc\u5411\uff0c\u652f\u6301\u52a8\u6001\u8ba1\u7b97\u56fe\u4e0e\u7075\u6d3b\u8c03\u8bd5\ud83d\udd27<\/td>\n<td>\u751f\u4ea7\u90e8\u7f72\u4f18\u5316\uff0c\u652f\u6301\u9759\u6001\u8ba1\u7b97\u56fe\u2699\ufe0f<\/td>\n<\/tr>\n<tr>\n<td><strong>API\u98ce\u683c<\/strong><\/td>\n<td>\u7edf\u4e00\u63a5\u53e3\uff08<code>fit()<\/code>\/<code>predict()<\/code>\uff09<\/td>\n<td>\u6a21\u5757\u5316\u6784\u5efa\uff08\u81ea\u5b9a\u4e49<code>nn.Module<\/code>\uff09<\/td>\n<td>\u9ad8\u7ea7API\uff08Keras\uff09\u4e0e\u5e95\u5c42API\u6df7\u5408<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u2699\ufe0f <strong>\u6280\u672f\u7279\u6027\u6df1\u5ea6\u89e3\u6790<\/strong><\/h3>\n<h4>1. <strong>Scikit-learn\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u745e\u58eb\u519b\u5200<\/strong><\/h4>\n<ul>\n<li>\n<p>\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u4e2d\u5c0f\u89c4\u6a21\u7ed3\u6784\u5316\u6570\u636e\uff08\u5982\u8868\u683c\u6570\u636e\uff09<\/li>\n<li>\u5feb\u901f\u9a8c\u8bc1\u7b97\u6cd5\u539f\u578b\uff08\u903b\u8f91\u56de\u5f52\u3001\u968f\u673a\u68ee\u6797\u7b49\uff09<\/li>\n<li>\u5168\u6d41\u7a0b\u8986\u76d6\uff1a\u6570\u636e\u6e05\u6d17 \u2192 \u7279\u5f81\u5de5\u7a0b \u2192 \u6a21\u578b\u8bc4\u4f30<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4f18\u52bf<\/p>\n<pre><code class=\"language-python\"># \u793a\u4f8b\uff1a3\u884c\u4ee3\u7801\u8bad\u7ec3\u968f\u673a\u68ee\u6797\nfrom sklearn.ensemble import RandomForestClassifier\nmodel = RandomForestClassifier()\nmodel.fit(X_train, y_train)  # \u5185\u7f6e\u6570\u636e\u6807\u51c6\u5316\u3001\u7f3a\u5931\u503c\u5904\u7406<\/code><\/pre>\n<ul>\n<li>\u5185\u7f6e\u4e30\u5bcc\u5de5\u5177\uff1a\u7279\u5f81\u9009\u62e9\uff08<code>SelectKBest<\/code>\uff09\u3001\u4ea4\u53c9\u9a8c\u8bc1\uff08<code>cross_val_score<\/code>\uff09<\/li>\n<li>\u65e0\u9700GPU\u652f\u6301\uff0cCPU\u9ad8\u6548\u8fd0\u884c\uff08Cython\u5e95\u5c42\u4f18\u5316\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. <strong>PyTorch\uff1a\u79d1\u7814\u521b\u65b0\u7684\u9996\u9009<\/strong><\/h4>\n<ul>\n<li>\n<p>\u6838\u5fc3\u7279\u6027<\/p>\n<ul>\n<li><strong>\u52a8\u6001\u8ba1\u7b97\u56fe<\/strong>\uff1a\u5b9e\u65f6\u8c03\u8bd5\u4e2d\u95f4\u53d8\u91cf\uff08\u5982<code>print()<\/code>\u67e5\u770b\u5f20\u91cf\uff09<\/li>\n<li><strong>\u7814\u7a76\u53cb\u597d<\/strong>\uff1aTransformer\u3001BERT\u7b49\u524d\u6cbf\u6a21\u578b\u7684\u9996\u9009\u5b9e\u73b0\u6846\u67b6<\/li>\n<li><strong>\u751f\u6001\u6269\u5c55<\/strong>\uff1aTorchVision\uff08CV\uff09\u3001TorchText\uff08NLP\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5178\u578b\u4ee3\u7801\u7ed3\u6784<\/p>\n<pre><code class=\"language-python\"># \u81ea\u5b9a\u4e49\u795e\u7ecf\u7f51\u7edc\u4e0e\u8bad\u7ec3\u5faa\u73af\nclass CNN(nn.Module):\n  def __init__(self):\n      super().__init__()\n      self.conv1 = nn.Conv2d(3, 16, kernel_size=3)  # \u7075\u6d3b\u5b9a\u4e49\u5c42\u7ed3\u6784\n\n  def forward(self, x):\n      return self.conv1(x)\n\noptimizer = torch.optim.Adam(model.parameters())  # \u624b\u52a8\u63a7\u5236\u4f18\u5316\u8fc7\u7a0b<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>3. <strong>TensorFlow\uff1a\u5de5\u4e1a\u7ea7\u90e8\u7f72\u7684\u6807\u6746<\/strong><\/h4>\n<ul>\n<li>\n<p>\u6838\u5fc3\u4f18\u52bf<\/p>\n<ul>\n<li><strong>\u9759\u6001\u8ba1\u7b97\u56fe<\/strong>\uff1a\u9884\u7f16\u8bd1\u4f18\u5316\uff0c\u9002\u5408\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u8bad\u7ec3<\/li>\n<li><strong>\u751f\u4ea7\u5de5\u5177\u94fe<\/strong>\uff1aTensorFlow Serving\uff08\u670d\u52a1\u90e8\u7f72\uff09\u3001TF Lite\uff08\u79fb\u52a8\u7aef\uff09<\/li>\n<li><strong>Keras\u524d\u7aef<\/strong>\uff1a\u7b80\u5316\u6a21\u578b\u6784\u5efa\uff08<code>Sequential<\/code>\/<code>Functional API<\/code>\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u90e8\u7f72\u793a\u4f8b<\/p>\n<pre><code class=\"language-python\"># \u4f7f\u7528Keras\u5feb\u901f\u6784\u5efa\u6a21\u578b\nmodel = tf.keras.Sequential([\n  tf.keras.layers.Dense(64, activation='relu'),\n  tf.keras.layers.Dense(10, activation='softmax')\n])\nmodel.compile(optimizer='adam', loss='sparse_categorical_crossentropy')\nmodel.save('model.h5')  # \u4e00\u952e\u5bfc\u51fa\u751f\u4ea7\u6a21\u578b<\/code><\/pre>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\ud83c\udfaf <strong>\u573a\u666f\u5316\u9009\u62e9\u6307\u5357<\/strong><\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u4efb\u52a1\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u63a8\u8350\u5de5\u5177<\/strong><\/th>\n<th><strong>\u7406\u7531<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8868\u683c\u6570\u636e\u5206\u7c7b\/\u56de\u5f52<\/td>\n<td>Scikit-learn<\/td>\n<td>10\u884c\u4ee3\u7801\u5185\u5b8c\u6210\u9884\u5904\u7406\u2192\u8bad\u7ec3\u2192\u8bc4\u4f30\uff0c\u65e0\u9700\u6df1\u5ea6\u5b66\u4e60\u77e5\u8bc6<\/td>\n<\/tr>\n<tr>\n<td>\u6df1\u5ea6\u5b66\u4e60\u7814\u7a76\uff08NLP\/CV\uff09<\/td>\n<td>PyTorch<\/td>\n<td>\u52a8\u6001\u56fe\u8c03\u8bd5\u8bba\u6587\u590d\u73b0\uff0c\u793e\u533a\u8d44\u6e90\u4e30\u5bcc\uff08Hugging Face\u7b49\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u89c4\u6a21\u751f\u4ea7\u90e8\u7f72<\/td>\n<td>TensorFlow<\/td>\n<td>\u652f\u6301\u5206\u5e03\u5f0f\u8bad\u7ec3\u3001\u6a21\u578b\u52a0\u5bc6\u3001\u670d\u52a1\u5316\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>\u79fb\u52a8\u7aefAI\u5e94\u7528<\/td>\n<td>TensorFlow Lite<\/td>\n<td>\u6a21\u578b\u91cf\u5316\u4e0e\u786c\u4ef6\u52a0\u901f\u4f18\u5316\uff0c\u5b89\u5353\/iOS\u65e0\u7f1d\u96c6\u6210<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\ud83d\udd04 <strong>\u534f\u540c\u5de5\u4f5c\u6d41\u793a\u4f8b<\/strong><\/h3>\n<p>\u5b9e\u9645\u9879\u76ee\u4e2d\u5e38\u7ec4\u5408\u4f7f\u7528\uff1a<\/p>\n<ol>\n<li><strong>\u6570\u636e\u9884\u5904\u7406<\/strong>\uff1a\u7528Scikit-learn\u7684<code>StandardScaler<\/code>\u6807\u51c6\u5316\u6570\u636e<\/li>\n<li><strong>\u7279\u5f81\u5de5\u7a0b<\/strong>\uff1a\u7528Scikit-learn\u7684<code>PCA<\/code>\u964d\u7ef4 \u2192 \u8f93\u5165PyTorch\u6a21\u578b<\/li>\n<li><strong>\u6a21\u578b\u90e8\u7f72<\/strong>\uff1a\u5c06PyTorch\u6a21\u578b\u8f6cONNX \u2192 \u901a\u8fc7TensorFlow Serving\u90e8\u7f72<\/li>\n<\/ol>\n<blockquote>\n<p>\ud83d\udca1 <strong>\u5173\u952e\u7ed3\u8bba<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u521d\u5b66\u8005<\/strong>\uff1a\u4eceScikit-learn\u5165\u624b\u7406\u89e3\u673a\u5668\u5b66\u4e60\u57fa\u7840<\/li>\n<li><strong>\u7814\u7a76\u8005<\/strong>\uff1a\u7528PyTorch\u5feb\u901f\u9a8c\u8bc1\u65b0\u7b97\u6cd5<\/li>\n<li><strong>\u5de5\u7a0b\u5e08<\/strong>\uff1a\u4f9d\u8d56TensorFlow\u6784\u5efa\u53ef\u6269\u5c55\u7684\u751f\u4ea7\u7cfb\u7edf<\/li>\n<\/ul>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5\uff1apip install scikit-learn \u4ee5\u4e0b\u662f\u5173\u4e8eScikit-learn\uff08sklearn\uff09\u4e0ePyTorch\/Tenso   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[59],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9418"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9418"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9418\/revisions"}],"predecessor-version":[{"id":9419,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9418\/revisions\/9419"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9418"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}