summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-11-27 21:25:26 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-11-27 21:25:26 +0530
commit5f85fe6603c6fbc68afa71d76c0b51ac8df6a41f (patch)
tree4ca0f0be5e373e85cc7b0bc267fc6e9db0590c01 /main.py
parent6670a8dfc419cf3d1f60427774de99e7010987e5 (diff)
downloadautopredict-5f85fe6603c6fbc68afa71d76c0b51ac8df6a41f.tar.gz
autopredict-5f85fe6603c6fbc68afa71d76c0b51ac8df6a41f.tar.bz2
autopredict-5f85fe6603c6fbc68afa71d76c0b51ac8df6a41f.zip
Added prediction feature of year
Diffstat (limited to 'main.py')
-rw-r--r--main.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/main.py b/main.py
index 3355b34..a8bdec8 100644
--- a/main.py
+++ b/main.py
@@ -17,6 +17,9 @@ def load_data(file_path):
# Preprocessing
def preprocess_data(df):
+ # Save the 'Year' column before calculating car age
+ df['Original_Year'] = df['Year']
+
# Calculate Car Age
df['Car_Age'] = 2024 - df['Year']
df.drop(columns=['Year'], inplace=True)
@@ -42,7 +45,7 @@ def preprocess_data(df):
# Train Model
def train_model(df, target, model_name):
# Features and target
- X = df.drop(columns=['Mileage Km/L', 'Price', 'Name'])
+ X = df.drop(columns=['Mileage Km/L', 'Price', 'Name', 'Original_Year'])
y = df[target]
# Split data
@@ -52,9 +55,7 @@ def train_model(df, target, model_name):
categorical_cols = ['Fuel_Type', 'Transmission', 'Owner_Type', 'Location']
numerical_cols = ['Kilometers_Driven', 'Engine CC', 'Power', 'Seats', 'Car_Age']
- preprocessor = ColumnTransformer(
- transformers=[
- ('num', StandardScaler(), numerical_cols),
+ preprocessor = ColumnTransformer( transformers=[ ('num', StandardScaler(), numerical_cols),
('cat', OneHotEncoder(drop='first'), categorical_cols)
]
)
@@ -106,5 +107,8 @@ def main():
print("Training price prediction model...")
train_model(df, target='Price', model_name='price_predictor')
+ print("Training year prediction model...")
+ train_model(df, target='Original_Year', model_name='year_predictor')
+
if __name__ == "__main__":
main()