示例#1
0
def test_regression_metrics():
    logger.info("Testeando métricas de evaluación para regresión...")
    # Ejemplos para testear regresión
    dim = 100  # Tamaño del muestreo
    x = np.linspace(-4, 4, dim)  # Eje x
    clean = np.sinc(x)  # Función sinc (labels)
    np.random.seed(123)
    noise = np.random.uniform(0, 0.1, dim)  # Ruido para ensuciar la sinc (error en la predicción)
    signal = clean + noise  # Señal resultante del ruido aditivo (predict)
    metrics = RegressionMetrics(zip(signal, clean))

    assert np.allclose(metrics.r2(), 0.9708194315829859, rtol=1e-4)
    assert np.allclose(metrics.explained_variance(), 0.9943620888461356, rtol=1e-4)
    assert np.allclose(metrics.mse(), 0.0031164269743473839, rtol=1e-4)
    assert np.allclose(metrics.rmse(), 0.0558249673027, rtol=1e-4)
    assert np.allclose(metrics.mae(), 0.0501428880, rtol=1e-4)
    assert np.allclose(metrics.rmae(), 0.2239260770, rtol=1e-4)
    logger.info("OK")
示例#2
0
hits_valid = neural_net.fit(train,
                            valid,
                            valid_iters=1,
                            mini_batch=20,
                            parallelism=0,
                            stops=global_stops,
                            optimizer_params=optimizer_params,
                            measure='R2',
                            keep_best=True,
                            reproducible=False)
hits_test, predict = neural_net.evaluate(test, predictions=True)

logger.info("Hits en test: %12.11f", hits_test)

# --4) Evaluacion de desempeño

logger.info("Metricas de evaluación en clasificacion: ")
labels = map(lambda lp: float(lp.label), test.collect())
metrics = RegressionMetrics(zip(predict, labels))
print "MSE: ", metrics.mse()
print "RMSE: ", metrics.rmse()
print "MAE: ", metrics.mae()
print "RMAE: ", metrics.rmae()
print "R-cuadrado: ", metrics.r2()
print "Explained Variance: ", metrics.explained_variance()
print zip(predict, labels)[:10]

# --5) Ploteos

plot_fitting(neural_net)
示例#3
0
logger.info("Configuracion usada: %s", os.linesep+str(net_params))

# -- 3) Construcción y ajuste de red neuronal

neural_net = NeuralNetwork(net_params)

logger.info("Entrenando red neuronal ...")
hits_valid = neural_net.fit(train, valid, valid_iters=1, mini_batch=20, parallelism=0,
                            stops=global_stops, optimizer_params=optimizer_params, measure='R2',
                            keep_best=True, reproducible=False)
hits_test, predict = neural_net.evaluate(test, predictions=True)

logger.info("Hits en test: %12.11f", hits_test)

# --4) Evaluacion de desempeño

logger.info("Metricas de evaluación en clasificacion: ")
labels = map(lambda lp: float(lp.label), test.collect())
metrics = RegressionMetrics(zip(predict, labels))
print "MSE: ", metrics.mse()
print "RMSE: ", metrics.rmse()
print "MAE: ", metrics.mae()
print "RMAE: ", metrics.rmae()
print "R-cuadrado: ", metrics.r2()
print "Explained Variance: ", metrics.explained_variance()
print zip(predict, labels)[:10]

# --5) Ploteos

plot_fitting(neural_net)