Scikit-learn提供了多種方法來(lái)實(shí)現(xiàn)模型選擇,其中包括交叉驗(yàn)證、網(wǎng)格搜索和隨機(jī)搜索等技術(shù)。以下是一些常用的方法:
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5)
from sklearn.model_selection import GridSearchCV
param_grid = {'param1': [val1, val2], 'param2': [val3, val4]}
grid_search = GridSearchCV(model, param_grid, cv=5)
grid_search.fit(X, y)
from sklearn.model_selection import RandomizedSearchCV
param_dist = {'param1': uniform(low=0, high=1), 'param2': randint(low=1, high=10)}
random_search = RandomizedSearchCV(model, param_dist, cv=5)
random_search.fit(X, y)
通過(guò)這些方法,可以幫助選擇最佳的模型參數(shù)組合,并提高模型的性能和泛化能力。