Skip to content

Commit

Permalink
Add target feature option for moses runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Habush committed Feb 21, 2020
1 parent 849eb0d commit 9bf96d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions crossval/moses_cross_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pandas as pd
from scipy import stats
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.model_selection import StratifiedShuffleSplit, ShuffleSplit

from crossval.model_evaluator import ModelEvaluator
from crossval.moses_runner import MosesRunner
Expand Down Expand Up @@ -95,7 +95,7 @@ def split_dataset(self):

x, y = df.values, df[self.session.target_feature].values
splits, test_size = self.session.crossval_options["folds"], self.session.crossval_options["testSize"]
cv = StratifiedShuffleSplit(n_splits=splits, test_size=test_size)
cv = ShuffleSplit(n_splits=splits, test_size=test_size, random_state=42)

return x, df.columns.values, cv.split(x, y)

Expand All @@ -111,7 +111,7 @@ def run_seeds(self, seeds, i, file):
output_file = tempfile.NamedTemporaryFile(mode="w+")
moses_options = " ".join([self.session.moses_options, "--random-seed " + str(seed)])

moses_runner = MosesRunner(file, output_file.name, moses_options, self.session.mnemonic)
moses_runner = MosesRunner(file, output_file.name, moses_options, self.session.mnemonic, self.session.target_feature)
returncode, stdout, stderr = moses_runner.run_moses()

if returncode != 0:
Expand Down
5 changes: 3 additions & 2 deletions crossval/moses_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MosesRunner:
A class that handles running of the MOSES binary program
"""

def __init__(self, input_file, output_file, moses_opts, session_id):
def __init__(self, input_file, output_file, moses_opts, session_id, target_feature="case"):
"""
:param input_file: The input file to run MOSES on
:param output_file: The file to write MOSES program outputs to
Expand All @@ -24,6 +24,7 @@ def __init__(self, input_file, output_file, moses_opts, session_id):
if not "W1" in moses_opts: moses_opts += ' -W1'
self.output_regex = re.compile(r"(-?\d+) (.+) \[(.+)\]")
self.logger = get_logger(session_id)
self.target_feature = target_feature

def run_moses(self):
"""
Expand All @@ -34,7 +35,7 @@ def run_moses(self):
:returns stdin: the error output of the process, if any
"""

cmd = ["moses", "-i", self.input, "-o", self.output]
cmd = ["moses", "-i", self.input, "-o", self.output, "--target-feature", self.target_feature]

for opt in self.moses_options.split():
cmd.append(opt)
Expand Down
5 changes: 3 additions & 2 deletions crossval/post_process.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
__author__ = 'Abdulrahman Semrie<[email protected]>'

import pymongo
from config import MONGODB_URI, DB_NAME, DATASET_DIR
import os
import pathlib

import pandas as pd

from config import DATASET_DIR
from crossval.filters import loader
from models.objmodel import Score, MosesModel

Expand Down

0 comments on commit 9bf96d1

Please sign in to comment.