-
Notifications
You must be signed in to change notification settings - Fork 0
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
f668682
commit df85969
Showing
9 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.vscode | ||
**__pycache__ | ||
|
||
checkpoints | ||
predictions | ||
|
||
catboost_info |
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
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
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
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,50 @@ | ||
import argparse | ||
import os | ||
import pickle | ||
|
||
from mlopscourse.data.prepare_dataset import prepare_dataset | ||
|
||
|
||
def parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="Training and evaluation parameters") | ||
|
||
parser.add_argument( | ||
"--model", | ||
type=str, | ||
default="rf", | ||
choices=["rf", "cb"], | ||
help="Type of model used for training", | ||
) | ||
parser.add_argument( | ||
"--ckpt", | ||
type=str, | ||
default="model_rf.p", | ||
help="The filename inside 'checkpoint/' to load the model from", | ||
) | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def infer(args: argparse.Namespace): | ||
( | ||
_, | ||
_, | ||
X_test, | ||
y_test, | ||
_, | ||
_, | ||
) = prepare_dataset(print_info=False) | ||
|
||
with open(f"checkpoints/{args.ckpt}", "rb") as f: | ||
model = pickle.load(f) | ||
print(f"Evaluating the {args.model} model...") | ||
y_preds = model.eval(X_test, y_test) | ||
|
||
os.makedirs("predictions", exist_ok=True) | ||
y_preds.to_csv(f"predictions/model_{args.model}_preds.csv") | ||
|
||
|
||
if __name__ == "__main__": | ||
arguments = parse_args() | ||
infer(arguments) |
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
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
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
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,43 @@ | ||
import argparse | ||
import os | ||
|
||
from data.prepare_dataset import prepare_dataset | ||
from models.models_zoo import prepare_model | ||
|
||
|
||
def parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="Training and evaluation parameters") | ||
|
||
parser.add_argument( | ||
"--model", | ||
type=str, | ||
default="rf", | ||
choices=["rf", "cb"], | ||
help="Type of model used for training", | ||
) | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def train(args: argparse.Namespace): | ||
( | ||
X_train, | ||
y_train, | ||
_, | ||
_, | ||
numerical_features, | ||
categorical_features, | ||
) = prepare_dataset() | ||
model = prepare_model(args, numerical_features, categorical_features) | ||
|
||
print(f"Training the {args.model} model...") | ||
model.train(X_train, y_train) | ||
|
||
os.makedirs("checkpoints", exist_ok=True) | ||
model.save_checkpoint("checkpoints/") | ||
|
||
|
||
if __name__ == "__main__": | ||
arguments = parse_args() | ||
train(arguments) |