Exemple #1
0
rmseLevels = {}
maeLevels = {}
rLevels = {}
fac2Levels = {}
nmseLevels = {}
fbLevels = {}
rsLevels = {}
mgLevels = {}
vgLevels = {}

for method in methods:
    print("Method: " + method)
    rmse = rmseEval(observations[method], predictions[method])[1]
    print("\trmse: " + str(rmse))
    mae = maeEval(observations[method], predictions[method])[1]
    print("\tmae: " + str(mae))
    r = correlationEval(observations[method], predictions[method])[1]
    print("\tr: " + str(r))
    print("\tr2: " +
          str(rsquaredEval(observations[method], predictions[method])[1]))
    print("\tr2: " + str(r2_score(observations[method], predictions[method])))
    fac2 = fac2Eval(observations[method], predictions[method])
    print("\tfac2: " + str(fac2))
    print("\tmg: " + str(mgEval(observations[method], predictions[method])))
    nmse = nmse_from_paper(observations[method], predictions[method])
    print("\tnmse: " + str(nmse))
    fb = fbEval(observations[method], predictions[method])[1]
    print("\tfb: " + str(fb))
    rs = evalRandomScatter(observations[method], predictions[method])
    print("\trandom_scatter: " + str(rs))
            modelledData.append(float('nan'))
        d = datetime(timestamp.year, timestamp.month, timestamp.day, timestamp.hour)
        datesList.append(d)
        if timestamp.key not in aqData or str(loc) not in aqData[timestamp.key]:
            aqDataStation.append(NAN)
        else:
            aqDataStation.append(aqData[timestamp.key][str(loc)])
            observed.append(aqData[timestamp.key][str(loc)])
            if timestamp.key in finalData and loc in finalData[timestamp.key]:
                predicted.append(finalData[timestamp.key][loc])
            else:
                predicted.append(float('nan'))            
    
    if len(predicted) > 0: 
        rmse = rmseEval(predicted, observed)
        mae = maeEval(predicted, observed)
        #r = correlationEval(predicted, observed)
#     print("r: " + str(r))
#     print("RMSE: " + str(rmse))
#     print("MAE: " + str(mae))
         
    fig = plt.figure(None, figsize=(15, 9))
    ax = fig.add_subplot(111)
    hfmt = dates.DateFormatter('%d/%m/%Y %H:%M')
    ax.xaxis.set_major_formatter(hfmt)
    if len(predicted) > 0:
        ax.plot_date(datesList, modelledData, '-', color="b", label="Modelled (RMSE:" + str(rmse[1])[0:5] + ",MAE:" + str(mae[1])[0:5] + ")")
    else:
        ax.plot_date(datesList, modelledData, '-', color="b", label="Modelled")
    ax.plot_date(datesList, aqDataStation, '-', color="r", label="Observed")
    ax.legend()
Exemple #3
0
for v in values:
    sName = stationNames[str(v)]
    print("location: " + str(v) + " -> " + sName)
    trainData, testData = splitDataForXValidation(v, "location", data)
    trainColumns = []
    for c in trainData:
        if c != "target":
            trainColumns.append(c)

    model = trainRandomForest(trainData, trainColumns, "target", {
        'estimators': 59,
        'leaf': 9
    })
    predictionData = applyRandomForest(testData, model, 0)
    eval1 = maeEval(testData["target"], predictionData)
    eval2 = maeDistribution(testData["target"], predictionData, 50)
    eval3 = maeDistribution2(testData["target"], predictionData, 50)
    eval4 = reDistribution(testData["target"], predictionData)
    eval5 = reDistribution2(testData["target"], predictionData)
    doGraph(eval2[1], "No2 hourly AE (MAE: " + str(eval1[1]) + ") @ " + sName,
            "AE (ug/m3)", OUTPUT_DIRECTORY + "ae_" + sName + ".png")
    doGraph2(50, eval3[1],
             "No2 hourly error (MAE: " + str(eval1[1]) + ") @ " + sName,
             "error (ug/m3)", OUTPUT_DIRECTORY + "e_" + sName + ".png")
    doGraph3(eval4[1], "No2 hourly RAE @ " + sName, "absolute relative error",
             OUTPUT_DIRECTORY + "rae_" + sName + ".png")
    doGraph4(eval5[1], "No2 hourly RE @ " + sName, "relative error",
             OUTPUT_DIRECTORY + "re_" + sName + ".png")

    for i in range(0, len(eval2[1])):
Exemple #4
0
    predictions = []

    for timestamp in ospm:
        if timestamp not in obs:
            continue
        pred = ospm[timestamp]
        o = obs[timestamp]

        observations.append(o)
        predictions.append(pred)

        c = c + 1
        obs_avg = obs_avg + o
        pred_avg = pred_avg + pred

    pred_avg = pred_avg / float(c)
    obs_avg = obs_avg / float(c)
    print("location: " + str(station))
    print("\tcounter: " + str(c))
    print("\tpred_avg: " + str(pred_avg))
    print("\tobs_avg: " + str(obs_avg))
    observationPerStation.append(obs_avg)
    predictionPerStation.append(pred_avg)
    rmse = rmseEval(observations, predictions)[1]
    print("\tRMSE: " + str(rmse))

rmse = rmseEval(observationPerStation, predictionPerStation)[1]
print("RMSE: " + str(rmse))
mae = maeEval(observationPerStation, predictionPerStation)[1]
print("MAE: " + str(mae))