-
-
Save mdfarragher/fc00028624cbc2f968cc6fcc7c37ba1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// step 4: one-hot encode the longitude | |
var pipeline3 = pipeline2.Append(context.Transforms.Categorical.OneHotEncoding( | |
inputColumnName: "BinnedLongitude", | |
outputColumnName: "EncodedLongitude" | |
)) | |
// step 5: one-hot encode the latitude | |
.Append(context.Transforms.Categorical.OneHotEncoding( | |
inputColumnName: "BinnedLatitude", | |
outputColumnName: "EncodedLatitude" | |
)) | |
// step 6: cross the two one-hot encoded columns | |
.Append(context.Transforms.CustomMapping<FromLocation, ToLocation>( | |
(input, output) => { | |
output.Location = new float[input.EncodedLongitude.Length * input.EncodedLatitude.Length]; | |
var index = 0; | |
for (var i = 0; i < input.EncodedLongitude.Length; i++) | |
for (var j = 0; j < input.EncodedLatitude.Length; j++) | |
output.Location[index++] = input.EncodedLongitude[i] * input.EncodedLatitude[j]; | |
}, | |
contractName: "Location" | |
)) | |
// step 7: remove all the columns we don't need anymore | |
.Append(context.Transforms.DropColumns( | |
"MedianHouseValue", | |
"Longitude", | |
"Latitude", | |
"BinnedLongitude", | |
"BinnedLatitude", | |
"EncodedLongitude", | |
"EncodedLatitude" | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment