超参数和模型参数
- 超参数︰在算法运行前需要决定的参数
- 模型参数︰算法过程中学习的参数
如何寻找好的超参数
- 领域知识
- 经验数值
- 实验搜索
寻找最好的k
```python best_score = 0.0 best_k = -1 for k in range(1, 11): knn_clf = KNeighborsClassifier(n_neighbors=k) knn_clf.fit(X_train, y_train) score = knn_clf.score(X_test, y_test) if score > best_score:best_k = k
best_score = score
print(“best_k =”, best_k) # best_k = 4 print(“best_score =”, best_score) # best_score = 0.991666666667 ```