成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何爬升用于機器學習的測試集

人工智能 機器學習
在本教程中,您將發現如何爬升用于機器學習的測試集。完成本教程后,您將知道一下內容,一起來看看吧。

[[385223]]

 爬坡測試集是一種在不影響訓練集甚至開發預測模型的情況下,在機器學習競賽中實現良好或完美預測的方法。作為機器學習競賽的一種方法,這是理所當然的,大多數競賽平臺都對其施加了限制,以防止出現這種情況,這一點很重要。但是,爬坡測試集是機器學習從業人員在參加比賽時不小心做的事情。通過開發一個明確的實現來爬升測試集,它有助于更好地了解通過過度使用測試數據集來評估建模管道而過度擬合測試數據集的難易程度。

在本教程中,您將發現如何爬升用于機器學習的測試集。完成本教程后,您將知道:

  •  無需查看訓練數據集,就可以通過爬上測試集來做出完美的預測。
  •  如何為分類和回歸任務爬坡測試集。
  •  當我們過度使用測試集來評估建模管道時,我們暗中爬升了測試集。

教程概述

本教程分為五個部分。他們是:

  •  爬坡測試儀
  •  爬山算法
  •  如何進行爬山
  •  爬坡糖尿病分類數據集
  •  爬坡房屋回歸數據集

爬坡測試儀

像Kaggle上的機器學習比賽一樣,機器學習比賽提供了完整的訓練數據集以及測試集的輸入。給定比賽的目的是預測目標值,例如測試集的標簽或數值。針對隱藏的測試設置目標值評估解決方案,并進行適當評分。與測試集得分最高的參賽作品贏得了比賽。機器學習競賽的挑戰可以被定義為一個優化問題。傳統上,競賽參與者充當優化算法,探索導致不同組預測的不同建模管道,對預測進行評分,然后對管道進行更改以期望獲得更高的分數。此過程也可以直接用優化算法建模,無需查看訓練集就可以生成和評估候選預測。通常,這稱為爬山測試集,作為解決此問題的最簡單的優化算法之一就是爬山算法。盡管在實際的機器學習競賽中應該正確地爬升測試集,但是實施該方法以了解該方法的局限性和過度安裝測試集的危險可能是一個有趣的練習。此外,無需接觸訓練數據集就可以完美預測測試集的事實常常使很多初學者機器學習從業人員感到震驚。最重要的是,當我們反復評估不同的建模管道時,我們暗中爬升了測試集。風險是測試集的分數得到了提高,但代價是泛化誤差增加,即在更廣泛的問題上表現較差。進行機器學習競賽的人們都非常清楚這個問題,并且對預測評估施加了限制以應對該問題,例如將評估限制為每天一次或幾次,并在測試集的隱藏子集而不是整個測試集上報告分數。。有關更多信息,請參閱進一步閱讀部分中列出的論文。接下來,讓我們看看如何實施爬坡算法來優化測試集的預測。

爬山算法

爬山算法是一種非常簡單的優化算法。它涉及生成候選解決方案并進行評估。然后是逐步改進的起點,直到無法實現進一步的改進,或者我們用光了時間,資源或興趣。從現有候選解決方案中生成新的候選解決方案。通常,這涉及對候選解決方案進行單個更改,對其進行評估,并且如果候選解決方案與先前的當前解決方案一樣好或更好,則將該候選解決方案接受為新的“當前”解決方案。否則,將其丟棄。我們可能會認為只接受分數更高的候選人是一個好主意。對于許多簡單問題,這是一種合理的方法,盡管在更復雜的問題上,希望接受具有相同分數的不同候選者,以幫助搜索過程縮放要素空間中的平坦區域(高原)。當爬上測試集時,候選解決方案是預測列表。對于二進制分類任務,這是兩個類的0和1值的列表。對于回歸任務,這是目標變量范圍內的數字列表。對候選分類解決方案的修改將是選擇一個預測并將其從0翻轉為1或從1翻轉為0。對回歸進行候選解決方案的修改將是將高斯噪聲添加到列表中的一個值或替換一個值在列表中使用新值。解決方案的評分涉及計算評分指標,例如分類任務的分類準確性或回歸任務的平均絕對誤差。現在我們已經熟悉了算法,現在就來實現它。

如何進行爬山

我們將在綜合分類任務上開發爬坡算法。首先,我們創建一個包含許多輸入變量和5,000行示例的二進制分類任務。然后,我們可以將數據集分為訓練集和測試集。下面列出了完整的示例。 

  1. # example of a synthetic dataset.  
  2. from sklearn.datasets import make_classification  
  3. from sklearn.model_selection import train_test_split  
  4. # define dataset  
  5. X, y = make_classification(n_samples=5000n_features=20n_informative=15n_redundant=5random_state=1 
  6. print(X.shape, y.shape)  
  7. # split dataset 
  8. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1 
  9. print(X_train.shape, X_test.shape, y_train.shape, y_test.shape) 

運行示例首先報告創建的數據集的形狀,顯示5,000行和20個輸入變量。然后將數據集分為訓練集和測試集,其中約3,300個用于訓練,約1,600個用于測試。 

  1. (5000, 20) (5000,)  
  2. (3350, 20) (1650, 20) (3350,) (1650,)

現在我們可以開發一個登山者。首先,我們可以創建一個將加載的函數,或者在這種情況下,定義數據集。當我們要更改數據集時,可以稍后更新此功能。 

  1. # load or prepare the classification dataset  
  2. def load_dataset():  
  3.  return make_classification(n_samples=5000n_features=20n_informative=15n_redundant=5random_state=1

接下來,我們需要一個函數來評估候選解決方案,即預測列表。我們將使用分類精度,其中分數范圍在0(最壞的解決方案)到1(完美的預測集)之間。 

  1. # evaluate a set of predictions  
  2. def evaluate_predictions(y_test, yhat):  
  3.  return accuracy_score(y_test, yhat) 

接下來,我們需要一個函數來創建初始候選解決方案。這是0和1類標簽的預測列表,長度足以匹配測試集中的示例數,在這種情況下為1650。我們可以使用randint()函數生成0和1的隨機值。 

  1. # create a random set of predictions  
  2. def random_predictions(n_examples):  
  3.  return [randint(0, 1) for _ in range(n_examples)] 

接下來,我們需要一個函數來創建候選解決方案的修改版本。在這種情況下,這涉及在解決方案中選擇一個值并將其從0翻轉為1或從1翻轉為0。通常,我們會在爬坡期間對每個新的候選解決方案進行一次更改,但是我已經對該函數進行了參數化,因此您可以根據需要探索多個更改。 

  1. # modify the current set of predictions  
  2. def modify_predictions(current, n_changes=1):  
  3.  # copy current solution  
  4.  updated = current.copy()  
  5.  for i in range(n_changes):  
  6.   # select a point to change  
  7.   ix = randint(0, len(updated)-1)  
  8.   # flip the class label  
  9.   updated[ix] = 1 - updated[ix]  
  10.  return updated 

到現在為止還挺好。接下來,我們可以開發執行搜索的功能。首先,通過調用random_predictions()函數和隨后的validate_predictions()函數來創建和評估初始解決方案。然后,我們循環進行固定次數的迭代,并通過調用Modify_predictions()生成一個新的候選值,對其進行求值,如果分數與當前解決方案相同或更好,則將其替換。當我們完成預設的迭代次數(任意選擇)或達到理想分數時,該循環結束,在這種情況下,我們知道其精度為1.0(100%)。下面的函數hill_climb_testset()實現了此功能,將測試集作為輸入并返回在爬坡過程中發現的最佳預測集。 

  1. # run a hill climb for a set of predictions  
  2. def hill_climb_testset(X_test, y_test, max_iterations):  
  3.  scores = list()  
  4.  # generate the initial solution  
  5.  solution = random_predictions(X_test.shape[0])  
  6.  # evaluate the initial solution  
  7.  score = evaluate_predictions(y_test, solution)  
  8.  scores.append(score)  
  9.  # hill climb to a solution  
  10.  for i in range(max_iterations):  
  11.   # record scores  
  12.   scores.append(score)  
  13.   # stop once we achieve the best score  
  14.   if score == 1.0:  
  15.    break  
  16.   # generate new candidate  
  17.   candidate = modify_predictions(solution)  
  18.   # evaluate candidate  
  19.   value = evaluate_predictions(y_test, candidate)  
  20.   # check if it is as good or better  
  21.   if value >= score:  
  22.    solution, score = candidate, value  
  23.    print('>%d, score=%.3f' % (i, score))  
  24.  return solution, scores 

這里的所有都是它的。下面列出了爬坡測試裝置的完整示例。 

  1. # example of hill climbing the test set for a classification task  
  2. from random import randint  
  3. from sklearn.datasets import make_classification  
  4. from sklearn.model_selection import train_test_split  
  5. from sklearn.metrics import accuracy_score  
  6. from matplotlib import pyplot   
  7. # load or prepare the classification dataset  
  8. def load_dataset():  
  9.  return make_classification(n_samples=5000n_features=20n_informative=15n_redundant=5random_state=1 
  10. # evaluate a set of predictions  
  11. def evaluate_predictions(y_test, yhat): 
  12.  return accuracy_score(y_test, yhat)  
  13. # create a random set of predictions  
  14. def random_predictions(n_examples):  
  15.  return [randint(0, 1) for _ in range(n_examples)] 
  16.  # modify the current set of predictions  
  17. def modify_predictions(current, n_changes=1):  
  18.  # copy current solution  
  19.  updated = current.copy()  
  20.  for i in range(n_changes):  
  21.   # select a point to change  
  22.   ix = randint(0, len(updated)-1)  
  23.   # flip the class label  
  24.   updated[ix] = 1 - updated[ix] 
  25.   return updated  
  26. # run a hill climb for a set of predictions  
  27. def hill_climb_testset(X_test, y_test, max_iterations):  
  28.  scores = list()  
  29.  # generate the initial solution  
  30.  solution = random_predictions(X_test.shape[0])  
  31.  # evaluate the initial solution  
  32.  score = evaluate_predictions(y_test, solution)  
  33.  scores.append(score)  
  34.  # hill climb to a solution  
  35.  for i in range(max_iterations):  
  36.   # record scores  
  37.   scores.append(score)  
  38.   # stop once we achieve the best score  
  39.   if score == 1.0:  
  40.    break  
  41.   # generate new candidate  
  42.   candidate = modify_predictions(solution)  
  43.   # evaluate candidate  
  44.   value = evaluate_predictions(y_test, candidate) 
  45.    # check if it is as good or better  
  46.   if value >= score:  
  47.    solution, score = candidate, value  
  48.    print('>%d, score=%.3f' % (i, score))  
  49.  return solution, scores   
  50. # load the dataset  
  51. X, y = load_dataset()  
  52. print(X.shape, y.shape)  
  53. # split dataset into train and test sets  
  54. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1 
  55. print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)  
  56. # run hill climb 
  57. yhat, scores = hill_climb_testset(X_test, y_test, 20000)  
  58. # plot the scores vs iterations  
  59. pyplot.plot(scores) 
  60. pyplot.show() 

運行示例將使搜索進行20,000次迭代,或者如果達到理想的準確性,則停止搜索。注意:由于算法或評估程序的隨機性,或者數值精度的差異,您的結果可能會有所不同。考慮運行該示例幾次并比較平均結果。在這種情況下,我們在約12,900次迭代中找到了一組理想的測試集預測。回想一下,這是在不接觸訓練數據集且不通過查看測試集目標值進行欺騙的情況下實現的。相反,我們只是簡單地優化了一組數字。這里的教訓是,將測試管道用作爬山優化算法,對測試集重復建模管道的評估會做同樣的事情。解決方案將過度適合測試集。 

  1. ...  
  2. >8092, score=0.996  
  3. >8886, score=0.997  
  4. >9202, score=0.998  
  5. >9322, score=0.998  
  6. >9521, score=0.999  
  7. >11046, score=0.999  
  8. >12932, score=1.000 

還創建了優化進度圖。這有助于了解優化算法的更改(例如,在坡道上更改內容的選擇以及更改方式)如何影響搜索的收斂性。

爬坡糖尿病分類數據集

我們將使用糖尿病數據集作為探索爬坡測試集以解決分類問題的基礎。每條記錄都描述了女性的醫療細節,并且預測是未來五年內糖尿病的發作。

數據集詳細信息:pima-indians-diabetes.names數據集:pima-indians-diabetes.csv

數據集有八個輸入變量和768行數據;輸入變量均為數字,目標具有兩個類別標簽,例如 這是一個二進制分類任務。下面提供了數據集前五行的示例。 

  1. 6,148,72,35,0,33.6,0.627,50,1  
  2. 1,85,66,29,0,26.6,0.351,31,0  
  3. 8,183,64,0,0,23.3,0.672,32,1  
  4. 1,89,66,23,94,28.1,0.167,21,0  
  5. 0,137,40,35,168,43.1,2.288,33,1  
  6. ... 

我們可以使用Pandas直接加載數據集,如下所示。 

  1. # load or prepare the classification dataset  
  2. def load_dataset():  
  3.  url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.csv'  
  4.  df = read_csv(url, header=None 
  5.  data = df.values  
  6.  return data[:, :-1], data[:, -1] 

其余代碼保持不變。創建該文件是為了使您可以放入自己的二進制分類任務并進行嘗試。下面列出了完整的示例。 

  1. # example of hill climbing the test set for the diabetes dataset  
  2. from random import randint  
  3. from pandas import read_csv  
  4. from sklearn.model_selection import train_test_split  
  5. from sklearn.metrics import accuracy_score  
  6. from matplotlib import pyplot   
  7. # load or prepare the classification dataset  
  8. def load_dataset():  
  9.  url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.csv'  
  10.  df = read_csv(url, header=None 
  11.  data = df.values  
  12.  return data[:, :-1], data[:, -1]  
  13. # evaluate a set of predictions  
  14. def evaluate_predictions(y_test, yhat):  
  15.  return accuracy_score(y_test, yhat)  
  16. # create a random set of predictions  
  17. def random_predictions(n_examples):  
  18.  return [randint(0, 1) for _ in range(n_examples)]  
  19. # modify the current set of predictions  
  20. def modify_predictions(current, n_changes=1):  
  21.  # copy current solution  
  22.  updated = current.copy()  
  23.  for i in range(n_changes):  
  24.   # select a point to change  
  25.   ix = randint(0, len(updated)-1)  
  26.   # flip the class label  
  27.   updated[ix] = 1 - updated[ix]  
  28.  return updated  
  29. # run a hill climb for a set of predictions  
  30. def hill_climb_testset(X_test, y_test, max_iterations):  
  31.  scores = list()  
  32.  # generate the initial solution  
  33.  solution = random_predictions(X_test.shape[0])  
  34.  # evaluate the initial solution  
  35.  score = evaluate_predictions(y_test, solution)  
  36.  scores.append(score)  
  37.  # hill climb to a solution  
  38.  for i in range(max_iterations):  
  39.   # record scores  
  40.   scores.append(score)  
  41.   # stop once we achieve the best score  
  42.   if score == 1.0:  
  43.    break  
  44.   # generate new candidate  
  45.   candidate = modify_predictions(solution)  
  46.   # evaluate candidate 
  47.   value = evaluate_predictions(y_test, candidate)  
  48.   # check if it is as good or better  
  49.   if value >= score:  
  50.    solution, score = candidate, value  
  51.    print('>%d, score=%.3f' % (i, score))  
  52.  return solution, scores  
  53. # load the dataset  
  54. X, y = load_dataset()  
  55. print(X.shape, y.shape)  
  56. # split dataset into train and test sets  
  57. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1 
  58. print(X_train.shape, X_test.shape, y_train.shape, y_test.shape) 
  59. # run hill climb  
  60. yhat, scores = hill_climb_testset(X_test, y_test, 5000)  
  61. # plot the scores vs iterations  
  62. pyplot.plot(scores)  
  63. pyplot.show() 

運行示例將報告每次搜索過程中看到改進時的迭代次數和準確性。

在這種情況下,我們使用的迭代次數較少,因為要進行的預測較少,因此優化起來比較簡單。

注意:由于算法或評估程序的隨機性,或者數值精度的差異,您的結果可能會有所不同。考慮運行該示例幾次并比較平均結果。

在這種情況下,我們可以看到在大約1,500次迭代中達到了完美的精度。 

  1. ...  
  2. >617, score=0.961  
  3. >627, score=0.965  
  4. >650, score=0.969  
  5. >683, score=0.972  
  6. >743, score=0.976  
  7. >803, score=0.980  
  8. >817, score=0.984  
  9. >945, score=0.988  
  10. >1350, score=0.992  
  11. >1387, score=0.996  
  12. >1565, score=1.000 

還創建了搜索進度的折線圖,表明收斂迅速。

爬坡房屋回歸數據集

我們將使用住房數據集作為探索爬坡測試集回歸問題的基礎。住房數據集包含給定房屋及其附近地區詳細信息的數千美元房屋價格預測。

數據集詳細信息:housing.names數據集:housing.csv

這是一個回歸問題,這意味著我們正在預測一個數值。共有506個觀測值,其中包含13個輸入變量和一個輸出變量。下面列出了前五行的示例。 

  1. 0.00632,18.00,2.310,0,0.5380,6.5750,65.20,4.0900,1,296.0,15.30,396.90,4.98,24.00  
  2. 0.02731,0.00,7.070,0,0.4690,6.4210,78.90,4.9671,2,242.0,17.80,396.90,9.14,21.60  
  3. 0.02729,0.00,7.070,0,0.4690,7.1850,61.10,4.9671,2,242.0,17.80,392.83,4.03,34.70  
  4. 0.03237,0.00,2.180,0,0.4580,6.9980,45.80,6.0622,3,222.0,18.70,394.63,2.94,33.40  
  5. 0.06905,0.00,2.180,0,0.4580,7.1470,54.20,6.0622,3,222.0,18.70,396.90,5.33,36.20  
  6. ... 

首先,我們可以更新load_dataset()函數以加載住房數據集。作為加載數據集的一部分,我們將標準化目標值。由于我們可以將浮點值限制在0到1的范圍內,這將使爬坡的預測更加簡單。通常不需要這樣做,只是此處采用的簡化搜索算法的方法。 

  1. # load or prepare the classification dataset  
  2. def load_dataset():  
  3.  url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/housing.csv'  
  4.  df = read_csv(url, header=None 
  5.  data = df.values  
  6.  X, y = data[:, :-1], data[:, -1]  
  7.  # normalize the target  
  8.  scaler = MinMaxScaler()  
  9.  yy = y.reshape((len(y), 1))  
  10.  y = scaler.fit_transform(y)  
  11.  return X, y 

接下來,我們可以更新評分函數,以使用預期值和預測值之間的平均絕對誤差。 

  1. # evaluate a set of predictions  
  2. def evaluate_predictions(y_test, yhat):  
  3.  return mean_absolute_error(y_test, yhat) 

我們還必須將解決方案的表示形式從0和1標簽更新為介于0和1之間的浮點值。必須更改初始候選解的生成以創建隨機浮點列表。 

  1. # create a random set of predictions  
  2. def random_predictions(n_examples):  
  3.  return [random() for _ in range(n_examples)] 

在這種情況下,對解決方案所做的單個更改以創建新的候選解決方案,包括簡單地用新的隨機浮點數替換列表中的隨機選擇的預測。我選擇它是因為它很簡單。 

  1. # modify the current set of predictions  
  2. def modify_predictions(current, n_changes=1):  
  3.  # copy current solution  
  4.  updated = current.copy()  
  5.  for i in range(n_changes):  
  6.   # select a point to change  
  7.   ix = randint(0, len(updated)-1)  
  8.   # flip the class label  
  9.   updated[ix] = random()  
  10.  return updated 

更好的方法是將高斯噪聲添加到現有值,我將其作為擴展留給您。如果您嘗試過,請在下面的評論中告訴我。例如: 

  1. # add gaussian noise  
  2. updated[ix] += gauss(0, 0.1) 

最后,必須更新搜索。最佳值現在是錯誤0.0,如果發現錯誤,該錯誤將用于停止搜索。 

  1. # stop once we achieve the best score  
  2. if score == 0.0:  
  3.  break 

我們還需要將搜索從最大分數更改為現在最小分數。 

  1. # check if it is as good or better  
  2. if value <= score:  
  3.  solution, score = candidate, value 
  4.  print('>%d, score=%.3f' % (i, score)) 

下面列出了具有這兩個更改的更新的搜索功能。 

  1. # run a hill climb for a set of predictions  
  2. def hill_climb_testset(X_test, y_test, max_iterations):  
  3.  scores = list()  
  4.  # generate the initial solution  
  5.  solution = random_predictions(X_test.shape[0])  
  6.  # evaluate the initial solution  
  7.  score = evaluate_predictions(y_test, solution)  
  8.  print('>%.3f' % score)  
  9.  # hill climb to a solution  
  10.  for i in range(max_iterations):  
  11.   # record scores  
  12.   scores.append(score)  
  13.   # stop once we achieve the best score  
  14.   if score == 0.0:  
  15.    break  
  16.   # generate new candidate  
  17.   candidate = modify_predictions(solution)  
  18.   # evaluate candidate  
  19.   value = evaluate_predictions(y_test, candidate)  
  20.   # check if it is as good or better  
  21.   if value <= score:  
  22.    solution, score = candidate, value  
  23.    print('>%d, score=%.3f' % (i, score))  
  24.  return solution, scores 

結合在一起,下面列出了用于回歸任務的測試集爬坡的完整示例。 

  1. # example of hill climbing the test set for the housing dataset  
  2. from random import random  
  3. from random import randint  
  4. from pandas import read_csv  
  5. from sklearn.model_selection import train_test_split  
  6. from sklearn.metrics import mean_absolute_error  
  7. from sklearn.preprocessing import MinMaxScaler  
  8. from matplotlib import pyplot   
  9. # load or prepare the classification dataset 
  10. def load_dataset():  
  11.  url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/housing.csv'  
  12.  df = read_csv(url, header=None 
  13.  data = df.values  
  14.  X, y = data[:, :-1], data[:, -1]  
  15.  # normalize the target  
  16.  scaler = MinMaxScaler()  
  17.  yy = y.reshape((len(y), 1))  
  18.  y = scaler.fit_transform(y)  
  19.  return X, y   
  20. # evaluate a set of predictions  
  21. def evaluate_predictions(y_test, yhat):  
  22.  return mean_absolute_error(y_test, yhat)  
  23. # create a random set of predictions  
  24. def random_predictions(n_examples):  
  25.  return [random() for _ in range(n_examples)]  
  26. # modify the current set of predictions  
  27. def modify_predictions(current, n_changes=1):  
  28.  # copy current solution  
  29.  updated = current.copy()  
  30.  for i in range(n_changes):  
  31.   # select a point to change  
  32.   ix = randint(0, len(updated)-1)  
  33.   # flip the class label  
  34.   updated[ix] = random()  
  35.  return updated   
  36. # run a hill climb for a set of predictions  
  37. def hill_climb_testset(X_test, y_test, max_iterations):  
  38.  scores = list()  
  39.  # generate the initial solution  
  40.  solution = random_predictions(X_test.shape[0])  
  41.  # evaluate the initial solution  
  42.  score = evaluate_predictions(y_test, solution)  
  43.  print('>%.3f' % score)  
  44.  # hill climb to a solution  
  45.  for i in range(max_iterations):  
  46.   # record scores  
  47.   scores.append(score)  
  48.   # stop once we achieve the best score  
  49.   if score == 0.0:  
  50.    break  
  51.   # generate new candidate  
  52.   candidate = modify_predictions(solution)  
  53.   # evaluate candidate  
  54.   value = evaluate_predictions(y_test, candidate)  
  55.   # check if it is as good or better  
  56.   if value <= score:  
  57.    solution, score = candidate, value  
  58.    print('>%d, score=%.3f' % (i, score))  
  59.  return solution, scores  
  60. # load the dataset  
  61. X, y = load_dataset()  
  62. print(X.shape, y.shape)  
  63. # split dataset into train and test sets  
  64. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1 
  65. print(X_train.shape, X_test.shape, y_train.shape, y_test.shape) 
  66. # run hill climb 
  67. yhat, scores = hill_climb_testset(X_test, y_test, 100000)  
  68. # plot the scores vs iterations  
  69. pyplot.plot(scores)  
  70. pyplot.show() 

運行示例將在搜索過程中每次看到改進時報告迭代次數和MAE。

在這種情況下,我們將使用更多的迭代,因為要優化它是一個更復雜的問題。選擇的用于創建候選解決方案的方法也使它變慢了,也不太可能實現完美的誤差。實際上,我們不會實現完美的錯誤;相反,如果錯誤達到的值低于最小值(例如1e-7)或對目標域有意義的值,則最好停止操作。這也留給讀者作為練習。例如: 

  1. # stop once we achieve a good enough  
  2. if score <= 1e-7:  
  3.  break 

注意:由于算法或評估程序的隨機性,或者數值精度的差異,您的結果可能會有所不同。考慮運行該示例幾次并比較平均結果。

在這種情況下,我們可以看到在運行結束時實現了良好的錯誤。 

  1. >95991, score=0.001  
  2. >96011, score=0.001  
  3. >96295, score=0.001  
  4. >96366, score=0.001  
  5. >96585, score=0.001  
  6. >97575, score=0.001  
  7. >98828, score=0.001  
  8. >98947, score=0.001  
  9. >99712, score=0.001  
  10. >99913, score=0.001 

還創建了搜索進度的折線圖,顯示收斂速度很快,并且在大多數迭代中保持不變。

 

 

責任編輯:龐桂玉 來源: Python中文社區 (ID:python-china)
相關推薦

2021-03-12 11:00:14

機器學習人工智能爬坡測試

2022-09-19 15:37:51

人工智能機器學習大數據

2020-08-19 09:20:00

機器學習人工智能Python

2017-04-06 09:20:10

機器學習模型信用卡詐騙

2020-06-24 07:53:03

機器學習技術人工智能

2019-12-18 10:25:12

機器學習單元測試神經網絡

2020-04-27 09:52:03

預測銷售機器學習ML

2022-10-24 08:02:00

2020-06-10 07:46:39

機器學習預測性維護工業物聯網

2017-12-12 13:17:36

機器學習代碼單元測試

2024-07-10 14:25:20

2019-07-17 09:59:46

JavaScriptJava機器學習

2021-12-13 09:14:06

清單管理數據集

2019-06-19 09:13:29

機器學習中數據集深度學習

2021-09-16 15:41:59

機器學習數據科學算法

2017-11-03 12:57:06

機器學習文本數據Python

2018-09-15 23:23:04

Web開發機器學習軟件開發

2019-04-15 13:25:29

數據科學機器學習Gartner

2017-05-05 09:56:08

神經網絡模型繪畫

2023-12-21 17:05:46

機器學習MLOps人工智能
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩中文字幕 | 农村妇女毛片精品久久久 | 日韩精品在线一区 | 国产精品午夜电影 | 福利成人| 日本成人中文字幕 | 色婷婷精品国产一区二区三区 | 亚洲精品久久区二区三区蜜桃臀 | 国产7777 | 干干天天 | 国产区在线观看 | 亚洲视频一区二区三区四区 | 午夜伦4480yy私人影院 | 精品丝袜在线 | 一区二区三区久久久 | 亚洲欧美aⅴ | 蜜臀久久99精品久久久久久宅男 | 色爱av| 欧美一区 | 最新av中文字幕 | 免费成人在线网站 | 天天拍天天插 | 欧美黄视频 | 久久国产精品视频观看 | 一区二区三区四区视频 | 狠狠涩| 精品国偷自产在线 | 日韩免费一区 | 亚洲综合一区二区三区 | 欧美精品一二三区 | 国产精品特级毛片一区二区三区 | 涩涩鲁亚洲精品一区二区 | 成人国产精品一级毛片视频毛片 | 国产精品成人一区二区三区 | 国产成人免费 | 国产激情偷乱视频一区二区三区 | 日本人做爰大片免费观看一老师 | 波多野结衣电影一区 | 国产精品国产三级国产播12软件 | 日韩中文字幕一区 | 丝袜美腿一区二区三区 |