Skip to content

Commit

Permalink
add time to models
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelefevre committed Jan 5, 2024
1 parent 0521ef8 commit d67aa7c
Show file tree
Hide file tree
Showing 23 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "bostadspriser-with-askingPrice", "nameWithDate": "bostadspriser-with-askingPrice-2024-01-05", "features": ["fee", "livingArea", "rooms", "runningCosts", "hasElevator", "hasBalcony", "lat", "long", "cpi", "hasHousingCooperative", "isPlot", "isWinterLeisureHouse", "isApartment", "isFarmWithForest", "isHouse", "isRowHouse", "isPairHouse", "isPairTerracedRowHouse", "isTerracedHouse", "isFarmWithoutForest", "isLeisureHouse", "isOtherHousingForm", "isFarmWithAgriculture", "age", "sinceLastRenovation", "soldYear", "soldMonth", "askingPrice"], "target": "finalPrice", "trainedAt": "2024-01-05T15:01:59.314123"}
Binary file not shown.
1 change: 0 additions & 1 deletion api/models/bostadspriser-with-askingPrice/metadata.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "bostadspriser-without-askingPrice", "nameWithDate": "bostadspriser-without-askingPrice-2024-01-05", "features": ["fee", "livingArea", "rooms", "runningCosts", "hasElevator", "hasBalcony", "lat", "long", "cpi", "hasHousingCooperative", "isPlot", "isWinterLeisureHouse", "isApartment", "isFarmWithForest", "isHouse", "isRowHouse", "isPairHouse", "isPairTerracedRowHouse", "isTerracedHouse", "isFarmWithoutForest", "isLeisureHouse", "isOtherHousingForm", "isFarmWithAgriculture", "age", "sinceLastRenovation", "soldYear", "soldMonth"], "target": "finalPrice", "trainedAt": "2024-01-05T15:01:52.948934"}
Binary file not shown.
1 change: 0 additions & 1 deletion api/models/bostadspriser-without-askingPrice/metadata.json

This file was deleted.

9 changes: 0 additions & 9 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,12 @@ def predict():
# Chose model depending on the parameters
model = helpers.choose_model(transformed_params.keys())

print("model chosen: " + model["name"])

# Convert to df and sort alphabetically
transformed_params_df = pd.DataFrame([transformed_params])

print("before sort")
print(transformed_params_df.columns)

transformed_params_df = transformed_params_df.reindex(
sorted(transformed_params_df.columns), axis=1
)

print("after sort")
print(transformed_params_df.columns)

# Scale the data
transformed_params = model["scaler"].transform(transformed_params_df)

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const api_url = "https://bostadspriser-api.app.cloud.cbh.kth.se";
// const api_url = "http://localhost:8080";
// const api_url = "https://bostadspriser-api.app.cloud.cbh.kth.se";
const api_url = "http://localhost:8080";

export const getListings = async (n, skip) => {
if (n === undefined) {
Expand Down
19 changes: 15 additions & 4 deletions model/train.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
import os
import json
import datetime
import pickle

import pandas as pd
import numpy as np
import pickle

from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.preprocessing import StandardScaler
Expand Down Expand Up @@ -129,7 +130,7 @@ def get_test_train_split(dataset, features, target):
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)

scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
Expand Down Expand Up @@ -201,6 +202,10 @@ def main():
data = data.reindex(sorted(data.columns), axis=1)

for name, setup in setups.items():
# Allow multiple timed versions of the same model
now = datetime.datetime.now()
name_with_date = name + "-" + now.strftime("%Y-%m-%d")

print(f"[{name}] Getting test train split...")
X_train, X_test, y_train, y_test, scaler = get_test_train_split(
data, setup["features"], setup["target"]
Expand All @@ -224,7 +229,7 @@ def main():
print(f"[{name}] Best model: " + best_model)

print(f"[{name}] Saving model and results...")
folder = f"../models/{name}"
folder = f"../models/{name_with_date}"

# Make directory
os.makedirs(folder, exist_ok=True)
Expand All @@ -241,7 +246,13 @@ def main():
results_df.to_csv(f"{folder}/results.csv")

# Save metadata
metadata = {"features": setup["features"], "target": setup["target"]}
metadata = {
"name": name,
"nameWithDate": name_with_date,
"features": setup["features"],
"target": setup["target"],
"trainedAt": now.isoformat(),
}
with open(f"{folder}/metadata.json", "w") as f:
json.dump(metadata, f)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "bostadspriser-with-askingPrice", "nameWithDate": "bostadspriser-with-askingPrice-2024-01-05", "features": ["fee", "livingArea", "rooms", "runningCosts", "hasElevator", "hasBalcony", "lat", "long", "cpi", "hasHousingCooperative", "isPlot", "isWinterLeisureHouse", "isApartment", "isFarmWithForest", "isHouse", "isRowHouse", "isPairHouse", "isPairTerracedRowHouse", "isTerracedHouse", "isFarmWithoutForest", "isLeisureHouse", "isOtherHousingForm", "isFarmWithAgriculture", "age", "sinceLastRenovation", "soldYear", "soldMonth", "askingPrice"], "target": "finalPrice", "trainedAt": "2024-01-05T15:01:59.314123"}
Binary file not shown.
1 change: 0 additions & 1 deletion models/bostadspriser-with-askingPrice/metadata.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "bostadspriser-without-askingPrice", "nameWithDate": "bostadspriser-without-askingPrice-2024-01-05", "features": ["fee", "livingArea", "rooms", "runningCosts", "hasElevator", "hasBalcony", "lat", "long", "cpi", "hasHousingCooperative", "isPlot", "isWinterLeisureHouse", "isApartment", "isFarmWithForest", "isHouse", "isRowHouse", "isPairHouse", "isPairTerracedRowHouse", "isTerracedHouse", "isFarmWithoutForest", "isLeisureHouse", "isOtherHousingForm", "isFarmWithAgriculture", "age", "sinceLastRenovation", "soldYear", "soldMonth"], "target": "finalPrice", "trainedAt": "2024-01-05T15:01:52.948934"}
Binary file not shown.
1 change: 0 additions & 1 deletion models/bostadspriser-without-askingPrice/metadata.json

This file was deleted.

0 comments on commit d67aa7c

Please sign in to comment.