liveBook · Manning

Wine dataset

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

The wine dataset is a labeled collection of 178 wine-cultivar samples represented by chemical-analysis attributes and belonging to three cultivars.

The wine dataset contains 178 Italian wine-cultivar samples. Each row has a cultivar label from 1 to 3 and 13 chemical-analysis parameters, making it a multiclass classification dataset. section 7.6

A neural-network experiment uses the dataset as follows:

  • Parse the CSV label separately from its 13 numeric parameters and encode cultivars as three-element classifications. section 7.6
  • Configure a network with 13 input neurons and three output neurons; one tested configuration uses seven hidden neurons and a 0.9 learning rate. section 7.6
  • Train on the first 150 shuffled samples for five passes, then validate on the remaining 28. section 7.6

Classification result

The network maps the largest output value to cultivar 1, 2, or 3 and reports 27 correct classifications out of 28, or 96.4285714285714%. section 7.6

/// assumes all rows are of equal length
/// and feature scale each column to be in the range 0–1
func normalizeByFeatureScaling(dataset: inout [[Double]]) {
    for colNum in 0..<dataset[0].count {
        let column = dataset.map { $0[colNum] }
        let maximum = column.max()!
        let minimum = column.min()!
        for rowNum in 0..<dataset.count {
            dataset[rowNum][colNum] = (dataset[rowNum][colNum]
             - minimum) / (maximum - minimum)
        }
    }
}

Normalize each feature column to the range 0–1 before using the numeric parameters. section 7.6

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Explains dataset layout, parsing, network dimensions, training split, validation, and output interpretation without detailing neural-network internals.
Examples
Uses raw CSV rows, Swift parsing functions, a 13–7–3 network, and a 150/28 training-validation split.
What it assumes
Assumes familiarity with CSV data and neural-network training while demonstrating the dataset-specific parsing from its layout.
What you can do after
Apply it via a neural network to classify wine samples into three integer-coded cultivars.
How it connects
Connects CSV parsing, feature scaling, neural networks, classification, training, and validation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.