Aún no tienes acceso a esta clase

Crea una cuenta y continúa viendo este curso

# Implementación de Boosting

24/37
Recursos

Aportes 5

Preguntas 3

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.

Para este método de ensamble, jugue un poco con los estimators:

``````X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.35)

estimators = range(10, 200, 10)
total_accuracy = []
for i in estimators:
boost_pred = boost.predict(X_test)

total_accuracy.append(accuracy_score(y_test, boost_pred))

plt.plot(estimators, total_accuracy)
plt.xlabel('Estimators')
plt.ylabel('Accuracy')
plt.show()
plt.savefig('Boost.png')

print(np.array(total_accuracy).max())

``````

Accuracy = 0.9749303621169917

Configurando el boosting de esta manera:

``````boosting = GradientBoostingClassifier(loss='exponential',learning_rate=0.15, n_estimators=100, max_depth=5).fit(x_train, y_train)
``````

Obtuve un score de:
0.9888579387186629

Para determinar el mejor n_estimator

``````estimators = range(10, 300, 10)
total_accuracy = []
best_result = {'result' : 0, 'n_estimator': 1}

for i in estimators:
boost_pred = boost.predict(X_test)
new_accuracy = accuracy_score(boost_pred, y_test)
total_accuracy.append(new_accuracy)
if new_accuracy > best_result['result']:
best_result['result'] = new_accuracy
best_result['n_estimator'] = i

print(best_result)

``````

Les adjunto mi version del codigo:

``````import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.metrics import  accuracy_score

if __name__ == "__main__":

path = './Boosting/data/heart.csv'

print('')
print(dataset['target'].describe())

x = dataset.drop(['target'], axis=1, inplace=False)
y = dataset['target']

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.35, random_state=42)

boost_pred = boost.predict(x_test)

print('')
#print('Accuracy GBC:', accuracy_score(y_test, boost_pred)) # este esta bien.
print('Accuracy GBC:', accuracy_score(boost_pred, y_test)) # este me parece que esta mal.
``````

Donde el output es el siguiente:

Accuracy GBC: `0.935933147632312`

KNeighborsClassifier 0.711038961038961

BaggingClassifier 0.7727272727272727

RanfomForestClassifier: 1.0