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
| import regex as re | |
| texte = "Drôle de texte" | |
| chaine_a_retirer = "x" | |
| nouveau_texte = re.sub(chaine_a_retirer, "", texte) | |
| # nouveau_texte est à présent la chaîne de caractères "Drôle de tete". |
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
| df[COLUMN_NAME] = values | |
| # où COLUMN_NAME est le nom de la colonne à rajouter | |
| # et values sont les valeurs à affecter. | |
| # values peut être un numpy array par exemple. |
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
| from torch.utils.data import Dataset | |
| class CustomDataset(Dataset): | |
| def __init__(self, X, Y): | |
| self.X = X | |
| self.Y = Y | |
| def __len__(self): | |
| return len(self.Y) |
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
| import torch.nn as nn | |
| class CustomModel(nn.Module): | |
| def __init__(self): | |
| super(CustomModel, self).__init__() | |
| # c'est ici que vous pouvez définir les couches du réseau | |
| # que vous utilsierez ensuite dans le forward. | |
| def forward(self, x): | |
| # Ici vous appliquez les couches de votre modèle à l'entrée 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
| x = x.toarray() | |
| # avec x une matrice csr que vous avez définie au préalable. |
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
| import torch | |
| x = torch.rand(1) | |
| # génère un tenseur de dimension 1 et dont la valeur est choisie uniformément sur [0, 1[. |
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
| import torch | |
| x_squared = torch.square(x) # où x est un tenseur défini au préalable. |
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
| df = df.drop(["pays", "ville"], axis=1) | |
| # La ligne ci-dessus supprime les colonnes "pays" et "ville" d'une dataframe df qui contiendrait de telles colonnes. | |
| # Modifiez la liste passée en argument de drop pour supprimer les colonnes que vous voulez de votre dataframe. |
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
| for column in df: | |
| # faire quelque chose. |
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
| columns = list(df.columns.values) | |
| # où df est une dataframe définie au préalable. |