mirror of
https://github.com/Ladebeze66/ft_linear_regression.git
synced 2025-12-15 13:46:48 +01:00
gui
This commit is contained in:
parent
c8f4ee3bbb
commit
81b0118bd3
25
data/data_normalized.csv
Normal file
25
data/data_normalized.csv
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
km,price,km_norm,price_norm
|
||||||
|
240000,3650,1.0,0.0
|
||||||
|
139800,3800,0.5384636643774096,0.032327586206896554
|
||||||
|
150500,4400,0.5877494806564687,0.16163793103448276
|
||||||
|
185530,4450,0.7491029520822106,0.1724137931034483
|
||||||
|
176000,5250,0.7052063325364692,0.3448275862068966
|
||||||
|
114800,5350,0.4233098880244679,0.36637931034482757
|
||||||
|
166800,5800,0.6628297428385866,0.46336206896551724
|
||||||
|
89000,5990,0.30447119082823204,0.5043103448275862
|
||||||
|
144500,5999,0.5601125743317626,0.50625
|
||||||
|
84000,6200,0.2814404355576437,0.5495689655172413
|
||||||
|
82029,6390,0.27236171182997776,0.5905172413793104
|
||||||
|
63060,6390,0.18498763248441968,0.5905172413793104
|
||||||
|
74000,6600,0.23537892501646698,0.6357758620689655
|
||||||
|
97500,6800,0.3436234747882322,0.6788793103448276
|
||||||
|
67000,6800,0.2031358676376433,0.6788793103448276
|
||||||
|
76025,6900,0.24470638090105526,0.7004310344827587
|
||||||
|
48235,6900,0.11670144310712526,0.7004310344827587
|
||||||
|
93000,6990,0.32289579504470267,0.7198275862068966
|
||||||
|
60949,7490,0.1752640476091773,0.8275862068965517
|
||||||
|
65674,7555,0.1970281113398833,0.8415948275862069
|
||||||
|
54000,7990,0.1432559039341136,0.9353448275862069
|
||||||
|
68500,7990,0.2100450942188198,0.9353448275862069
|
||||||
|
22899,7990,0.0,0.9353448275862069
|
||||||
|
61789,8290,0.17913321449463615,1.0
|
||||||
|
31
main.py
31
main.py
@ -5,33 +5,20 @@ import os
|
|||||||
sys.path.append(os.path.abspath("src"))
|
sys.path.append(os.path.abspath("src"))
|
||||||
|
|
||||||
from src.training_model import train_model
|
from src.training_model import train_model
|
||||||
from src.prediction import predict_price
|
from src.prediction import predict_price # ✅ Peut maintenant être importé dès le début
|
||||||
|
from src.gui import show_gui # ✅ Import propre et structuré
|
||||||
|
|
||||||
# Interface principale en console
|
|
||||||
def main():
|
def main():
|
||||||
print(" Bienvenue dans le modèle de prédiction de prix de voiture !")
|
print("📌 Bienvenue dans le modèle de prédiction de prix de voiture !")
|
||||||
print(" Le modèle va être entraîné...")
|
print("🔄 Le modèle va être entraîné...")
|
||||||
|
|
||||||
# Entraîner le modèle
|
# Entraîner le modèle
|
||||||
train_model()
|
train_model()
|
||||||
|
print("✅ Modèle entraîné avec succès !")
|
||||||
|
|
||||||
while True:
|
# Lancer l'interface graphique après l'entraînement
|
||||||
try:
|
print("🖥️ Lancement de l'interface graphique...")
|
||||||
# Demander un kilométrage
|
show_gui(predict_price)
|
||||||
km = float(input("\nEntrez un kilométrage (ou tapez 'exit' pour quitter) : "))
|
|
||||||
|
|
||||||
# Prédire le prix
|
|
||||||
price = predict_price(km)
|
|
||||||
print(f"Prix estimé : {price:.2f} €")
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
print("Veuillez entrer un nombre valide ou 'exit' pour quitter.")
|
|
||||||
|
|
||||||
# Demander si l'utilisateur veut continuer
|
|
||||||
continuer = input("Voulez-vous faire une autre estimation ? (o/n) : ").strip().lower()
|
|
||||||
if continuer != "o":
|
|
||||||
print("Merci d'avoir utilisé le modèle de prédiction ! À bientôt !")
|
|
||||||
break
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -13,6 +13,7 @@ def load_and_process_data(file_path):
|
|||||||
df["km_norm"] = (df["km"] - km_min) / (km_max - km_min)
|
df["km_norm"] = (df["km"] - km_min) / (km_max - km_min)
|
||||||
df["price_norm"] = (df["price"] - price_min) / (price_max - price_min)
|
df["price_norm"] = (df["price"] - price_min) / (price_max - price_min)
|
||||||
|
|
||||||
|
print("Normalisation en cours...")
|
||||||
df.to_csv("data/data_normalized.csv", index=False)
|
df.to_csv("data/data_normalized.csv", index=False)
|
||||||
print("Données nettoyées et normalisées suvegardées dans 'data/data_normalized.csv' !")
|
print("Données nettoyées et normalisées suvegardées dans 'data/data_normalized.csv' !")
|
||||||
plot_raw_data(df) # Affichage des données normalisées
|
plot_raw_data(df) # Affichage des données normalisées
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from src.cost_function import compute_cost
|
from cost_function import compute_cost
|
||||||
|
|
||||||
def gradient_descent(X, y, theta_0, theta_1, learning_rate, iterations):
|
def gradient_descent(X, y, theta_0, theta_1, learning_rate, iterations):
|
||||||
"""Applique la descente de gradient et retourne les paramètres optimisés."""
|
"""Applique la descente de gradient et retourne les paramètres optimisés."""
|
||||||
|
|||||||
36
src/gui.py
Normal file
36
src/gui.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
def show_gui(predict_price):
|
||||||
|
"""Affiche l'interface graphique Tkinter pour entrer un kilométrage et voir le prix estimé."""
|
||||||
|
|
||||||
|
def estimate_price():
|
||||||
|
try:
|
||||||
|
km = float(entry_km.get()) # Récupère la valeur entrée
|
||||||
|
price = predict_price(km) # Prédiction du prix
|
||||||
|
label_result.config(text=f"Prix estimé : {price:.2f} €", fg="green") # Affiche le prix
|
||||||
|
except ValueError:
|
||||||
|
messagebox.showerror("Erreur", "Veuillez entrer un kilométrage valide.")
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.title("Estimation de prix de voiture")
|
||||||
|
|
||||||
|
frame = tk.Frame(root, padx=20, pady=20)
|
||||||
|
frame.pack()
|
||||||
|
|
||||||
|
label_title = tk.Label(frame, text="Estimation de prix de voiture", font=("Arial", 14, "bold"))
|
||||||
|
label_title.pack()
|
||||||
|
|
||||||
|
label_km = tk.Label(frame, text="Entrez le kilométrage :")
|
||||||
|
label_km.pack()
|
||||||
|
|
||||||
|
entry_km = tk.Entry(frame)
|
||||||
|
entry_km.pack()
|
||||||
|
|
||||||
|
btn_estimate = tk.Button(frame, text="Estimer le prix", command=estimate_price)
|
||||||
|
btn_estimate.pack()
|
||||||
|
|
||||||
|
label_result = tk.Label(frame, text="", font=("Arial", 12))
|
||||||
|
label_result.pack()
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from src.data_process import load_and_process_data
|
from data_process import load_and_process_data
|
||||||
from src.gradient_descent import gradient_descent
|
from gradient_descent import gradient_descent
|
||||||
from src.visualization import plot_cost_history, plot_regression_line
|
from visualization import plot_cost_history, plot_regression_line
|
||||||
|
|
||||||
def train_model():
|
def train_model():
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user