Salary Prediction. Stage 5/5

Deal with negative predictions

Report a typo

Description

A linear model may predict negative values. However, such values can be meaningless because the salary can't be negative. In this stage, handle negative predictions.

Objectives

  1. Read the data. For downloading the dataset refer to Stage 1;
  2. Load data with pandas.read_csv;
  3. As predictors select those variables that gave the best metric in the previous stage. Make X a DataFrame with predictors and y a series with a target. To make X, drop target variable from the data.
  4. Split predictors and the target into train and test parts. Use test_size=0.3 and random_state=100 — they guarantee that the results will be the same as the test system expects.
  5. Fit the model that predicts salary based on all other variables;
  6. Predict the salaries.
  7. Try two techniques to deal with negative predictions:
    • replace the negative values with 0;
    • replace the negative values with the median of the training part of y.
  8. Calculate the MAPE for every two options and print the best as a floating number rounded to five decimal places.

Example

Example 1: program output

0.00001
Write a program
IDE integration
Checking the IDE status

Create a free account to access the full topic