Skip to content

Instantly share code, notes, and snippets.

@arikaa
Last active July 17, 2018 03:00
Show Gist options
  • Save arikaa/6188def4d49beb88604245010537d156 to your computer and use it in GitHub Desktop.
Save arikaa/6188def4d49beb88604245010537d156 to your computer and use it in GitHub Desktop.
3rd order polynomial transform
def thirdorder(data):
'''
3rd order polynomial transform of data
Arguments
data: The input data is assumed to have shape (:, 3). The first dimension represents
the total samples and the second dimension represents the total features.
Returns
result: A numpy array format of the new data with shape (:,10), where the feature
numbers are extended.
'''
# converting data to 3rd order polynomial - (1, x1,x2,x1^2,x1x2,x2^2,x1^3,x1^2x2,x1x2^2,x2^3)
dimension = data.shape[0]
new_data = []
for i in range(dimension):
x1 = data[i][0]
x2 = data[i][1]
new_row = [1, x1, x2, x1**2, x1*x2, x2**2, x1**3, x1**2 *x2, x1* x2**2, x2**3]
new_data.append(new_row)
final_data = np.array(new_data)
return final_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment