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

Dementia Prediction Model #215

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
31 changes: 31 additions & 0 deletions models/Dementia Prediction Model/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):
# Assuming 'price' is the target column and the rest are features
X = data.drop('price', axis=1) # Replace 'price' with the actual target column name
y = data['price'] # Replace 'price' with the actual target column name
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/cleaned_car_data.csv') # Adjust the path to your dataset
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/Dementia Prediction Model/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/cleaned_car_data.csv') # Load your test data
X_test = data.drop('price', axis=1) # Replace 'price' with the actual target column name
y_test = data['price'] # Replace 'price' with the actual target column name
evaluator = ModelEvaluator('saved_models/car_price_model.pkl')
evaluator.evaluate(X_test, y_test)
Loading
Loading