Suite à une analyse approfondie avec des modèles supplémentaires, voici les résultats pour la prédiction du diabète. Nous avons testé plusieurs modèles notamment XGBoost et Gradient Boosting pour améliorer nos performances.
Identique à la précédente analyse :
StandardScaler
.# Code de prétraitement
X = df.drop('Outcome', axis=1)
y = df['Outcome']
# Remplacement des zéros par NaN (sauf pour 'Pregnancies')
zero_columns = X.columns[~X.columns.isin(['Pregnancies'])]
X[zero_columns] = X[zero_columns].replace(0, np.nan)
X = X.fillna(X.mean())
# Normalisation
scaler = StandardScaler()
X = scaler.fit_transform(X)
# Division des données
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
model = LogisticRegression(max_iter=1000)
param_grid = {
'C': [0.01, 0.1, 1, 10, 100],
'penalty': ['l1', 'l2'],
'solver': ['liblinear', 'saga']
}
model_GSCV = GridSearchCV(model, param_grid, cv=5, scoring='accuracy', n_jobs=-1)
model_GSCV.fit(X_train, y_train)
best_model = model_GSCV.best_estimator_
Meilleurs paramètres :
n_estimators
: 50max_depth
: 10min_samples_split
: 10min_samples_leaf
: 4class_weight
: Nonefrom sklearn.ensemble import RandomForestClassifier
rf_param_grid = {
'n_estimators': [50, 100, 200],
'max_depth': [5, 10, 20, None],
'min_samples_split': [2, 5, 10],
'min_samples_leaf': [1, 2, 4],
'class_weight': ['balanced', None]
}
rf_model = RandomForestClassifier(random_state=42)
rf_grid_search = GridSearchCV(rf_model, rf_param_grid, cv=5, scoring='accuracy', n_jobs=-1)
rf_grid_search.fit(X_train, y_train)
best_rf = rf_grid_search.best_estimator_
rf_y_pred = best_rf.predict(X_test)
Meilleurs paramètres :
C
: 1kernel
: rbfgamma
: scalefrom sklearn.svm import SVC
from sklearn.pipeline import Pipeline
svc_param_grid = {
'svc__C': [0.1, 1, 10, 100],
'svc__kernel': ['linear', 'rbf', 'poly'],
'svc__gamma': ['scale', 'auto']
}
svc_pipeline = Pipeline([
('scaler', StandardScaler()),
('svc', SVC(probability=True, random_state=42))
])
svc_grid_search = GridSearchCV(svc_pipeline, svc_param_grid, cv=5, scoring='accuracy', n_jobs=-1)
svc_grid_search.fit(X_train, y_train)
best_svc = svc_grid_search.best_estimator_
svc_y_pred = best_svc.predict(X_test)
from sklearn.ensemble import VotingClassifier
logreg = LogisticRegression(C=10, penalty='l1', solver='liblinear', max_iter=1000, random_state=42)
rf = RandomForestClassifier(n_estimators=50, max_depth=10, min_samples_leaf=4, min_samples_split=10, random_state=42)
svc = SVC(C=1, kernel='rbf', gamma='scale', probability=True, random_state=42)
voting_clf = VotingClassifier(estimators=[
('Logistic Regression', logreg),
('Random Forest', rf),
('SVC', svc)
], voting='soft')
voting_clf.fit(X_train, y_train)
y_pred_voting = voting_clf.predict(X_test)
from xgboost import XGBClassifier
xgb_model = XGBClassifier(n_estimators=100, learning_rate=0.1, max_depth=5, random_state=42)
xgb_model.fit(X_train, y_train)
y_pred_xgb = xgb_model.predict(X_test)
La Régression Logistique Optimisée offre les meilleures performances en termes d'exactitude, avec 77.9%, suivie de près par les modèles Random Forest et Voting Classifier à 76.0%. Cependant, chaque modèle présente des avantages spécifiques selon les métriques. Pour aller plus loin, voici quelques pistes d'amélioration:
Kaggle Notebook Link : https://www.kaggle.com/code/khaledkhaouani/different-models-scores-on-diabetes-prediction || Auteur : Anwar, Fondateur d'InfiniTech || Linkedin : Khaled Khaouani
Vous avez des questions, des projets ou souhaitez simplement en savoir plus ? N'hésitez pas à nous contacter !