This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Obtention des centres de cluster et des labels | |
| centers = kmeans.cluster_centers_ | |
| labels = kmeans.labels_ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Application de l'algorithme de K-Means | |
| kmeans = KMeans(n_clusters=4) | |
| kmeans.fit(X) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Visualisation des données | |
| plt.scatter(X[:, 0], X[:, 1], s=50) | |
| plt.title("Données non supervisées") | |
| plt.show() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Génération de données synthétiques | |
| X, y = make_blobs(n_samples=300, centers=4, random_state=42) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Importation des bibliothèques nécessaires | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from sklearn.cluster import KMeans | |
| from sklearn.datasets import make_blobs | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Étape 7 : Visualisation des résultats avec un graphique | |
| plt.scatter(X_test, y_test, color='black', label='Données réelles') | |
| plt.plot(X_test, predictions, color='blue', linewidth=3, label='Régression linéaire') | |
| plt.xlabel('Heures de révision') | |
| plt.ylabel('Notes d\'examen') | |
| plt.legend() | |
| plt.show() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Étape 6 : Évaluation des performances du modèle | |
| mse = mean_squared_error(y_test, predictions) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Étape 5 : Prédictions sur l'ensemble de test | |
| predictions = modele.predict(X_test) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Étape 4 : Création et entraînement du modèle de régression linéaire | |
| modele = LinearRegression() | |
| modele.fit(X_train, y_train) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Étape 3 : Division des données en ensembles d'entraînement et de test | |
| X_train, X_test, y_train, y_test = train_test_split(heures_de_revision, notes_examen, test_size=0.2, random_state=42) |