Exemplo n.º 1
0
def precomp_prediction(data_train, data_test, outfile, lamb=0.3):
    lin_l = LinearLearner(lamb)
    lin_c = lin_l(data_train)

    out_file = open(outfile, "wt")
    for row in data_test:
        out_file.write(lpputils.tsadd(row[DEP_IDX], lin_c(row)) + "\n")
    out_file.close()
Exemplo n.º 2
0
def comp_prediction(data_train, data_test, outfile, lamb=0.3):
    lin_l = LineSpecificLearner(LinearLearner(lamb))
    lin_c = lin_l(data_train)

    #rf_l = LineSpecificLearner(RFRegressorLearner())
    #rf_c = rf_l(data_train)

    out_file = open(outfile, "wt")
    for row in data_test:
        out_file.write(lpputils.tsadd(row[DEP_IDX], lin_c(row)) + "\n")
    out_file.close()
Exemplo n.º 3
0
def comp_prediction_neural(data_train, data_test, outfile):
    X_train, y_train = prepare_NN_data(data_train, False)
    X_test, _ = prepare_NN_data(data_test, True)

    mlpr = MLPRegressor(hidden_layer_sizes=(300,),activation='tanh')
    mlpr.fit(X_train,y_train)
    pred = mlpr.predict(X_test)

    print("Mreza narejena ....")

    out_file = open(outfile, "wt")
    st = 0
    for row in data_test:
        out_file.write(lpputils.tsadd(row[DEP_IDX],pred[st]) + "\n")
        st += 1
    out_file.close()
Exemplo n.º 4
0
    else:
        linije[primer[3]] = [primer]

linearna_regresija = linear.LinearLearner()
for linija in linije.keys():
    x, y = zgradi_matrike(linije[linija], True)
    linije[linija] = linearna_regresija(x, y)

f = gzip.open("test.csv.gz", "rt",
              encoding="latin1")  #za izpis MAE spremeni v "train.csv.gz"
vrstica = csv.reader(f, delimiter="\t")
next(vrstica)
ime, dejanski_cas, primeri, testni_X = zgradi_matrike(vrstica, False)

datoteka = open("napovedi_tekmovanje.txt", "wt", encoding="latin1")

mae_mesec = 11
mae = 0
stevilo_primerov = 0

for vrstica in range(len(primeri)):
    napoved = lpputils.tsadd(primeri[vrstica],
                             -linije[ime[vrstica]](testni_X[vrstica]))
    datoteka.write(napoved + "\n")
    if lpputils.parsedate(primeri[vrstica]).month == mae_mesec:
        mae += absolute_error(dejanski_cas[vrstica], napoved)
        stevilo_primerov += 1
datoteka.close()
if mae != 0:
    print("Mean absolute error:", mae / stevilo_primerov)
class AverageTripClassifier(object):
    def __init__(self, mean):
        self.mean = mean

    def __call__(self, x):
        # does not use the input example at all, because
        # in this case the prediction is always the same
        return self.mean


if __name__ == "__main__":

    f = gzip.open("train_pred.csv.gz", "rt")
    reader = csv.reader(f, delimiter="\t")
    next(reader)
    data = [d for d in reader]

    l = AverageTripLearner()
    c = l(data)

    f = gzip.open("test_pred.csv.gz", "rt")
    reader = csv.reader(f, delimiter="\t")
    next(reader)  # skip legend

    fo = open("naloga3.txt", "wt")
    for l in reader:
        print(l[-3])
        fo.write(lpputils.tsadd(l[-3], c(l)) + "\n")
    fo.close()
Exemplo n.º 6
0
import gzip
import csv
import lpputils

f = gzip.open("test_pred.csv.gz", "rt")
reader = csv.reader(f, delimiter="\t")
next(reader)  #skip legend

fo = open("polurniki.txt", "wt")
for l in reader:
    fo.write(lpputils.tsadd(l[-3], 30 * 60) + "\n")
fo.close()
        dejanski_cas = []
        for d in reader:
            originalen_datum.append(d[-3])
            dejanski_cas.append(d[-1])
            x.append(napolni_x(d, prazniki))
        X = linear.append_ones(np.array(x))
        return dejanski_cas, originalen_datum, X


X, Y = zgradi_matrike("train_pred.csv.gz", True)

linearna_regresija = linear.LinearLearner()
predikcijski_model = linearna_regresija(X, Y)

dejanski_cas, primeri, testni_X = zgradi_matrike(
    "test_pred.csv.gz", False)  #za izpis MAE spremeni v "train_pred.csv.gz"
mae_mesec = 11  #MAE za november
mae = 0
stevilo_primerov = 0
datoteka = open("napovedi.txt", "wt", encoding="latin1")
for vrstica in range(len(primeri)):
    napoved = lpputils.tsadd(primeri[vrstica],
                             -predikcijski_model(testni_X[vrstica]))
    datoteka.write(napoved + "\n")
    if lpputils.parsedate(primeri[vrstica]).month == mae_mesec:
        mae += absolute_error(dejanski_cas[vrstica], napoved)
        stevilo_primerov += 1
datoteka.close()
if mae != 0:
    print("Mean absolute error:", mae / stevilo_primerov)