diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e43b0f988953ae3a84b00331d0ccf5f7d51cb3cf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/Cours/ML-01-Introduction_Apprentissage_automatique.pdf b/Cours/ML-01-Introduction_Apprentissage_automatique.pdf new file mode 100644 index 0000000000000000000000000000000000000000..127c2e90abda863d8b01613fb75314349820151c Binary files /dev/null and b/Cours/ML-01-Introduction_Apprentissage_automatique.pdf differ diff --git a/Cours/ML-02-Classification_non_supervisee.pdf b/Cours/ML-02-Classification_non_supervisee.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3666a7da6767f992ac46d50d40605bf3b5b69090 Binary files /dev/null and b/Cours/ML-02-Classification_non_supervisee.pdf differ diff --git a/README.md b/README.md index 7ab06d565e12766afa6880a7f293d59e4ae4752e..4d802d76a0b67046cd7781714d5ebd984c027746 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,6 @@ -# Machine_Learning +# Introduction au Machine Learning +Cours Enise - Centrale Lyon -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.ec-lyon.fr/edelland/machine_learning.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.ec-lyon.fr/edelland/machine_learning/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +Emmanuel Dellandréa - emmanuel.dellandrea@ec-lyon.fr \ No newline at end of file diff --git a/TD/TD1/ML-TD1.pdf b/TD/TD1/ML-TD1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..6f1f0e3e8bf34702a8eeef9711c6e9e98ebdb0c9 Binary files /dev/null and b/TD/TD1/ML-TD1.pdf differ diff --git a/TD/TD1/centres_mobiles.py b/TD/TD1/centres_mobiles.py new file mode 100644 index 0000000000000000000000000000000000000000..877db89cfc06f2370ddca7bebcd8ed2bc4e25b0d --- /dev/null +++ b/TD/TD1/centres_mobiles.py @@ -0,0 +1,200 @@ +import numpy as np + +def lecture_donnees(nom_fichier, delimiteur=','): + """ Lit le fichier contenant les données et renvoiee les matrices correspondant + + Parametres + ---------- + nom_fichier : nom du fichier contenant les données, organisées avec exemplaires en lignes et variables en colonne. La dernière colonne correspond à la classe de l'exemplaire + delimiteur : caratère délimitant les colonne dans le fichier ("," par défaut) + + Retour + ------- + X : matrice des données de dimension [N, nb_var] + Y : matrice contenant les valeurs de la variable cible de dimension [N, 1] + + avec N : nombre d'exemplaires et nb_var : nombre de variables prédictives + + """ + data = np.loadtxt(nom_fichier, delimiter=delimiteur) + + ####################### + ##### A compléter ##### + ####################### + + return X, Y + +def normalisation(data): + """ Normalise les données par un centrage-réduction des variables prédictives + + + Parametres + ---------- + data : matrice des données de dimension [N, nb_var] + + avec N : nombre d'éléments et nb_var : nombre de variables prédictives + + Retour + ------- + data_norm : matrice des données centrées-réduites de dimension [N, nb_var] + + """ + + ####################### + ##### A compléter ##### + ####################### + + return data_norm + +def initialisation_centres(data, k): + """ Initialise les centres en choisissant aléatoirement k points dans les données. + + Parametres + ---------- + data : matrice des données de dimension [N, nb_var] + k : nombre de centres désirés + + Retour + ------- + centres : matrice des données de dimension [k, nb_var] contenant les coordonnées des k centres + + avec N : nombre d'exemplaires et nb_var : nombre de variables prédictives + + """ + + ####################### + ##### A compléter ##### + ####################### + + return centres + +def distance_euclidienne(v1, v2): + """ Calcul de la distance euclidienne entre 2 points. + + Parametres + ---------- + v1 et v2 : vecteurs de dimension [1, nb_var] + + Retour + ------- + dist : valeur scalaire correspondant à la distance euclidienne entre v1 et v2 + + avec nb_var : nombre de variables prédictives + + """ + + ####################### + ##### A compléter ##### + ####################### + + return dist + + +def affectation_partition(data, centres): + """ Définit une partition en assignant chaque point de données à la classe + dont le centre est le plus proche. + + Parametres + ---------- + data : matrice des données de dimension [N, nb_var] + centres k : matrice contenant les coordonnées des centres de dimension [k, nb_var] + + Retour + ------- + partition : matrice des données de dimension [N, 1] et contenant le code de la classe pour chaque exemplaire + + avec N : nombre d'exemplaires, nb_var : nombre de variables prédictives, k : nombre de classes + + """ + + ####################### + ##### A compléter ##### + ####################### + + return partition + +def maj_centres(data, partition, k): + """ Met à jour les centres en calculant la moyenne des points assignés à chaque classe. + + Parametres + ---------- + data : matrice des données de dimension [N, nb_var] + partition : matrice des données de dimension [N, 1] + k : nombre de centres + + Retour + ------- + centres : matrice des données de dimension [k, nb_var] contenant les coordonnées des k centres + + avec N : nombre d'exemplaires, nb_var : nombre de variables prédictives + + """ + + ####################### + ##### A compléter ##### + ####################### + + return nv_centres + +def centres_mobiles(data, k, nb_iters=100): + """ + Implémente l'algorithme k-means. + + :param data: Données d'entrée (numpy array). + :param k: Nombre de clusters. + :param max_iters: Nombre maximum d'itérations. + :return: Les centroids finaux et les labels des clusters. + """ + + """ Implémente l'algorithme centres mobiles. + + Parametres + ---------- + data : matrice des données de dimension [N, nb_var] + k : nombre de centres + nb_iters = nombres d'itérations pour la mise à jour de la partition + + Retour + ------- + centres : matrice des données de dimension [k, nb_var] contenant les coordonnées des k centres + partition : matrice des données de dimension [N, 1] et contenant le code de la classe pour chaque exemplaire + + avec N : nombre d'exemplaires, nb_var : nombre de variables prédictives + + """ + + ####################### + ##### A compléter ##### + ####################### + + return centres, partition + +# Programme principal +if __name__ == "__main__": + + print("Lecture des données ...") + + X, Y = lecture_donnees("iris.txt") + + # Affichage des 10 premiers exemples du dataset + print("Affichage des 10 premiers exemples du dataset : ") + for i in range(0, 10): + print(f"x = {X[i,:]}, y = {Y[i]}") + + print("Dimension des données : ") + print(X.shape) + + # Normalisation des données + X = normalisation(X) + + # Nombre de clusters + k = 3 + + # Exécution des centres mobiles + centres, partition = centres_mobiles(X, k) + + print("Centres finaux :") + print(centres) + + print("Partition :") + print(partition) diff --git a/TD/TD1/iris.txt b/TD/TD1/iris.txt new file mode 100644 index 0000000000000000000000000000000000000000..1de4bbac2d427f72603868801f7647f04cb281a1 --- /dev/null +++ b/TD/TD1/iris.txt @@ -0,0 +1,150 @@ +5.1,3.5,1.4,0.2,0 +4.9,3.0,1.4,0.2,0 +4.7,3.2,1.3,0.2,0 +4.6,3.1,1.5,0.2,0 +5.0,3.6,1.4,0.2,0 +5.4,3.9,1.7,0.4,0 +4.6,3.4,1.4,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