【问题标题】:Hypermarameters optimization in Gaussian Process in scikitlearnscikit learn中高斯过程中的超参数优化
【发布时间】:2020-08-16 10:21:44
【问题描述】:

在 scikit-learn 的拟合过程中,Gaussian Process Regresor 中的超参数是否进行了优化?

在页面中

https://scikit-learn.org/stable/modules/gaussian_process.html

据说:

“在 GaussianProcessRegressor 拟合期间,通过基于传递的优化器最大化对数边际似然 (LML),对内核的超参数进行优化”

那么,是不是就不需要,比如用grid_arch来优化呢?

【问题讨论】:

    标签: scikit-learn hyperparameters


    【解决方案1】:

    超参数是您需要指定的东西,通常,最好的方法是在管道(一系列步骤)中尝试许多超参数并获得最佳参数。这是一个仅针对 k-means 尝试不同超参数的示例,您可以在其中提供超参数列表(K-Means 的 n_neighbors),以便查看哪些最有效!希望对你有帮助!

    neighbors = np.arange(1, 9)
    train_accuracy = np.empty(len(neighbors))
    test_accuracy = np.empty(len(neighbors))
    
    # Loop over different values of k
    for i, k in enumerate(neighbors):
        # Setup a k-NN Classifier with k neighbors: knn
        knn = KNeighborsClassifier(n_neighbors= k)
    
      # Fit the classifier to the training data
        knn.fit(X_train,y_train)
    
      #Compute accuracy on the training set
       train_accuracy[i] = knn.score(X_train, y_train)
    
       knn.predict(X_test)
    
      #Compute accuracy on the testing set
       test_accuracy[i] = knn.score(X_test, y_test)
    
    # Generate plot
    plt.title('k-NN: Varying Number of Neighbors')
    plt.plot(neighbors, test_accuracy, label = 'Testing Accuracy')
    plt.plot(neighbors, train_accuracy, label = 'Training Accuracy')
    plt.legend()
    plt.xlabel('Number of Neighbors')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-30
      • 2016-04-15
      • 2020-02-24
      • 2018-10-15
      • 2020-03-11
      • 2020-11-11
      • 2019-09-15
      相关资源
      最近更新 更多