'sklearn'에 해당되는 글 2건

  1. 2022.05.30 :: [python] sklearn RandomizedSearchCV
  2. 2020.02.29 :: [Text 분석] Scikit-Learn의 문서 전처리 기능
Python 2022. 5. 30. 11:50

GridSearch와 동일한 방식으로 사용하지만, 모든 조합을 시도하지 않고 각 반복마다 임의의 값만 대입해 지정한 횟수만큼 평가

 

import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV

X = []
Y = []

xtrain, xtest, ytrain, ytest = train_test_split(X,Y,random_state=1234)
rf = RandomForestClassifier()

n_estimators = [int(x) for x in np.linspace(start = 200, stop = 2000, num = 10)]
max_features = ['auto', 'sqrt']
max_depth = [int(x) for x in np.linspace(10, 110, num = 11)]
max_depth.append(None)
min_samples_split = [2, 5, 10]
min_samples_leaf = [1, 2, 4]
bootstrap = [True, False]

random_grid = {'n_estimators': n_estimators,
               'max_features': max_features,
               'max_depth': max_depth,
               'min_samples_split': min_samples_split,
               'min_samples_leaf': min_samples_leaf,
               'bootstrap': bootstrap}
print(random_grid)

rf_random = RandomizedSearchCV(estimator = rf, param_distributions = random_grid, n_iter = 100, cv = 3, verbose=2, random_state=42, n_jobs = -1)
# Fit the random search model
rf_random.fit(xtrain,ytrain)

best_random = rf_random.best_estimator_

best_random.score(xtest,ytest)
posted by 초코렛과자
:
Python 2020. 2. 29. 21:20

https://datascienceschool.net/view-notebook/3e7aadbf88ed4f0d87a76f9ddc925d69/

 

Data Science School

Data Science School is an open space!

datascienceschool.net

 

 

 

posted by 초코렛과자
: