<jupyter_start><jupyter_text>Create a type that represents our data:<jupyter_code>[<CLIMutable>]
type AbaloneData =
    {
        [<LoadColumn(0)>]
        Sex : string

        [<LoadColumn(1)>]
        Length : float32

        [<LoadColumn(2)>]
        Diameter : float32

        [<LoadColumn(3)>]
        Height : float32

        [<LoadColumn(4)>]
        WholeWeight : float32

        [<LoadColumn(5)>]
        ShuckedWeight : float32

        [<LoadColumn(6)>]
        VisceraWeight : float32

        [<LoadColumn(7)>]
        ShellWeight : float32

        [<LoadColumn(8)>]
        Rings : single
    }<jupyter_output><empty_output><jupyter_text>Download the data from [UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/machine-learning-databases/abalone):<jupyter_code>if not <| File.Exists("abalone.data") then
    use client = new WebClient()
    client.DownloadFile("https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data", "abalone.data")

File.ReadLines("abalone.data")
|> Seq.take 5<jupyter_output><empty_output><jupyter_text>Create a new MLContext:<jupyter_code>let context = new MLContext()<jupyter_output><empty_output><jupyter_text>Read the data in the file:<jupyter_code>let dataView = context.Data.LoadFromTextFile<AbaloneData>("abalone.data", hasHeader = false, separatorChar = ',')<jupyter_output><empty_output><jupyter_text>Create a One-Hot Encoder:<jupyter_code>let encoder = context.Transforms.Categorical.OneHotEncoding(inputColumnName = "Sex", outputColumnName = "EncodedSex")<jupyter_output><empty_output><jupyter_text>Create a transformer and fit it to the data:<jupyter_code>let transformer = encoder.Fit(dataView)
let transformedDataView = transformer.Transform(dataView)<jupyter_output><empty_output><jupyter_text>Create a type to hold the value and its encoding:<jupyter_code>[<CLIMutable>]
type SexEncoding =
    {
        Sex : string
        EncodedSex : single[]
    }<jupyter_output><empty_output><jupyter_text>Encode the data and randomly select 10 examples:<jupyter_code>let encodedLabels = context.Data.CreateEnumerable<SexEncoding>(transformedDataView, reuseRowObject = false)
let rand = new Random()
    
encodedLabels
|> Seq.sortBy (fun _ -> rand.Next())
|> Seq.take 10<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1220472440944882, 'fraction_numerical': 0.012248468941382326, 'mean_word_length': 4.619164619164619, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 50, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '137330', 'license': 'MIT', 'n_tokens_mistral': 794, 'n_tokens_neox': 748, 'n_words': 131, 'path': 'One-Hot Encoding - F#.ipynb', 'repo_name': 'rvernagus/simple-ml.net-examples', 'size': '2286'}