Search code examples
linear-regressionmse

How to show the MAE, MSE, and R2 in a tabular format using data frame for the linear regression model?


I have these, but I am not sure how I can show them in tabular format.

from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
LinearRegression_MAE = mean_squared_error(predictions, y_test)
LinearRegression_MSE = mean_absolute_error(predictions, y_test)
LinearRegression_R2 = r2_score(predictions, y_test)

Report = ?

Solution

  • Let's say LinarRegresion_MAE to MAE, LinearRegression_MSE to MSE, LinearRegression_R2 to R2. Firstly we create dict then we convert dict to dataframe.

        Report = {"Metrics":["MAE","MSE","R2"],"Result": 
        [LinearRegression_MAE,LinearRegression_MSE,LinearRegression_R2]}
        pd.DataFrame(Report)