[Python] What's the right way in handling target values for a regressor neural network?

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently handling a particular dataset:

    Brand Model Year Engine_Size Fuel_Type Transmission Mileage Doors Owner_Count Price
    Kia Rio 2020 4.2 Diesel Manual 289944 3 5 8501
    Chevrolet Malibu 2012 2.0 Hybrid Automatic 5356 2 3 12092
    Mercedes GLA 2020 4.2 Diesel Automatic 231440 4 2 11171
    Audi Q5 2023 2.0 Electric Manual 160971 2 1 11780
    Volkswagen Golf 2003 2.6 Hybrid Semi-Automatic 286618 3 3 2867
    Toyota Camry 2007 2.7 Petrol Automatic 157889 4 4 7242
    ...



    My goal here is to create a neural network that will perform regression based on the features.

    Based on what I've been reading before, you don't generally need to scale the target feature. But when I try that, my RMSE is very high:

    Epoch 631/1000
    25/25 ━━━━━━━━━━━━━━━━━━━━ 0s 3ms/step
    loss: 4282125.0000
    mse: 4282125.0000
    root_mean_squared_error: 2069.2246
    val_loss: 4227971.5000
    val_mse: 4227971.5000
    val_root_mean_squared_error: 2056.2031



    Then I read a few forum posts here that suggest that it may be beneficial to perform target scaling, which yielded promising results:

    Epoch 100/100
    25/25 ━━━━━━━━━━━━━━━━━━━━ 0s 3ms/step
    loss: 0.0141
    mse: 0.0141
    root_mean_squared_error: 0.1186
    val_loss: 0.0170
    val_mse: 0.0170
    val_root_mean_squared_error: 0.1305



    but after applying inverse_transform and calculating the RMSE again, the results are still pretty bad:

    Mscale = MinMaxScaler() ###I fitted my data to this scaler earlier in my notebook.
    ### I just added it here to show what scaler I used.

    pred = model_neural.predict(X_train_complete)
    pred_inv_scale = Mscale.inverse_transform(pred)
    y_test_split_inv = Mscale.inverse_transform(y_train_final)
    print(np.sqrt(mean_squared_error(y_test_split_inv, pred_inv_scale)))

    250/250 ━━━━━━━━━━━━━━━━━━━━ 0s 466us/step
    1988.584022180217



    And the results to me make sense, by scaling the target this way, I affect the distances between the predicted and true value; at a scale of [0,1] I understand that it's normal to see the RMSE be really small.

    I know that interpretation of RMSE is highly dependent on the data, but with the smallest value of my target being 2000, and the largest value being 18,000, I felt that an RMSE of around 2000 is pretty bad.

    Is there a proper way to actually perform regression on large target features? Should you even scale them at all?

    Continue reading...

Compartilhe esta Página