Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vBykoff committed Nov 2, 2022
1 parent 873f0e1 commit edd8188
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 0 deletions.
27 changes: 27 additions & 0 deletions configs/train_config_gb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
input_data_path: "./data/raw/heart_cleveland_upload.csv"
output_model_path: "./models/model_gb.pkl"
splitting_params:
val_size: 0.3
random_state: 42
model_params:
model: "GB"
n_estimators: 25
random_state: 42
feature_params:
categorical_features:
- 'sex'
- 'cp'
- 'fbs'
- 'restecg'
- 'exang'
- 'slope'
- 'ca'
- 'thal'
numerical_features:
- 'age'
- 'trestbps'
- 'chol'
- 'thalach'
- 'oldpeak'
features_to_drop:
target: 'condition'
27 changes: 27 additions & 0 deletions configs/train_config_rf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
input_data_path: "./data/raw/heart_cleveland_upload.csv"
output_model_path: "./models/model_rf.pkl"
splitting_params:
val_size: 0.2
random_state: 42
model_params:
model: "RF"
n_estimators: 100
random_state: 42
feature_params:
categorical_features:
- 'sex'
- 'cp'
- 'fbs'
- 'restecg'
- 'exang'
- 'slope'
- 'ca'
- 'thal'
numerical_features:
- 'age'
- 'trestbps'
- 'chol'
- 'thalach'
- 'oldpeak'
features_to_drop:
target: 'condition'
298 changes: 298 additions & 0 deletions data/raw/heart_cleveland_upload.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,thal,condition
69,1,0,160,234,1,2,131,0,0.1,1,1,0,0
69,0,0,140,239,0,0,151,0,1.8,0,2,0,0
66,0,0,150,226,0,0,114,0,2.6,2,0,0,0
65,1,0,138,282,1,2,174,0,1.4,1,1,0,1
64,1,0,110,211,0,2,144,1,1.8,1,0,0,0
64,1,0,170,227,0,2,155,0,0.6,1,0,2,0
63,1,0,145,233,1,2,150,0,2.3,2,0,1,0
61,1,0,134,234,0,0,145,0,2.6,1,2,0,1
60,0,0,150,240,0,0,171,0,0.9,0,0,0,0
59,1,0,178,270,0,2,145,0,4.2,2,0,2,0
59,1,0,170,288,0,2,159,0,0.2,1,0,2,1
59,1,0,160,273,0,2,125,0,0,0,0,0,1
59,1,0,134,204,0,0,162,0,0.8,0,2,0,1
58,0,0,150,283,1,2,162,0,1,0,0,0,0
56,1,0,120,193,0,2,162,0,1.9,1,0,2,0
52,1,0,118,186,0,2,190,0,0,1,0,1,0
52,1,0,152,298,1,0,178,0,1.2,1,0,2,0
51,1,0,125,213,0,2,125,1,1.4,0,1,0,0
45,1,0,110,264,0,0,132,0,1.2,1,0,2,1
42,1,0,148,244,0,2,178,0,0.8,0,2,0,0
40,1,0,140,199,0,0,178,1,1.4,0,0,2,0
38,1,0,120,231,0,0,182,1,3.8,1,0,2,1
34,1,0,118,182,0,2,174,0,0,0,0,0,0
74,0,1,120,269,0,2,121,1,0.2,0,1,0,0
71,0,1,160,302,0,0,162,0,0.4,0,2,0,0
70,1,1,156,245,0,2,143,0,0,0,0,0,0
66,1,1,160,246,0,0,120,1,0,1,3,1,1
63,0,1,140,195,0,0,179,0,0,0,2,0,0
62,1,1,120,281,0,2,103,0,1.4,1,1,2,1
62,1,1,128,208,1,2,140,0,0,0,0,0,0
59,1,1,140,221,0,0,164,1,0,0,0,0,0
58,1,1,120,284,0,2,160,0,1.8,1,0,0,1
58,0,1,136,319,1,2,152,0,0,0,2,0,1
57,0,1,130,236,0,2,174,0,0,1,1,0,1
57,1,1,124,261,0,0,141,0,0.3,0,0,2,1
57,1,1,154,232,0,2,164,0,0,0,1,0,1
56,1,1,120,240,0,0,169,0,0,2,0,0,0
56,0,1,140,294,0,2,153,0,1.3,1,0,0,0
56,1,1,120,236,0,0,178,0,0.8,0,0,0,0
56,1,1,130,221,0,2,163,0,0,0,0,2,0
55,0,1,135,250,0,2,161,0,1.4,1,0,0,0
55,1,1,130,262,0,0,155,0,0,0,0,0,0
55,0,1,132,342,0,0,166,0,1.2,0,0,0,0
54,1,1,108,309,0,0,156,0,0,0,0,2,0
54,0,1,132,288,1,2,159,1,0,0,1,0,0
54,1,1,192,283,0,2,195,0,0,0,1,2,1
52,1,1,120,325,0,0,172,0,0.2,0,0,0,0
52,1,1,134,201,0,0,158,0,0.8,0,1,0,0
52,1,1,128,205,1,0,184,0,0,0,0,0,0
50,0,1,120,244,0,0,162,0,1.1,0,0,0,0
49,0,1,134,271,0,0,162,0,0,1,0,0,0
49,1,1,130,266,0,0,171,0,0.6,0,0,0,0
48,1,1,110,229,0,0,168,0,1,2,0,2,1
48,1,1,130,245,0,2,180,0,0.2,1,0,0,0
46,1,1,101,197,1,0,156,0,0,0,0,2,0
46,0,1,105,204,0,0,172,0,0,0,0,0,0
45,0,1,130,234,0,2,175,0,0.6,1,0,0,0
45,0,1,112,160,0,0,138,0,0,1,0,0,0
45,1,1,128,308,0,2,170,0,0,0,0,0,0
44,1,1,120,263,0,0,173,0,0,0,0,2,0
44,1,1,130,219,0,2,188,0,0,0,0,0,0
44,1,1,120,220,0,0,170,0,0,0,0,0,0
42,1,1,120,295,0,0,162,0,0,0,0,0,0
41,1,1,135,203,0,0,132,0,0,1,0,1,0
41,0,1,130,204,0,2,172,0,1.4,0,0,0,0
41,0,1,105,198,0,0,168,0,0,0,1,0,0
41,1,1,110,235,0,0,153,0,0,0,0,0,0
41,0,1,126,306,0,0,163,0,0,0,0,0,0
41,1,1,120,157,0,0,182,0,0,0,0,0,0
35,1,1,122,192,0,0,174,0,0,0,0,0,0
34,0,1,118,210,0,0,192,0,0.7,0,0,0,0
29,1,1,130,204,0,2,202,0,0,0,0,0,0
76,0,2,140,197,0,1,116,0,1.1,1,0,0,0
71,0,2,110,265,1,2,130,0,0,0,1,0,0
70,1,2,160,269,0,0,112,1,2.9,1,1,2,1
69,1,2,140,254,0,2,146,0,2,1,3,2,1
68,1,2,180,274,1,2,150,1,1.6,1,0,2,1
68,0,2,120,211,0,2,115,0,1.5,1,0,0,0
68,1,2,118,277,0,0,151,0,1,0,1,2,0
67,0,2,115,564,0,2,160,0,1.6,1,0,2,0
67,1,2,152,212,0,2,150,0,0.8,1,0,2,1
67,0,2,152,277,0,0,172,0,0,0,1,0,0
66,0,2,146,278,0,2,152,0,0,1,1,0,0
65,0,2,140,417,1,2,157,0,0.8,0,1,0,0
65,0,2,155,269,0,0,148,0,0.8,0,0,0,0
65,0,2,160,360,0,2,151,0,0.8,0,0,0,0
64,1,2,125,309,0,0,131,1,1.8,1,0,2,1
64,1,2,140,335,0,0,158,0,0,0,0,0,1
64,0,2,140,313,0,0,133,0,0.2,0,0,2,0
63,0,2,135,252,0,2,172,0,0,0,0,0,0
62,1,2,130,231,0,0,146,0,1.8,1,3,2,0
62,0,2,130,263,0,0,97,0,1.2,1,1,2,1
61,1,2,150,243,1,0,137,1,1,1,0,0,0
60,1,2,140,185,0,2,155,0,3,1,0,0,1
60,0,2,102,318,0,0,160,0,0,0,1,0,0
60,0,2,120,178,1,0,96,0,0,0,0,0,0
59,1,2,126,218,1,0,134,0,2.2,1,1,1,1
59,1,2,150,212,1,0,157,0,1.6,0,0,0,0
58,1,2,112,230,0,2,165,0,2.5,1,1,2,1
58,1,2,105,240,0,2,154,1,0.6,1,0,2,0
58,1,2,132,224,0,2,173,0,3.2,0,2,2,1
58,0,2,120,340,0,0,172,0,0,0,0,0,0
58,1,2,140,211,1,2,165,0,0,0,0,0,0
57,1,2,128,229,0,2,150,0,0.4,1,1,2,1
57,1,2,150,168,0,0,174,0,1.6,0,0,0,0
57,1,2,150,126,1,0,173,0,0.2,0,1,2,0
56,1,2,130,256,1,2,142,1,0.6,1,1,1,1
54,1,2,125,273,0,2,152,0,0.5,2,1,0,0
54,1,2,120,258,0,2,147,0,0.4,1,0,2,0
54,0,2,110,214,0,0,158,0,1.6,1,0,0,0
54,0,2,135,304,1,0,170,0,0,0,0,0,0
54,1,2,150,232,0,2,165,0,1.6,0,0,2,0
54,0,2,108,267,0,2,167,0,0,0,0,0,0
54,0,2,160,201,0,0,163,0,0,0,1,0,0
53,1,2,130,197,1,2,152,0,1.2,2,0,0,0
53,1,2,130,246,1,2,173,0,0,0,3,0,0
52,0,2,136,196,0,2,169,0,0.1,1,0,0,0
52,1,2,172,199,1,0,162,0,0.5,0,0,2,0
51,1,2,100,222,0,0,143,1,1.2,1,0,0,0
51,1,2,125,245,1,2,166,0,2.4,1,0,0,0
51,1,2,110,175,0,0,123,0,0.6,0,0,0,0
51,0,2,140,308,0,2,142,0,1.5,0,1,0,0
51,0,2,130,256,0,2,149,0,0.5,0,0,0,0
51,1,2,94,227,0,0,154,1,0,0,1,2,0
51,0,2,120,295,0,2,157,0,0.6,0,0,0,0
50,0,2,120,219,0,0,158,0,1.6,1,0,0,0
50,1,2,140,233,0,0,163,0,0.6,1,1,2,1
50,1,2,129,196,0,0,163,0,0,0,0,0,0
49,1,2,120,188,0,0,139,0,2,1,3,2,1
49,1,2,118,149,0,2,126,0,0.8,0,3,0,1
48,0,2,130,275,0,0,139,0,0.2,0,0,0,0
48,1,2,124,255,1,0,175,0,0,0,2,0,0
47,1,2,138,257,0,2,156,0,0,0,0,0,0
47,1,2,108,243,0,0,152,0,0,0,0,0,1
47,1,2,130,253,0,0,179,0,0,0,0,0,0
46,0,2,142,177,0,2,160,1,1.4,2,0,0,0
46,1,2,150,231,0,0,147,0,3.6,1,0,0,1
44,0,2,108,141,0,0,175,0,0.6,1,0,0,0
44,0,2,118,242,0,0,149,0,0.3,1,1,0,0
44,1,2,130,233,0,0,179,1,0.4,0,0,0,0
44,1,2,140,235,0,2,180,0,0,0,0,0,0
44,1,2,120,226,0,0,169,0,0,0,0,0,0
43,0,2,122,213,0,0,165,0,0.2,1,0,0,0
43,1,2,130,315,0,0,162,0,1.9,0,1,0,0
42,1,2,120,240,1,0,194,0,0.8,2,0,2,0
42,0,2,120,209,0,0,173,0,0,1,0,0,0
42,1,2,130,180,0,0,150,0,0,0,0,0,0
41,1,2,130,214,0,2,168,0,2,1,0,0,0
41,1,2,112,250,0,0,179,0,0,0,0,0,0
41,0,2,112,268,0,2,172,1,0,0,0,0,0
39,0,2,138,220,0,0,152,0,0,1,0,0,0
39,1,2,140,321,0,2,182,0,0,0,0,0,0
39,0,2,94,199,0,0,179,0,0,0,0,0,0
37,1,2,130,250,0,0,187,0,3.5,2,0,0,0
37,0,2,120,215,0,0,170,0,0,0,0,0,0
77,1,3,125,304,0,2,162,1,0,0,3,0,1
71,0,3,112,149,0,0,125,0,1.6,1,0,0,0
70,1,3,145,174,0,0,125,1,2.6,2,0,2,1
70,1,3,130,322,0,2,109,0,2.4,1,3,0,1
68,1,3,144,193,1,0,141,0,3.4,1,2,2,1
67,1,3,160,286,0,2,108,1,1.5,1,3,0,1
67,1,3,120,229,0,2,129,1,2.6,1,2,2,1
67,1,3,125,254,1,0,163,0,0.2,1,2,2,1
67,1,3,100,299,0,2,125,1,0.9,1,2,0,1
67,1,3,120,237,0,0,71,0,1,1,0,0,1
67,0,3,106,223,0,0,142,0,0.3,0,2,0,0
66,1,3,120,302,0,2,151,0,0.4,1,0,0,0
66,0,3,178,228,1,0,165,1,1,1,2,2,1
66,1,3,112,212,0,2,132,1,0.1,0,1,0,1
66,1,3,160,228,0,2,138,0,2.3,0,0,1,0
65,0,3,150,225,0,2,114,0,1,1,3,2,1
65,1,3,135,254,0,2,127,0,2.8,1,1,2,1
65,1,3,120,177,0,0,140,0,0.4,0,0,2,0
65,1,3,110,248,0,2,158,0,0.6,0,2,1,1
64,1,3,120,246,0,2,96,1,2.2,2,1,0,1
64,1,3,145,212,0,2,132,0,2,1,2,1,1
64,0,3,130,303,0,0,122,0,2,1,2,0,0
64,1,3,128,263,0,0,105,1,0.2,1,1,2,0
64,0,3,180,325,0,0,154,1,0,0,0,0,0
63,1,3,130,254,0,2,147,0,1.4,1,1,2,1
63,0,3,150,407,0,2,154,0,4,1,3,2,1
63,0,3,108,269,0,0,169,1,1.8,1,2,0,1
63,0,3,124,197,0,0,136,1,0,1,0,0,1
63,1,3,130,330,1,2,132,1,1.8,0,3,2,1
63,1,3,140,187,0,2,144,1,4,0,2,2,1
62,0,3,140,268,0,2,160,0,3.6,2,2,0,1
62,0,3,160,164,0,2,145,0,6.2,2,3,2,1
62,1,3,120,267,0,0,99,1,1.8,1,2,2,1
62,0,3,140,394,0,2,157,0,1.2,1,0,0,0
62,0,3,138,294,1,0,106,0,1.9,1,3,0,1
62,0,3,150,244,0,0,154,1,1.4,1,0,0,1
62,0,3,124,209,0,0,163,0,0,0,0,0,0
61,1,3,120,260,0,0,140,1,3.6,1,1,2,1
61,0,3,145,307,0,2,146,1,1,1,0,2,1
61,1,3,138,166,0,2,125,1,3.6,1,1,0,1
61,0,3,130,330,0,2,169,0,0,0,0,0,1
61,1,3,140,207,0,2,138,1,1.9,0,1,2,1
61,1,3,148,203,0,0,161,0,0,0,1,2,1
60,1,3,130,206,0,2,132,1,2.4,1,2,2,1
60,1,3,145,282,0,2,142,1,2.8,1,2,2,1
60,1,3,125,258,0,2,141,1,2.8,1,1,2,1
60,0,3,150,258,0,2,157,0,2.6,1,2,2,1
60,1,3,140,293,0,2,170,0,1.2,1,2,2,1
60,1,3,117,230,1,0,160,1,1.4,0,2,2,1
60,1,3,130,253,0,0,144,1,1.4,0,1,2,1
60,0,3,158,305,0,2,161,0,0,0,0,0,1
59,1,3,170,326,0,2,140,1,3.4,2,0,2,1
59,1,3,135,234,0,0,161,0,0.5,1,0,2,0
59,1,3,110,239,0,2,142,1,1.2,1,1,2,1
59,0,3,174,249,0,0,143,1,0,1,0,0,1
59,1,3,164,176,1,2,90,0,1,1,2,1,1
59,1,3,140,177,0,0,162,1,0,0,1,2,1
59,1,3,138,271,0,2,182,0,0,0,0,0,0
58,1,3,114,318,0,1,140,0,4.4,2,3,1,1
58,1,3,128,216,0,2,131,1,2.2,1,3,2,1
58,0,3,100,248,0,2,122,0,1,1,0,0,0
58,1,3,128,259,0,2,130,1,3,1,2,2,1
58,1,3,146,218,0,0,105,0,2,1,1,2,1
58,0,3,130,197,0,0,131,0,0.6,1,0,0,0
58,0,3,170,225,1,2,146,1,2.8,1,2,1,1
58,1,3,150,270,0,2,111,1,0.8,0,0,2,1
58,1,3,125,300,0,2,171,0,0,0,2,2,1
58,1,3,100,234,0,0,156,0,0.1,0,1,2,1
57,1,3,140,192,0,0,148,0,0.4,1,0,1,0
57,1,3,150,276,0,2,112,1,0.6,1,1,1,1
57,1,3,165,289,1,2,124,0,1,1,3,2,1
57,1,3,152,274,0,0,88,1,1.2,1,1,2,1
57,1,3,110,201,0,0,126,1,1.5,1,0,1,0
57,1,3,110,335,0,0,143,1,3,1,1,2,1
57,0,3,140,241,0,0,123,1,0.2,1,0,2,1
57,1,3,130,131,0,0,115,1,1.2,1,1,2,1
57,0,3,120,354,0,0,163,1,0.6,0,0,0,0
57,0,3,128,303,0,2,159,0,0,0,1,0,0
57,1,3,132,207,0,0,168,1,0,0,0,2,0
56,0,3,200,288,1,2,133,1,4,2,2,2,1
56,1,3,130,283,1,2,103,1,1.6,2,0,2,1
56,1,3,125,249,1,2,144,1,1.2,1,1,0,1
56,1,3,132,184,0,2,105,1,2.1,1,1,1,1
56,0,3,134,409,0,2,150,1,1.9,1,2,2,1
55,1,3,140,217,0,0,111,1,5.6,2,0,2,1
55,1,3,132,353,0,0,132,1,1.2,1,1,2,1
55,1,3,160,289,0,2,145,1,0.8,1,1,2,1
55,0,3,180,327,0,1,117,1,3.4,1,0,0,1
55,0,3,128,205,0,1,130,1,2,1,1,2,1
54,1,3,124,266,0,2,109,1,2.2,1,1,2,1
54,1,3,120,188,0,0,113,0,1.4,1,1,2,1
54,1,3,110,239,0,0,126,1,2.8,1,1,2,1
54,1,3,110,206,0,2,108,1,0,1,1,0,1
54,1,3,122,286,0,2,116,1,3.2,1,2,0,1
54,1,3,140,239,0,0,160,0,1.2,0,0,0,0
53,1,3,140,203,1,2,155,1,3.1,2,0,2,1
53,0,3,130,264,0,2,143,0,0.4,1,0,0,0
53,1,3,123,282,0,0,95,1,2,1,2,2,1
53,0,3,138,234,0,2,160,0,0,0,0,0,0
53,1,3,142,226,0,2,111,1,0,0,0,2,0
52,1,3,128,255,0,0,161,1,0,0,1,2,1
52,1,3,108,233,1,0,147,0,0.1,0,3,2,0
52,1,3,112,230,0,0,160,0,0,0,1,0,1
52,1,3,125,212,0,0,168,0,1,0,2,2,1
51,0,3,130,305,0,0,142,1,1.2,1,0,2,1
51,1,3,140,298,0,0,122,1,4.2,1,3,2,1
51,1,3,140,261,0,2,186,1,0,0,0,0,0
51,1,3,140,299,0,0,173,1,1.6,0,0,2,1
50,1,3,150,243,0,2,128,0,2.6,1,0,2,1
50,1,3,144,200,0,2,126,1,0.9,1,0,2,1
50,0,3,110,254,0,2,159,0,0,0,0,0,0
49,0,3,130,269,0,0,163,0,0,0,0,0,0
48,1,3,124,274,0,2,166,0,0.5,1,0,2,1
48,1,3,122,222,0,2,186,0,0,0,0,0,0
48,1,3,130,256,1,2,150,1,0,0,2,2,1
47,1,3,110,275,0,2,118,1,1,1,1,0,1
47,1,3,112,204,0,0,143,0,0.1,0,0,0,0
46,0,3,138,243,0,2,152,1,0,1,0,0,0
46,1,3,140,311,0,0,120,1,1.8,1,2,2,1
46,1,3,120,249,0,2,144,0,0.8,0,0,2,1
45,1,3,104,208,0,2,148,1,3,1,0,0,0
45,0,3,138,236,0,2,152,1,0.2,1,0,0,0
45,1,3,142,309,0,2,147,1,0,1,3,2,1
45,1,3,115,260,0,2,185,0,0,0,0,0,0
44,1,3,120,169,0,0,144,1,2.8,2,0,1,1
44,1,3,112,290,0,2,153,0,0,0,1,0,1
44,1,3,110,197,0,2,177,0,0,0,1,0,1
43,1,3,120,177,0,2,120,1,2.5,1,0,2,1
43,0,3,132,341,1,2,136,1,3,1,0,2,1
43,1,3,115,303,0,0,181,0,1.2,1,0,0,0
43,1,3,150,247,0,0,171,0,1.5,0,0,0,0
43,1,3,110,211,0,0,161,0,0,0,0,2,0
42,0,3,102,265,0,2,122,0,0.6,1,0,0,0
42,1,3,136,315,0,0,125,1,1.8,1,0,1,1
42,1,3,140,226,0,0,178,0,0,0,0,0,0
41,1,3,110,172,0,2,158,0,0,0,0,2,1
40,1,3,110,167,0,2,114,1,2,1,0,2,1
40,1,3,152,223,0,0,181,0,0,0,0,2,1
39,1,3,118,219,0,0,140,0,1.2,1,0,2,1
35,1,3,120,198,0,0,130,1,1.6,1,0,2,1
35,0,3,138,183,0,0,182,0,1.4,0,0,0,0
35,1,3,126,282,0,2,156,1,0,0,0,2,1
Binary file added models/model_gb.pkl
Binary file not shown.
Binary file added models/model_rf.pkl
Binary file not shown.
Empty file added src/__init__.py
Empty file.
Empty file added tests/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions tests/make_dataset_test/test_make_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from src.data.make_dataset import read_data, train_val_split
from src.enities.splitting_params import SplittingParams


class MakeDatasetTest(unittest.TestCase):
def setUp(self) -> None:
self.dataset_path = "./tests/test_data/synthetic_data.csv"
self.target = "condition"

def test_load_dataset(self):
data = read_data(self.dataset_path)
self.assertEqual(data.shape, (50, 15))
assert self.target in data.keys()

def test_split_dataset(self):
val_size = 0.2
splitting_params = SplittingParams(random_state=42, val_size=val_size)
data = read_data(self.dataset_path)
train, val = train_val_split(data, splitting_params)
self.assertEqual(train.shape, (data.shape[0] * (1 - val_size), 15))
self.assertEqual(val.shape, (data.shape[0] * val_size, 15))


if __name__ == '__main__':
unittest.main()
Empty file added tests/test_data/__init__.py
Empty file.

0 comments on commit edd8188

Please sign in to comment.