Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre Owned Car Price Predictor #214

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
817 changes: 817 additions & 0 deletions models/PreOwnedCarPrediction/data/Cleaned_Car_data.csv

Large diffs are not rendered by default.

893 changes: 893 additions & 0 deletions models/PreOwnedCarPrediction/data/raw_car_data.csv

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions models/PreOwnedCarPrediction/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import joblib

class CarPriceModel:
def __init__(self):
self.model = LinearRegression()

def load_data(self, filepath):
data = pd.read_csv(filepath)
return data

def preprocess_data(self, data):
# Perform preprocessing steps here
X = data.drop('price', axis=1) # Assuming 'price' is the target column
y = data['price']
return train_test_split(X, y, test_size=0.2, random_state=42)

def train(self, X_train, y_train):
self.model.fit(X_train, y_train)

def save_model(self, model_path):
joblib.dump(self.model, model_path)

if __name__ == "__main__":
car_model = CarPriceModel()
data = car_model.load_data('data/car_data.csv') # Example path
X_train, X_test, y_train, y_test = car_model.preprocess_data(data)
car_model.train(X_train, y_train)
car_model.save_model('saved_models/car_price_model.pkl')
21 changes: 21 additions & 0 deletions models/PreOwnedCarPrediction/modelEvalution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import joblib
import pandas as pd
from sklearn.metrics import mean_squared_error, r2_score

class ModelEvaluator:
def __init__(self, model_path):
self.model = joblib.load(model_path)

def evaluate(self, X_test, y_test):
predictions = self.model.predict(X_test)
mse = mean_squared_error(y_test, predictions)
r2 = r2_score(y_test, predictions)
print("Mean Squared Error:", mse)
print("R^2 Score:", r2)

if __name__ == "__main__":
data = pd.read_csv('data/car_data.csv') # Load your test data
X_test = data.drop('price', axis=1) # Adjust based on your dataset
y_test = data['price']
evaluator = ModelEvaluator('saved_models/car_price_model.pkl')
evaluator.evaluate(X_test, y_test)

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions models/PreOwnedCarPrediction/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import joblib
import pandas as pd

class CarPricePredictor:
def __init__(self, model_path):
self.model = joblib.load(model_path)

def predict(self, input_data):
return self.model.predict(input_data)

if __name__ == "__main__":
predictor = CarPricePredictor('saved_models/car_price_model.pkl')
# Example input data, replace with actual data
input_data = pd.DataFrame([[...]], columns=[...]) # Replace with actual column names
predictions = predictor.predict(input_data)
print(predictions)
Loading