summaryrefslogtreecommitdiffstats
path: root/edit.py
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-11-30 23:14:55 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-11-30 23:14:55 +0530
commit3b3a6547649f75066f45ea2a7e1c46e34d2e26a9 (patch)
treefa1e228ab570d315ea5e8c3bf5361f1be7df8e4b /edit.py
parent54c94edb7a222c7c5585ee18648ce809e5d4ad0e (diff)
downloadautopredict-master.tar.gz
autopredict-master.tar.bz2
autopredict-master.zip
Added LSTM for neural networkingHEADmaster
Diffstat (limited to 'edit.py')
-rw-r--r--edit.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/edit.py b/edit.py
new file mode 100644
index 0000000..d2bf57a
--- /dev/null
+++ b/edit.py
@@ -0,0 +1,55 @@
+import joblib
+import pandas as pd
+
+# Load the models
+mileage_model = joblib.load('mileage_predictor.pkl')
+price_model = joblib.load('price_predictor.pkl')
+year_model = joblib.load('year_predictor.pkl')
+
+# Required columns
+REQUIRED_COLUMNS = [
+ 'Name', 'Manufacturer', 'Location', 'Year', 'Kilometers_Driven',
+ 'Fuel_Type', 'Transmission', 'Owner_Type', 'Engine CC', 'Power', 'Seats'
+]
+
+# Prepare input data for prediction
+def prepare_input(df):
+ # Select only necessary columns
+ df = df[REQUIRED_COLUMNS]
+
+ # Add 'Car_Age' and drop 'Year'
+ df['Car_Age'] = 2024 - df['Year']
+ df.drop(columns=['Year'], inplace=True)
+ return df
+
+# Make predictions
+def predict_from_csv(input_csv, output_csv):
+ # Load the input CSV file
+ data = pd.read_csv(input_csv)
+
+ # Ensure the required columns exist
+ if not all(col in data.columns for col in REQUIRED_COLUMNS):
+ raise ValueError(f"The input CSV must contain these columns: {REQUIRED_COLUMNS}")
+
+ # Prepare the input data
+ prepared_data = prepare_input(data.copy())
+
+ # Perform predictions
+ data['Predicted_Mileage'] = mileage_model.predict(prepared_data)
+ data['Predicted_Price'] = price_model.predict(prepared_data)
+ data['Predicted_Year'] = year_model.predict(prepared_data).astype(int)
+
+ # Format numeric predictions to two decimal places
+ data['Predicted_Mileage'] = data['Predicted_Mileage'].map(lambda x: round(x, 2))
+ data['Predicted_Price'] = data['Predicted_Price'].map(lambda x: round(x, 2))
+
+ # Save results to a new CSV file
+ data.to_csv(output_csv, index=False)
+ print(f"Predictions saved to {output_csv}")
+
+# Input and output CSV file paths
+input_csv = 'data.csv' # Change to your input CSV file name
+output_csv = 'predicted_data.csv' # Change to your desired output file name
+
+# Run the prediction
+predict_from_csv(input_csv, output_csv)