[Python] Prediction on new data after pickling on regression model

Discussão em 'Python' iniciado por Stack, Agosto 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have created ridge regression model to predict sales of an item say X. My final model contains around 180 features. I have pickled this model and now I want to see how model I created is performing on new data set containing same features as present in different model but on different timeframe. I have to pass entire new dataset(dataframe) into existing model and check relevant score say r-square or any other score relevant to regression model.

    Below is the code I'm using:

    # loading library
    import pickle

    with open('ridge_model', 'wb') as p:
    pickle.dump(ridge, p)

    y_test = df.pop('Target')
    x_test = df

    # load saved model
    with open('ridge_model' , 'rb') as p:
    new_reg = pickle.load(p)

    r_squared = new_reg.score(x_test,y_test)
    print(r-squared)


    Here ridge is the regression model I created

    df is the new data on which prediction needs to be done

    y_test contains target variable x_test contains features in dataset except target variable

    I want to understand:


    1. Can we pass entire new data set onto existing model for prediction and see how model is performing or not?


    2. r_squared = new_reg.score(x_test,y_test) in this line does .score calculates r-square as calculated on existing model or any other score it calculates?

    Continue reading...

Compartilhe esta Página