Implement the phi transformation to generate polynomial features from input data. Given a feature vector and a degree, produce the expanded feature vector containing all polynomial terms up to the specified degree.
def phi_transform(x, degree):
result = []
for d in range(1, degree + 1):
for val in x:
result.append(val ** d)
return result