Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-113

Lag-1 Difference Feature

Problem

Build the lag-1 difference feature: x_i - x_{i-1} for i >= 1.

Return [] when there are fewer than two values.

Hint

Each output element is the change from the previous step.

Test cases

case 1
in: [[1,3,6,10]]
expected: [2,3,4]
case 2
in: [[5]]
expected: []
case 3
in: [[2,2,2]]
expected: [0,0]
case 4
in: [[]]
expected: []
Starter codePython
def difference_feature(values):
    # Your code here
    pass

4 test cases · run your code against them in the editor