This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89c5053
commit 3781959
Showing
6 changed files
with
1,779 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
1 change: 1 addition & 0 deletions
1
models/PreOwnedCarPrediction/notebooks/car_price_predictor.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |