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
| public partial class Utilisateur | |
| { | |
| [Key] | |
| [Column("UtilisateurID")] | |
| public int UtilisateurId { get; set; } | |
| [StringLength(100)] | |
| [Unicode(false)] | |
| public string? Nom { get; set; } |
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
| # Exemple d'utilisation du modèle entraîné pour prédire une nouvelle opinion | |
| new_text = ["je ne le recommande pas du tout !"] | |
| new_text_transformed = vectorizer.transform(new_text) | |
| prediction = classifier.predict(new_text_transformed) | |
| print("Prédiction pour la nouvelle opinion :", prediction[0]) |
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
| # Afficher les résultats | |
| print("Précision du modèle :", accuracy) |
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
| # Prédiction et évaluation | |
| predictions = classifier.predict(X_test) | |
| accuracy = metrics.accuracy_score(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
| # Entraînement du modèle | |
| classifier = MultinomialNB() | |
| classifier.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
| # Division des données en ensembles d'entraînement et de test | |
| X_train, X_test, y_train, y_test = ( | |
| train_test_split(X, labels, test_size=0.2, 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
| # Création des caractéristiques (features) | |
| texts, labels = zip(*data) | |
| vectorizer = CountVectorizer() | |
| X = vectorizer.fit_transform(texts) |
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
| # Préparation des données | |
| data = [ | |
| ("J'adore ce produit, il est fantastique !", "positif"), | |
| ("Je ne recommande pas ce produit, il est mauvais.", "négatif"), | |
| ("Ce produit est tout simplement inefficace.", "négatif"), | |
| ("C'est un excellent produit", "positif"), | |
| # Ajoutez autant d'exemples que nécessaire avec leurs étiquettes correspondantes | |
| ] |
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 | |
| from sklearn.feature_extraction.text import CountVectorizer | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.naive_bayes import MultinomialNB | |
| from sklearn import metrics |
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 résultats | |
| plt.scatter(X[:, 0], X[:, 1], c=labels, s=50, cmap='viridis') | |
| plt.scatter(centers[:, 0], centers[:, 1], c='red', s=200, marker='X') | |
| plt.title("Résultats du clustering K-Means") | |
| plt.show() |
NewerOlder