def test_predict(self): x = np.array([[1, 0, 0], [0, 1, 1], [1, 1, 1], [0, 1, 1]]) y = {"test1": [1, 0, 2, 0], "test2": [1, 0, 2, 0]} lr = LogisticRegression() lr.fit(EncodedData(x, y), Label("test2")) test_x = np.array([[0, 1, 0], [1, 0, 0]]) y = lr.predict(EncodedData(test_x), Label("test2")) self.assertTrue(len(y["test2"]) == 2) self.assertTrue(y["test2"][1] in [0, 1, 2])
def test_run(self): method = LogisticRegression() dataset = RepertoireDataset() dataset.encoded_data = EncodedData(examples=np.array([[1, 2, 3], [2, 3, 4], [1, 2, 3], [2, 3, 4], [1, 2, 3], [2, 3, 4]]), labels={ "l1": [1, 0, 1, 0, 1, 0], "l2": [0, 1, 0, 1, 0, 1] }, feature_names=["f1", "f2", "f3"]) path = EnvironmentSettings.root_path / "test/tmp/mlmethodtrainer/" method = MLMethodTrainer.run( MLMethodTrainerParams(result_path=path, dataset=dataset, label=Label(name="l1", values=[0, 1]), method=method, model_selection_n_folds=2, model_selection_cv=True, cores_for_training=1, train_predictions_path=path / "predictions.csv", ml_details_path=path / "details.yaml", optimization_metric="balanced_accuracy")) method.predict(EncodedData(np.array([1, 2, 3]).reshape(1, -1)), Label("l1")) self.assertTrue(os.path.isfile(path / "predictions.csv")) self.assertTrue(os.path.isfile(path / "details.yaml")) shutil.rmtree(path)