0
respostas

[ Desafio]: hora da prática

dados['diabetes'].value_counts(normalize = True)

from imblearn.pipeline import Pipeline as imbpipeline
from imblearn.over_sampling import SMOTE

dtc = DecisionTreeClassifier(max_depth = 3)
pipeline = imbpipeline([('oversample', SMOTE()), ('arvore', dtc)])
skf = StratifiedKFold(n_splits = 10, shuffle = True, random_state = 5)
resultado_dtc = cross_val_score(pipeline, X, y, cv = skf, scoring = 'f1')
print(f'F1 (Decision Tree):{resultado_dtc.mean()}')

rf = RandomForestClassifier(max_depth = 2)
pipeline = imbpipeline([('oversample', SMOTE()), ('random_forest', rf)])
skf = StratifiedKFold(n_splits = 10, shuffle = True, random_state = 5)
resultado_rf = cross_val_score(pipeline, X, y, cv = skf, scoring = 'f1')
print(f'F1 (Random Forest):{resultado_rf.mean()}') 

from imblearn.under_sampling import NearMiss
from imblearn.pipeline import Pipeline as imbpipeline

dtc = DecisionTreeClassifier(max_depth = 3)
pipeline = imbpipeline([('undersample', NearMiss(version = 3)), ('arvore', dtc)])
skf = StratifiedKFold(n_splits = 10, shuffle = True, random_state = 5)
resultado_dtc = cross_val_score(pipeline, X, y, cv = skf, scoring = 'f1')
print(f'F1 (Decision Tree):{resultado_dtc.mean()}') 

rf = RandomForestClassifier(max_depth = 2)
pipeline = imbpipeline([('undersample', NearMiss(version = 3)), ('random_forest', rf)])
skf = StratifiedKFold(n_splits = 10, shuffle = True, random_state = 5)
resultado_rf = cross_val_score(pipeline, X, y, cv = skf, scoring = 'f1')
print(f'F1 (Random Forest):{resultado_rf.mean()}')

undersample = NearMiss(version = 3)
X_balanceado, y_balanceado = undersample.fit_resample(X, y)

modelo = RandomForestClassifier(max_depth = 2)
modelo.fit(X_balanceado, y_balanceado)
y_previsto = modelo.predict(X_teste)

print(classification_report(y_teste, y_previsto))
ConfusionMatrixDisplay.from_predictions(y_teste, y_previsto);

Matricule-se agora e aproveite até 50% OFF

O maior desconto do ano para você evoluir com a maior escola de tecnologia

QUERO APROVEITAR