Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
machinelearningparkinson
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tebboune Amel
machinelearningparkinson
Commits
c7ccb456
Commit
c7ccb456
authored
1 month ago
by
Mimoun Bisontin
Browse files
Options
Downloads
Patches
Plain Diff
Update file remplissageoff.ipynb
parent
9d6021de
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
preprocess/remplissageoff.ipynb
+50
-22
50 additions, 22 deletions
preprocess/remplissageoff.ipynb
with
50 additions
and
22 deletions
preprocess/remplissageoff.ipynb
+
50
−
22
View file @
c7ccb456
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
data = pd.read_csv("data_avec_gene.csv")
print(data.head())
# Prédit la variable "off" sans utiliser la donnée "on"
# data_known : lignes pour lesquelles "off" est renseigné
# data_missing : lignes pour lesquelles "off" est manquant
data_known = data[data["off"].notnull()].copy()
data_missing = data[data["off"].isnull()].copy()
features = data.columns.drop(["on", "off"])
print("Variables explicatives utilisées :", features.tolist())
# Préparation des ensembles d'entraînement
X = data_known[features]
y = data_known["off"]
# Division en ensemble d'entraînement et de test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
#J'utilise un RandomForestRegressor, choix à discuter
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# On test un peu le model
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f"Mean Squared Error sur l'ensemble de test : {mse:.3f}")
# Validation croisée
cv_scores = cross_val_score(model, X, y, cv=5, scoring='neg_mean_squared_error')
print("CV MSE scores :", -cv_scores)
print("CV MSE moyen :", -cv_scores.mean())
# Prédiction des valeurs manquantes de "off"
if not data_missing.empty:
X_missing = data_missing[features]
data.loc[data_missing.index, "off_pred"] = model.predict(X_missing)
print("Prédictions effectuées pour les données manquantes.")
# Enregistrement du jeu de données avec les prédictions dans un nouveau fichier CSV
data.to_csv("data_with_predictions.csv", index=False)
print("Les données avec les prédictions ont été enregistrées dans 'data_with_predictions.csv'.")
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment