Ajuste de Hiperparâmetros em Python
Alex Scriven
Data Scientist
Hiperparâmetros:

Crie um estimador simples de Random Forest e imprima-o:
rf_clf = RandomForestClassifier() print(rf_clf)RandomForestClassifier(n_estimators='warn', criterion='gini', max_depth=None, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, n_jobs=None, oob_score=False, random_state=None, verbose=0,bootstrap=True, class_weight=None, warm_start=False)
Mais info: http://scikit-learn.org
Veja o parâmetro n_estimators.
Tipo de dado e valor padrão:
n_estimators : integer, optional (default=10)
Definição:
The number of trees in the forest.
Defina alguns hiperparâmetros na criação do estimador:
rf_clf = RandomForestClassifier(n_estimators=100, criterion='entropy')
print(rf_clf)
RandomForestClassifier(n_estimators=100, criterion='entropy',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_jobs=None,
oob_score=False, random_state=None, verbose=0,bootstrap=True,
class_weight=None, warm_start=False)
Encontre os hiperparâmetros de uma Regressão Logística:
log_reg_clf = LogisticRegression()print(log_reg_clf) LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', random_state=None, solver='warn', tol=0.0001, verbose=0, warm_start=False)
Há menos hiperparâmetros para ajustar neste algoritmo!
Alguns hiperparâmetros são mais importantes que outros.
Alguns não ajudam no desempenho do modelo:
Para o classificador Random Forest:
n_jobsrandom_state verboseNem todo hiperparâmetro faz sentido para "treinar"
Alguns hiperparâmetros importantes:
n_estimators (valor alto)max_features (teste valores diferentes)max_depth e min_sample_leaf (importantes para overfitting)criterionLembre: isto é só um guia
Alguns recursos para aprender isso:
Ajuste de Hiperparâmetros em Python