Esempio n. 1
0
    def __init__(self):
        self.utils = Utilities()
        self.validation = Validation()
        self.entry = Entry()
        self.menu = Menu()

        self.results = list()
Esempio n. 2
0
 def __init__(self, config, hq):
   self.config = config
   self.ident = config.ident
   self.hq = hq
   self.state = 0
   self.perm8_state = 0
   self.stats = Stats(config, hq)
   self.utils = Utilities()
Esempio n. 3
0
def main():
    # Instantiate objects
    config = Config()
    fields = build_data()
    utils = Utilities(fields, config)
    agent = PPO(utils.total_fields, utils.total_fields, utils.field_indexes,
                config)
    # train on data
    verify_network(agent, utils, config)
Esempio n. 4
0
def main():
    # Instantiate objects
    agent_name = 'PPO'
    config = Config(agent_name)
    fields = build_data()
    utils = Utilities(fields, config)
    agent = PPO(utils.total_fields, utils.total_fields, utils.field_indexes,
                config)
    # train on data
    train_network(agent, utils, config)
Esempio n. 5
0
def feature_selection(data):

    clf = LogisticRegression(max_iter=1000)
    y = data["Outcome"].copy()
    X = data.loc[:, ~data.columns.isin(['Outcome'])].copy()

    num_attribs = [
        "Age", "ContactsTotal", "DaysFromPrevAttempt", "PrevAttempts",
        "CallDuration"
    ]
    cat_attribs = [
        "Job", "MaritalStatus", "EducationLevel", "ContactMeans",
        "ContactMonth", "PrevOutcome"
    ]
    ordinal_attribs = ["ContactDay"]

    full_pipeline = ColumnTransformer([
        ("num", StandardScaler(), num_attribs),
        ("cat", OneHotEncoder(sparse=False), cat_attribs),
        ("ord", OrdinalEncoder(), ordinal_attribs)
    ])

    X_p = full_pipeline.fit_transform(X)
    rfecv = RFECV(estimator=clf, step=1, cv=StratifiedKFold(2), scoring='f1')
    rfecv.fit(X_p, y)

    # Plot number of features VS. cross-validation scores
    plt.figure()
    plt.xlabel("Number of features selected")
    plt.ylabel("Cross validation score (nb of correct classifications)")
    plt.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_)
    plt.savefig("../plots/RFE.png")
    plt.show()

    print("Optimal number of features : %d" % rfecv.n_features_)
    get_names = Utilities()
    feature_names = get_names.get_column_names_from_ColumnTransformer(
        full_pipeline)

    res = list(compress(feature_names, rfecv.support_))
    non_res = list(compress(feature_names, ~rfecv.support_))
    print("The list with the optimal features is: ", str(res))
    print("The list with non optimal features is: ", str(non_res))

    indexes = [i for i, val in enumerate(rfecv.support_) if val]
    with open("../models/optimal_features.txt", "wb") as fp:
        pickle.dump(indexes, fp)
def run():

    input_file_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'input', 'inputPS4.txt'))
    output_file_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'output', 'outputPS4.txt'))
    input_file = open(input_file_path, 'r')
    output_file = open(output_file_path, 'w')
    utils = Utilities(input_file)
    input_data_list = utils.create_list_from_input_data()
    for data in input_data_list:
        if not data:
            output_file.write("Empty or invalid row entered \n")
            continue
        if len(data) == 1:
            output_file.write("Single element entered : " + str(data[0]) +
                              "\n")
            continue
        distribution_type = utils.get_distribution_type(data)
        maxima_minima = utils.get_maxima_minima(distribution_type)
        output_file.write(f"{distribution_type} {maxima_minima}\n")
Esempio n. 7
0
def elevate(argv):
    totalDomains = set([])
    outputFileName = ''
    targetDomain = ''
    targetEmail = ''
    partialOrgName = ''
    checkEmails = False
    verbose = False
    try:
        (opts, args) = getopt.getopt(argv, 'h:o:d:e:n:v')
    except getopt.GetoptError:
        print('elevate.py -o <outputfile> -d <domain name> -e <email address> -n <partial name> -v <verbose mode>')
        sys.exit(2)
    for (opt, arg) in opts:
        if opt == '-h':
            print('elevate.py -o <outputfile>')
            sys.exit()
        elif opt in '-o':
            outputFileName = arg
        elif opt in '-d':
            targetDomain = arg
        elif opt in '-e':
            targetEmail = arg
        elif opt in '-n':
            partialOrgName = arg
        elif opt in '-v':
            verbose = True
    if(outputFileName == ''):
        raise Exception("Output file must be set with '-o' flag")
    utils = Utilities()
    if(targetDomain != ''):
        totalDomains = totalDomains.union(whoisSearch(utils,targetDomain,verbose))
    if(partialOrgName != ''):
        totalDomains = totalDomains.union(asnSearch(utils,partialOrgName,verbose))
    if(targetEmail != ''):
        totalDomains = totalDomains.union(emailSearch(utils,targetEmail,verbose))
    print(str(len(totalDomains)) + " unique domain names discovered.")
    utils.writeToFile(list(totalDomains),outputFileName)   
Esempio n. 8
0
from test_data import build_data
sys.path.append('/Users/morgan/Code/RouteMuse/')
# sys.path.append('/home/kenpachi/Code/RouteMuse/')
from utils import Utilities
from config import Config

"""
Unit tests for all functions

seed the Utility class with the relevant data
"""

config = Config()
keys = config.keys
fields = build_data()
utils = Utilities(fields,keys)

class TestConversion(unittest.TestCase):
    def test(self):
        print('utils route_array',utils.route_array)
        self.assertEqual(len(utils.field_indexes), 12)

class TestRandomRoutes(unittest.TestCase):
    def test(self):
        ran_routes = utils.gen_random_routes(5)
        self.assertEqual(ran_routes.shape[0], 5)

class TestReadable(unittest.TestCase):
    def test(self):
        ran_routes = utils.gen_random_routes(5)
        readable_routes = [utils.convert_route_to_readable(route) for route in ran_routes]
 def test_return_correct_size_of_model(self):
     utils = Utilities()
     json_ob = utils.chunk_json_object(0, 2)
     assertEqual(len(json_ob), 2)
Esempio n. 10
0
 def __init__(self):
     super().__init__()
     self.utils = Utilities()
     self.validation = Validation()
Esempio n. 11
0
    def access_log(self):
        '''Method containing the main loop to run the program.'''

        menu = Menu()
        entry = Entry()
        utils = Utilities()
        search = Search()
        validation = Validation()
        current_menu = constants.MAIN_MENU

        if not os.path.exists(constants.FILENAME):
            with open(constants.FILENAME, 'a') as file:
                writer = csv.DictWriter(file, fieldnames=constants.FIELDNAMES)
                writer.writeheader()

        while True:
            utils.clear_screen()
            menu.display(current_menu)
            choice = menu.get_user_choice()

            if current_menu == constants.MAIN_MENU:

                if not validation.is_valid_input(choice, menu='csq'):
                    continue

                if choice == 'c':
                    utils.clear_screen()
                    entry.create_new_entry()

                elif choice == 's':
                    current_menu = constants.SEARCH_MENU

                elif choice == 'q':
                    break

            elif current_menu == constants.SEARCH_MENU:

                if not validation.is_valid_input(choice, menu='edtprm'):
                    continue

                if choice == 'e':
                    search.search('Please enter a date to search: ', 'date')

                elif choice == 'd':
                    search.search(
                        'Please enter two comma separated dates to search'
                        '\n(ex. 01/15/1982, 12/11/2017): ', 'date_range')

                elif choice == 't':
                    search.search(
                        'Please enter a time to search: ', 'time_spent')

                elif choice == 'p':
                    search.search(
                        'Please enter a word or phrase to search: ',
                        'exact_match')

                elif choice == 'r':
                    search.search(
                        'Please enter a word or phrase to search: ', 'regex')

                elif choice == 'm':
                    current_menu = constants.MAIN_MENU