11 GradientBoostingClassifier
In [1]:
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y = True)In [2]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)In [3]:
from sklearn.ensemble import GradientBoostingClassifier
gboost = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=1, random_state=0)
gboost.fit(X_train, y_train)
y_pred = gboost.predict(X_test)In [4]:
from sklearn.metrics import classification_report, confusion_matrix
print("Matrice di confusione:")
print(confusion_matrix(y_test,y_pred))
print("\nClassification Report:")
print(classification_report(y_test,y_pred))Matrice di confusione:
[[13 0 0]
[ 0 6 2]
[ 0 2 15]]
Classification Report:
precision recall f1-score support
0 1.00 1.00 1.00 13
1 0.75 0.75 0.75 8
2 0.88 0.88 0.88 17
accuracy 0.89 38
macro avg 0.88 0.88 0.88 38
weighted avg 0.89 0.89 0.89 38