@@ -42,7 +42,7 @@ def test_basic_usage(self):
4242 '''
4343 model = Mljar (project = self .proj_title , experiment = self .expt_title ,
4444 algorithms = ['xgb' ], metric = 'logloss' ,
45- validation = '3fold' , tuning_mode = 'Normal' )
45+ validation_kfolds = 3 , tuning_mode = 'Normal' )
4646 self .assertTrue (model is not None )
4747 # fit models and wait till all models are trained
4848 model .fit (X = self .X , y = self .y )
@@ -52,6 +52,72 @@ def test_basic_usage(self):
5252 score = self .mse (pred , self .y )
5353 self .assertTrue (score < 0.1 )
5454
55+ def test_usage_with_defaults (self ):
56+ '''
57+ Test usage with defaults.
58+ '''
59+ model = Mljar (project = self .proj_title , experiment = self .expt_title )
60+ self .assertTrue (model is not None )
61+ # fit models and wait till all models are trained
62+ model .fit (X = self .X , y = self .y , wait_till_all_done = False )
63+ # wait some time
64+ time .sleep (120 ) # wait a little longer - there are a lot of models
65+ # run prediction
66+ pred = model .predict (self .X )
67+ # get MSE
68+ score = self .mse (pred , self .y )
69+ self .assertTrue (score < 0.5 )
70+ # check default validation
71+ self .assertEqual (model .selected_algorithm .validation_scheme , "5-fold CV, Shuffle, Stratify" )
72+
73+ def test_usage_with_train_split (self ):
74+ '''
75+ Test usage with train split.
76+ '''
77+ model = Mljar (project = self .proj_title , experiment = self .expt_title ,
78+ validation_train_split = 0.8 , algorithms = ['xgb' ], tuning_mode = 'Normal' )
79+ self .assertTrue (model is not None )
80+ # fit models and wait till all models are trained
81+ model .fit (X = self .X , y = self .y , wait_till_all_done = False )
82+ # wait some time
83+ time .sleep (60 )
84+ # run prediction
85+ pred = model .predict (self .X )
86+ # get MSE
87+ score = self .mse (pred , self .y )
88+ self .assertTrue (score < 0.5 )
89+ # check default validation
90+ self .assertEqual (model .selected_algorithm .validation_scheme , "Split 80/20, Shuffle, Stratify" )
91+
92+
93+ def test_usage_with_validation_dataset (self ):
94+ '''
95+ Test usage with validation dataset.
96+ '''
97+ model = Mljar (project = self .proj_title , experiment = self .expt_title ,
98+ algorithms = ['xgb' ], tuning_mode = 'Normal' )
99+ self .assertTrue (model is not None )
100+ # load validation data
101+ df = pd .read_csv ('tests/data/test_1_vald.csv' )
102+ cols = ['sepal length' , 'sepal width' , 'petal length' , 'petal width' ]
103+ target = 'class'
104+ X_vald = df [cols ]
105+ y_vald = df [target ]
106+ # fit models and wait till all models are trained
107+ model .fit (X = self .X , y = self .y , validation_data = (X_vald , y_vald ), wait_till_all_done = False )
108+ # wait some time
109+ time .sleep (80 )
110+ # run prediction
111+ pred = model .predict (self .X )
112+ # get MSE
113+ score = self .mse (pred , self .y )
114+ self .assertTrue (score < 0.5 )
115+ # check default validation
116+ self .assertEqual (model .selected_algorithm .validation_scheme , "With dataset" )
117+
118+
119+
120+
55121 def test_empty_project_title (self ):
56122 with self .assertRaises (BadValueException ) as context :
57123 model = Mljar (project = '' , experiment = '' )
@@ -86,7 +152,7 @@ def test_non_wait_fit(self):
86152 '''
87153 model = Mljar (project = self .proj_title , experiment = self .expt_title ,
88154 algorithms = ['xgb' ], metric = 'logloss' ,
89- validation = '3fold' , tuning_mode = 'Normal' )
155+ validation_kfolds = 3 , tuning_mode = 'Normal' )
90156 self .assertTrue (model is not None )
91157 # fit models, just start computation and do not wait
92158 start_time = time .time ()
@@ -124,7 +190,7 @@ def test_retrive_models(self):
124190 '''
125191 model = Mljar (project = self .proj_title , experiment = self .expt_title ,
126192 algorithms = ['xgb' ], metric = 'logloss' ,
127- validation = '3fold' , tuning_mode = 'Normal' )
193+ validation_kfolds = 3 , tuning_mode = 'Normal' )
128194 self .assertTrue (model is not None )
129195 # fit models and wait till all models are trained
130196 model .fit (X = self .X , y = self .y )
@@ -153,7 +219,7 @@ def test_retrive_models(self):
153219 start_time = time .time ()
154220 model_2 = Mljar (project = self .proj_title , experiment = self .expt_title ,
155221 algorithms = ['xgb' ], metric = 'logloss' ,
156- validation = '3fold' , tuning_mode = 'Normal' )
222+ validation_kfolds = 3 , tuning_mode = 'Normal' )
157223 self .assertTrue (model_2 is not None )
158224 # re-use trained models
159225 model_2 .fit (X = self .X , y = self .y )
@@ -184,3 +250,6 @@ def test_basic_usage_with_defaults(self):
184250 score = self.mse(pred, self.y)
185251 self.assertTrue(score < 0.1)
186252 '''
253+
254+ if __name__ == "__main__" :
255+ unittest .main ()
0 commit comments