Exemple #1
0
def main():
    for z in range(1, 7):
        # Get file name
        file_name = join("instances", "instance{0}.txt".format(z))
        print("\n{0} file : {1}".format(z, file_name))

        # Read file data
        number_of_items, weight_constraint, items = get_data(file=file_name)

        # Display number of lines, weight and the volume
        print("\nNumber of Items:{0}, Weight constraint:{1}\n".format(number_of_items,
                                                                      weight_constraint))

        # Initialize item class
        item_object = Items(items=items)

        # Constants
        initial_temperature = 10000
        cooling_rate = 0.75
        iteration = 5
        epoch = 3
        termination_criteria = 0.001
        acceptance_criterion = 0.90

        sa_object = SA(items=items,
                       number_of_items=number_of_items,
                       item_object=item_object,
                       weight_constraint=weight_constraint,
                       initial_temperature=initial_temperature,
                       cooling_rate=cooling_rate,
                       iteration=iteration,
                       epoch=epoch,
                       termination_criteria=termination_criteria,
                       acceptance_criterion=acceptance_criterion)

        # Randomly initialed solution
        sa_object.first_improvement(initial_solution=sa_object.initial_solution)
Exemple #2
0
import pickle

# constants
dataset_version = "data"
print_topX = 10
print_report = True
print_cm = False
save_fig = True
show_fig = False
use_comps = False
use_ab = True
use_ti = True
test_percent = 0.25
scoring = "precision"

(feature_names_comps, feature_names_ab, feature_names_ti, X_comps, X_ab, X_ti, y) = get_data(dataset_version)


# <codecell>

############################################################################
# extract features via chi2
# assemble X_train, X_test, and feature_names
print("assembling features")
t0 = time()

(X_c_train, X_c_test, X_ab_train, X_ab_test, X_ti_train, X_ti_test, y_train, y_test) = train_test_split(
    X_comps, X_ab, X_ti, y, test_size=test_percent
)

feature_names = []
Exemple #3
0
    print()
    clf_descr = str(clf).split('(')[0]
    return clf_descr, score, train_time, test_time, clf, pred

# <codecell>

for select_chi2 in select_chi2s:

    # <codecell>

    ################################################################################
    # load data

    (feature_names_comps, feature_names_ab,
     feature_names_ti, X_comps, X_ab, X_ti, y) = get_data(dataset_version)


    # <codecell>

    ############################################################################
    # extract features via chi2
    # assemble X_train, X_test, and feature_names
    print("assembling features")
    t0 = time()

    (X_c_train, X_c_test, X_ab_train, X_ab_test, X_ti_train, X_ti_test,
     y_train, y_test) = train_test_split(X_comps, X_ab, X_ti, y,
                                         test_size=test_percent)

    feature_names = []
import methods
import config
import datetime

data_set = 'records.txt'
records_list = methods.get_data(data_set)

while True:
    methods.message()
    try:
        s = input('Choose action: ')

        if s == '1':
            phone_list = methods.get_bank_list(records_list)
            cards = methods.get_my_cards_list(records_list)

            k = 1
            for p in phone_list:
                current_funds = methods.get_account_states(records_list, p)
                try:
                    print(
                        str(k) + '. *' + cards[k - 1] + ' (' +
                        config.banks[p] + ') : {money} USD'.format(
                            money=methods.get_account_states(records_list, p)))
                    k = k + 1
                except KeyError as ke:
                    print(
                        str(k) + '. *' + cards[k - 1] + ' (Bank' + str(k) +
                        ') : {money} USD'.format(
                            money=methods.get_account_states(records_list, p)))
                    k = k + 1
Exemple #5
0
    print()
    clf_descr = str(clf).split('(')[0]
    return clf_descr, score, train_time, test_time, clf, pred


# <codecell>

for select_chi2 in select_chi2s:

    # <codecell>

    ################################################################################
    # load data

    (feature_names_comps, feature_names_ab, feature_names_ti, X_comps, X_ab,
     X_ti, y) = get_data(dataset_version)

    # <codecell>

    ############################################################################
    # extract features via chi2
    # assemble X_train, X_test, and feature_names
    print("assembling features")
    t0 = time()

    (X_c_train, X_c_test, X_ab_train, X_ab_test, X_ti_train, X_ti_test,
     y_train, y_test) = train_test_split(X_comps,
                                         X_ab,
                                         X_ti,
                                         y,
                                         test_size=test_percent)
Exemple #6
0
categories = ["1"]

bm = Benchmarker(print_topX, print_report, print_cm)


def benchmark(clf):
    return bm.benchmark(clf)


# <codecell>

################################################################################
# load data

feature_names_comps, feature_names_tfidf, X_train_comps, X_train_tfidf, X_test_comps, X_test_tfidf, y_train, y_test = get_data(
    dataset_version)

# <codecell>

################################################################################
# extract features via chi2
# assemble X_train, X_test, and feature_names

# if select_chi2:
print("Extracting %d best features by a chi-squared test" % select_chi2)
t0 = time()
ch2 = SelectKBest(chi2, k=select_chi2)
X_train_ch2 = ch2.fit_transform(X_train_tfidf, y_train)
X_train = hstack([X_train_comps, X_train_ch2])
X_test_ch2 = ch2.transform(X_test_tfidf)
X_test = hstack([X_test_comps, X_test_ch2])
Exemple #7
0
print_cm=False
save_fig=True

categories = ["1"]

bm = Benchmarker(print_topX, print_report, print_cm)

def benchmark(clf):
    return bm.benchmark(clf)

# <codecell>

################################################################################
# load data

feature_names_comps, feature_names_tfidf, X_train_comps, X_train_tfidf, X_test_comps, X_test_tfidf, y_train, y_test = get_data(dataset_version)


# <codecell>

################################################################################
# extract features via chi2
# assemble X_train, X_test, and feature_names

# if select_chi2:
print("Extracting %d best features by a chi-squared test" %
      select_chi2)
t0 = time()
ch2 = SelectKBest(chi2, k=select_chi2)
X_train_ch2 = ch2.fit_transform(X_train_tfidf, y_train)
X_train = hstack([X_train_comps, X_train_ch2])
Exemple #8
0
from hashtag import Hashtag
from methods import get_data

myHashtags = ('lodz')
for element in myHashtags:
    newHashtag = Hashtag(element)
    request = get_data(newHashtag)
#  result = put_dictionary(newHashtag)
#  print_dictionary(result)