Naive Bayes Regression Using C#

I put together a demo of an old regression technique called naive Bayes regression. Naive Bayes regression is essentially a variation of basic linear regression.

In simple linear regression, there is a single predictor variable x, and a single target variable y to predict. For example, you might want to predict a person’s income (y) from their age (x). Using a set of training data, you might get a prediction equation like y = (10.2 * x) + 3.57 where 10.2 is the regression coefficient and the 3.57 is the regression constant.

Now suppose you have a regression problem with two or more predictor variables. For example, you might want to predict a person’s income (y) from their age (x0), height (x1), and years of work experience (x2). In naive Bayes regression, you’d predict income from age, and predict income from height, and predict income from years of work experience. To generate the final predicted income, you’d compute the average of the three predicted income values.

In most problem scenarios, naive Bayes regression is much less accurate than other techniques and is therefore best used as a baseline for comparison with other regression techniques. That said however, in some problem scenarios, naive Bayes regression is surprisingly effective.

The demo program begins by loading a subset of the well-known Wine Dataset into memory. The data looks like:

7.4;0.7;0;1.9;0.076;11;34;0.9978;3.51;0.56;9.4;5
7.8;0.88;0;2.6;0.098;25;67;0.9968;3.2;0.68;9.8;5
7.8;0.76;0.04;2.3;0.092;15;54;0.997;3.26;0.65;9.8;5
11.2;0.28;0.56;1.9;0.075;17;60;0.998;3.16;0.58;9.8;6
. . .

There are 200 training items and 40 test items. Each line represents a glass of red wine. There are 12 semicolon-separated values on each line. The goal of the demo program is to predict the value in the first column from the values in the remaining 11 columns. Note: I used the Wine Dataset instead of one of my more usual synthetic datasets because the Wine Dataset is one of the relatively few datasets where naive Bayes works well.

The output of the demo program is:

Begin naive Bayes regression
Predict fixed acidity from volatile acidity, citric acid, etc.

Loading train (200) and test (40) data
Done

First five train X:
  0.7000  0.0000  1.9000  . . .  9.4000  5.0000
  0.8800  0.0000  2.6000  . . .  9.8000  5.0000
  0.7600  0.0400  2.3000  . . .  9.8000  5.0000
  0.2800  0.5600  1.9000  . . .  9.8000  6.0000
  0.7000  0.0000  1.9000  . . .  9.4000  5.0000

First five train y:
  7.4000
  7.8000
  7.8000
 11.2000
  7.4000

Creating and training naive Bayes regression model
Done

Evaluating model
Accuracy train (within 0.15) = 0.8550
Accuracy test (within 0.15) = 0.8000

Predicting for x =
  0.7000  0.0000  1.9000  . . .  9.4000  5.0000

predictor[ 0] : pred y = 7.4869
predictor[ 1] : pred y = 7.0785
predictor[ 2] : pred y = 7.5916
predictor[ 3] : pred y = 7.5403
predictor[ 4] : pred y = 7.5417
predictor[ 5] : pred y = 7.5447
predictor[ 6] : pred y = 8.2576
predictor[ 7] : pred y = 6.8554
predictor[ 8] : pred y = 7.4776
predictor[ 9] : pred y = 7.7879
predictor[10] : pred y = 7.5722

Predicted y = 7.5213

End demo

Because naive Bayes regression is based on simple linear regression, in order to understand naive Bayes regression, you must understand simple linear regression. The basic simple linear regression technique is perhaps best understood by looking at a concrete example. Suppose that you have a set of data with only five items:

x     y
-------
3.5   8
1.5   4
4.5  10
1.5   5
2.5   6

You want to find the value of the coefficient a, and the constant b, so that the sum of squared differences between predicted y’ = (a * x) + b and the actual y values, is minimized. There are several closed form solutions. One version, used by the demo program, first computes the sums of x, y, (x * x), (y * y), and (x * y):

  x     y   (x * x)  (y * y)  (x * y)
------------------------------------
 3.5    8    12.25      64      28
 1.5    4     2.25      16       6
 4.5   10    20.25     100      45
 1.5    4     2.25      16       6
 2.5    6     6.25      36      15
------------------------------------
13.5   32    43.25     232     100

Then, if n = 5 is the number of items, and Sx, Sy, Sxx, Syy, and Sxy represent the sums:

denom = (n * Sxx) - (Sx * x)
      = (5 * 13.5) - (13.5 * 13.5)
      = 34.0

coeff = a = ((n * Sxy) - (Sx * Sy)) / denom
          = ((5 * 100) - (13.5 * 32)) / 34.0
          = 68.0 / 34.0
          = 2.0

const = b = ((Sy * Sxx) - (Sx * Sxy)) / denom
          = ((32 * 43.25) - (13.5 * 100)) / 34.0
          = 34.0 / 34.0
          = 1.0

Note that this tiny artificial example is simplified in the sense that each data item can be predicted perfectly using the equation y’ = (2.0 * x) + 1.0. When working with real-life data, the training data cannot predicted perfectly.



Playboy Magazine issues of the 1960s through the 1980s were famous for their cartoons. A common theme was a scenario with a very naive (but not Bayesian) woman. Famous cartoonists with distinctive styles included Erich Sokol, Phil Interlandi, and John Dempsey.

Left: By artist Erich Sokol (1933-2003). “Sometimes I think I’d like to move to another city where the definition of ‘pure’ is a bit more variable.”

Center: By artist Phil Interlandi (1924-2002). “Do you mean to sit there on your cute Exhibit A and say you didn’t encourage him?”

Right: By artist John Dempsey (1919-2002). “You were right. I needed to get out of my Freudian slip.”

The humor of these old cartoons hasn’t really held up very well. I suspect that humor is very sensitive to current social contexts. I think it’s interesting that these artists all died within months of each other.


Demo program. Replace “lt” (less than), “gt”, “lte”, “gte” with Boolean operator symbols. (My blog editor often chokes on symbols).

using System;
using System.IO;
using System.Collections.Generic;

namespace NaiveBayesRegression
{
  internal class NaiveBayesRegressionProgram
  {
    static void Main(string[] args)
    {
      Console.WriteLine("\nBegin naive Bayes regression ");
      Console.WriteLine("Predict red wine fixed acidity" +
        " from volatile acidity, citric acid, etc. ");

      // 1. load data
      Console.WriteLine("\nLoading train (200) " +
        "and test (40) data");

      string trainFile =
        "..\\..\\..\\Data\\wine_train_200.txt";
      int[] colsX = new int[] { 1, 2, 3, 4, 5, 6,
        7, 8, 9, 10, 11 };
      double[][] trainX =
        MatLoad(trainFile, colsX, ';', "#");
      double[] trainY =
        MatToVec(MatLoad(trainFile,
        new int[] { 0 }, ';', "#"));

      string testFile =
        "..\\..\\..\\Data\\wine_test_40.txt";
      double[][] testX =
        MatLoad(testFile, colsX, ';', "#");
      double[] testY =
        MatToVec(MatLoad(testFile,
        new int[] { 0 }, ';', "#"));
      Console.WriteLine("Done ");

      Console.WriteLine("\nFirst five train X: ");
      for (int i = 0; i "lt" 5; ++i)
        VecShow(trainX[i], 4, 8);

      Console.WriteLine("\nFirst five train y: ");
      for (int i = 0; i "lt" 5; ++i)
        Console.WriteLine(trainY[i].ToString("F4").
          PadLeft(8));

      // 2. create and train model
     Console.WriteLine("\nCreating and training" +
        " naive Bayes regression model ");
      NaiveBayesRegressor model =
        new NaiveBayesRegressor();
      model.Train(trainX, trainY);
      Console.WriteLine("Done ");

      // 3. evaluate model
      Console.WriteLine("\nEvaluating model ");
      double accTrain = model.Accuracy(trainX, trainY, 0.15);
      Console.WriteLine("Accuracy train (within 0.15) = " +
        accTrain.ToString("F4"));
      double accTest = model.Accuracy(testX, testY, 0.15);
      Console.WriteLine("Accuracy test (within 0.15) = " +
        accTest.ToString("F4"));

      // 4. use model
      double[] x = trainX[0];
      Console.WriteLine("\nPredicting for x = ");
      VecShow(x, 4, 8);
      double predY = model.Predict(x, verbose:true);
      Console.WriteLine("\nPredicted y = " +
        predY.ToString("F4"));

      Console.WriteLine("\nEnd demo ");
      Console.ReadLine();
    } // Main()

    // ------------------------------------------------------
    // helpers for Main()
    // ------------------------------------------------------

    static double[][] MatLoad(string fn, int[] usecols,
      char sep, string comment)
    {
      List"lt"double[]"gt" result = new List"lt"double[]"gt"();
      string line = "";
      FileStream ifs = new FileStream(fn, FileMode.Open);
      StreamReader sr = new StreamReader(ifs);
      while ((line = sr.ReadLine()) != null)
      {
        if (line.StartsWith(comment) == true)
          continue;
        string[] tokens = line.Split(sep);
        List"lt"double"gt" lst = new List"lt"double"gt"();
        for (int j = 0; j "lt" usecols.Length; ++j)
          lst.Add(double.Parse(tokens[usecols[j]]));
        double[] row = lst.ToArray();
        result.Add(row);
      }
      sr.Close(); ifs.Close();
      return result.ToArray();
    }

    static double[] MatToVec(double[][] mat)
    {
      int nRows = mat.Length;
      int nCols = mat[0].Length;
      double[] result = new double[nRows * nCols];
      int k = 0;
      for (int i = 0; i "lt" nRows; ++i)
        for (int j = 0; j "lt" nCols; ++j)
          result[k++] = mat[i][j];
      return result;
    }

    static void VecShow(double[] vec, int dec, int wid)
    {
      for (int i = 0; i "lt" vec.Length; ++i)
        Console.Write(vec[i].ToString("F" + dec).
          PadLeft(wid));
      Console.WriteLine("");
    }

  } // class Program

  // ========================================================

  public class NaiveBayesRegressor
  {
    public double[] coefs;  // one per predictor
    public double[] constants;

    public NaiveBayesRegressor()
    {
      return;
    }

    public void Train(double[][] trainX, double[] trainY)
    {
      // compute coef and const for each column/predictor
      int n = trainX.Length;
      int dim = trainX[0].Length;
      this.coefs = new double[dim];
      this.constants = new double[dim];

      for (int j = 0; j "lt" dim; ++j)  // each predictor
      {
        double Sx = 0.0;  // sum x values
        double Sy = 0.0;  // sum y values
        double Sxx = 0.0; // sum x^2 values
        double Syy = 0.0; // sum y^2 values
        double Sxy = 0.0; // sum x*y values

        for (int i = 0; i "lt" n; ++i)
        {
          Sx += trainX[i][j];
          Sy += trainY[i];
          Sxx += (trainX[i][j] * trainX[i][j]);
          Syy += (trainY[i] * trainY[i]);
          Sxy += (trainX[i][j] * trainY[i]);
        }

        double denom = (n * Sxx) - (Sx * Sx);
        double coef = ((n * Sxy) - (Sx * Sy)) / denom;
        double constant = ((Sy * Sxx) - (Sx * Sxy)) / denom;
      
        this.coefs[j] = coef;
        this.constants[j] = constant;
      } // j
    } // Train()

    public double Predict(double[] x, bool verbose = false)
    {
      int dim = x.Length;
      double[] predY = new double[dim]; // one per feature
      double sumPredY = 0.0;

      if (verbose == true) Console.WriteLine("");
      for (int j = 0; j "lt" dim; ++j)
      {
        predY[j] = (x[j] * this.coefs[j]) + this.constants[j];
        if (verbose == true)
          Console.WriteLine("predictor[" +
            j.ToString().PadLeft(2) + "] : pred y = " +
            predY[j].ToString("F4"));
        sumPredY += predY[j];
      }
      return sumPredY / dim;
    }

    public double Accuracy(double[][] dataX, double[] dataY,
      double pctClose)
    {
      int numCorrect = 0; int numWrong = 0;
      for (int i = 0; i "lt" dataX.Length; ++i)
      {
        double actualY = dataY[i];
        double predY = this.Predict(dataX[i]);
        if (Math.Abs(predY - actualY) "lt"
          (pctClose * actualY))
          ++numCorrect;
        else
          ++numWrong;
      }
      return (numCorrect * 1.0) / (numWrong + numCorrect);
    }

  } // class NaiveBayesRegressor

} // ns

Training data:

# wine_train_200.txt
#
# "fixed acidity";"volatile acidity";"citric acid";
# "residual sugar";"chlorides";"free sulfur dioxide";
# "total sulfur dioxide";"density";"pH";"sulphates";
# "alcohol";"quality"
# https://archive.ics.uci.edu/dataset/186/wine+quality
# 
7.4;0.7;0;1.9;0.076;11;34;0.9978;3.51;0.56;9.4;5
7.8;0.88;0;2.6;0.098;25;67;0.9968;3.2;0.68;9.8;5
7.8;0.76;0.04;2.3;0.092;15;54;0.997;3.26;0.65;9.8;5
11.2;0.28;0.56;1.9;0.075;17;60;0.998;3.16;0.58;9.8;6
7.4;0.7;0;1.9;0.076;11;34;0.9978;3.51;0.56;9.4;5
7.4;0.66;0;1.8;0.075;13;40;0.9978;3.51;0.56;9.4;5
7.9;0.6;0.06;1.6;0.069;15;59;0.9964;3.3;0.46;9.4;5
7.3;0.65;0;1.2;0.065;15;21;0.9946;3.39;0.47;10;7
7.8;0.58;0.02;2;0.073;9;18;0.9968;3.36;0.57;9.5;7
7.5;0.5;0.36;6.1;0.071;17;102;0.9978;3.35;0.8;10.5;5
6.7;0.58;0.08;1.8;0.097;15;65;0.9959;3.28;0.54;9.2;5
7.5;0.5;0.36;6.1;0.071;17;102;0.9978;3.35;0.8;10.5;5
5.6;0.615;0;1.6;0.089;16;59;0.9943;3.58;0.52;9.9;5
7.8;0.61;0.29;1.6;0.114;9;29;0.9974;3.26;1.56;9.1;5
8.9;0.62;0.18;3.8;0.176;52;145;0.9986;3.16;0.88;9.2;5
8.9;0.62;0.19;3.9;0.17;51;148;0.9986;3.17;0.93;9.2;5
8.5;0.28;0.56;1.8;0.092;35;103;0.9969;3.3;0.75;10.5;7
8.1;0.56;0.28;1.7;0.368;16;56;0.9968;3.11;1.28;9.3;5
7.4;0.59;0.08;4.4;0.086;6;29;0.9974;3.38;0.5;9;4
7.9;0.32;0.51;1.8;0.341;17;56;0.9969;3.04;1.08;9.2;6
8.9;0.22;0.48;1.8;0.077;29;60;0.9968;3.39;0.53;9.4;6
7.6;0.39;0.31;2.3;0.082;23;71;0.9982;3.52;0.65;9.7;5
7.9;0.43;0.21;1.6;0.106;10;37;0.9966;3.17;0.91;9.5;5
8.5;0.49;0.11;2.3;0.084;9;67;0.9968;3.17;0.53;9.4;5
6.9;0.4;0.14;2.4;0.085;21;40;0.9968;3.43;0.63;9.7;6
6.3;0.39;0.16;1.4;0.08;11;23;0.9955;3.34;0.56;9.3;5
7.6;0.41;0.24;1.8;0.08;4;11;0.9962;3.28;0.59;9.5;5
7.9;0.43;0.21;1.6;0.106;10;37;0.9966;3.17;0.91;9.5;5
7.1;0.71;0;1.9;0.08;14;35;0.9972;3.47;0.55;9.4;5
7.8;0.645;0;2;0.082;8;16;0.9964;3.38;0.59;9.8;6
6.7;0.675;0.07;2.4;0.089;17;82;0.9958;3.35;0.54;10.1;5
6.9;0.685;0;2.5;0.105;22;37;0.9966;3.46;0.57;10.6;6
8.3;0.655;0.12;2.3;0.083;15;113;0.9966;3.17;0.66;9.8;5
6.9;0.605;0.12;10.7;0.073;40;83;0.9993;3.45;0.52;9.4;6
5.2;0.32;0.25;1.8;0.103;13;50;0.9957;3.38;0.55;9.2;5
7.8;0.645;0;5.5;0.086;5;18;0.9986;3.4;0.55;9.6;6
7.8;0.6;0.14;2.4;0.086;3;15;0.9975;3.42;0.6;10.8;6
8.1;0.38;0.28;2.1;0.066;13;30;0.9968;3.23;0.73;9.7;7
5.7;1.13;0.09;1.5;0.172;7;19;0.994;3.5;0.48;9.8;4
7.3;0.45;0.36;5.9;0.074;12;87;0.9978;3.33;0.83;10.5;5
7.3;0.45;0.36;5.9;0.074;12;87;0.9978;3.33;0.83;10.5;5
8.8;0.61;0.3;2.8;0.088;17;46;0.9976;3.26;0.51;9.3;4
7.5;0.49;0.2;2.6;0.332;8;14;0.9968;3.21;0.9;10.5;6
8.1;0.66;0.22;2.2;0.069;9;23;0.9968;3.3;1.2;10.3;5
6.8;0.67;0.02;1.8;0.05;5;11;0.9962;3.48;0.52;9.5;5
4.6;0.52;0.15;2.1;0.054;8;65;0.9934;3.9;0.56;13.1;4
7.7;0.935;0.43;2.2;0.114;22;114;0.997;3.25;0.73;9.2;5
8.7;0.29;0.52;1.6;0.113;12;37;0.9969;3.25;0.58;9.5;5
6.4;0.4;0.23;1.6;0.066;5;12;0.9958;3.34;0.56;9.2;5
5.6;0.31;0.37;1.4;0.074;12;96;0.9954;3.32;0.58;9.2;5
8.8;0.66;0.26;1.7;0.074;4;23;0.9971;3.15;0.74;9.2;5
6.6;0.52;0.04;2.2;0.069;8;15;0.9956;3.4;0.63;9.4;6
6.6;0.5;0.04;2.1;0.068;6;14;0.9955;3.39;0.64;9.4;6
8.6;0.38;0.36;3;0.081;30;119;0.997;3.2;0.56;9.4;5
7.6;0.51;0.15;2.8;0.11;33;73;0.9955;3.17;0.63;10.2;6
7.7;0.62;0.04;3.8;0.084;25;45;0.9978;3.34;0.53;9.5;5
10.2;0.42;0.57;3.4;0.07;4;10;0.9971;3.04;0.63;9.6;5
7.5;0.63;0.12;5.1;0.111;50;110;0.9983;3.26;0.77;9.4;5
7.8;0.59;0.18;2.3;0.076;17;54;0.9975;3.43;0.59;10;5
7.3;0.39;0.31;2.4;0.074;9;46;0.9962;3.41;0.54;9.4;6
8.8;0.4;0.4;2.2;0.079;19;52;0.998;3.44;0.64;9.2;5
7.7;0.69;0.49;1.8;0.115;20;112;0.9968;3.21;0.71;9.3;5
7.5;0.52;0.16;1.9;0.085;12;35;0.9968;3.38;0.62;9.5;7
7;0.735;0.05;2;0.081;13;54;0.9966;3.39;0.57;9.8;5
7.2;0.725;0.05;4.65;0.086;4;11;0.9962;3.41;0.39;10.9;5
7.2;0.725;0.05;4.65;0.086;4;11;0.9962;3.41;0.39;10.9;5
7.5;0.52;0.11;1.5;0.079;11;39;0.9968;3.42;0.58;9.6;5
6.6;0.705;0.07;1.6;0.076;6;15;0.9962;3.44;0.58;10.7;5
9.3;0.32;0.57;2;0.074;27;65;0.9969;3.28;0.79;10.7;5
8;0.705;0.05;1.9;0.074;8;19;0.9962;3.34;0.95;10.5;6
7.7;0.63;0.08;1.9;0.076;15;27;0.9967;3.32;0.54;9.5;6
7.7;0.67;0.23;2.1;0.088;17;96;0.9962;3.32;0.48;9.5;5
7.7;0.69;0.22;1.9;0.084;18;94;0.9961;3.31;0.48;9.5;5
8.3;0.675;0.26;2.1;0.084;11;43;0.9976;3.31;0.53;9.2;4
9.7;0.32;0.54;2.5;0.094;28;83;0.9984;3.28;0.82;9.6;5
8.8;0.41;0.64;2.2;0.093;9;42;0.9986;3.54;0.66;10.5;5
8.8;0.41;0.64;2.2;0.093;9;42;0.9986;3.54;0.66;10.5;5
6.8;0.785;0;2.4;0.104;14;30;0.9966;3.52;0.55;10.7;6
6.7;0.75;0.12;2;0.086;12;80;0.9958;3.38;0.52;10.1;5
8.3;0.625;0.2;1.5;0.08;27;119;0.9972;3.16;1.12;9.1;4
6.2;0.45;0.2;1.6;0.069;3;15;0.9958;3.41;0.56;9.2;5
7.8;0.43;0.7;1.9;0.464;22;67;0.9974;3.13;1.28;9.4;5
7.4;0.5;0.47;2;0.086;21;73;0.997;3.36;0.57;9.1;5
7.3;0.67;0.26;1.8;0.401;16;51;0.9969;3.16;1.14;9.4;5
6.3;0.3;0.48;1.8;0.069;18;61;0.9959;3.44;0.78;10.3;6
6.9;0.55;0.15;2.2;0.076;19;40;0.9961;3.41;0.59;10.1;5
8.6;0.49;0.28;1.9;0.11;20;136;0.9972;2.93;1.95;9.9;6
7.7;0.49;0.26;1.9;0.062;9;31;0.9966;3.39;0.64;9.6;5
9.3;0.39;0.44;2.1;0.107;34;125;0.9978;3.14;1.22;9.5;5
7;0.62;0.08;1.8;0.076;8;24;0.9978;3.48;0.53;9;5
7.9;0.52;0.26;1.9;0.079;42;140;0.9964;3.23;0.54;9.5;5
8.6;0.49;0.28;1.9;0.11;20;136;0.9972;2.93;1.95;9.9;6
8.6;0.49;0.29;2;0.11;19;133;0.9972;2.93;1.98;9.8;5
7.7;0.49;0.26;1.9;0.062;9;31;0.9966;3.39;0.64;9.6;5
5;1.02;0.04;1.4;0.045;41;85;0.9938;3.75;0.48;10.5;4
4.7;0.6;0.17;2.3;0.058;17;106;0.9932;3.85;0.6;12.9;6
6.8;0.775;0;3;0.102;8;23;0.9965;3.45;0.56;10.7;5
7;0.5;0.25;2;0.07;3;22;0.9963;3.25;0.63;9.2;5
7.6;0.9;0.06;2.5;0.079;5;10;0.9967;3.39;0.56;9.8;5
8.1;0.545;0.18;1.9;0.08;13;35;0.9972;3.3;0.59;9;6
8.3;0.61;0.3;2.1;0.084;11;50;0.9972;3.4;0.61;10.2;6
7.8;0.5;0.3;1.9;0.075;8;22;0.9959;3.31;0.56;10.4;6
8.1;0.545;0.18;1.9;0.08;13;35;0.9972;3.3;0.59;9;6
8.1;0.575;0.22;2.1;0.077;12;65;0.9967;3.29;0.51;9.2;5
7.2;0.49;0.24;2.2;0.07;5;36;0.996;3.33;0.48;9.4;5
8.1;0.575;0.22;2.1;0.077;12;65;0.9967;3.29;0.51;9.2;5
7.8;0.41;0.68;1.7;0.467;18;69;0.9973;3.08;1.31;9.3;5
6.2;0.63;0.31;1.7;0.088;15;64;0.9969;3.46;0.79;9.3;5
8;0.33;0.53;2.5;0.091;18;80;0.9976;3.37;0.8;9.6;6
8.1;0.785;0.52;2;0.122;37;153;0.9969;3.21;0.69;9.3;5
7.8;0.56;0.19;1.8;0.104;12;47;0.9964;3.19;0.93;9.5;5
8.4;0.62;0.09;2.2;0.084;11;108;0.9964;3.15;0.66;9.8;5
8.4;0.6;0.1;2.2;0.085;14;111;0.9964;3.15;0.66;9.8;5
10.1;0.31;0.44;2.3;0.08;22;46;0.9988;3.32;0.67;9.7;6
7.8;0.56;0.19;1.8;0.104;12;47;0.9964;3.19;0.93;9.5;5
9.4;0.4;0.31;2.2;0.09;13;62;0.9966;3.07;0.63;10.5;6
8.3;0.54;0.28;1.9;0.077;11;40;0.9978;3.39;0.61;10;6
7.8;0.56;0.12;2;0.082;7;28;0.997;3.37;0.5;9.4;6
8.8;0.55;0.04;2.2;0.119;14;56;0.9962;3.21;0.6;10.9;6
7;0.69;0.08;1.8;0.097;22;89;0.9959;3.34;0.54;9.2;6
7.3;1.07;0.09;1.7;0.178;10;89;0.9962;3.3;0.57;9;5
8.8;0.55;0.04;2.2;0.119;14;56;0.9962;3.21;0.6;10.9;6
7.3;0.695;0;2.5;0.075;3;13;0.998;3.49;0.52;9.2;5
8;0.71;0;2.6;0.08;11;34;0.9976;3.44;0.53;9.5;5
7.8;0.5;0.17;1.6;0.082;21;102;0.996;3.39;0.48;9.5;5
9;0.62;0.04;1.9;0.146;27;90;0.9984;3.16;0.7;9.4;5
8.2;1.33;0;1.7;0.081;3;12;0.9964;3.53;0.49;10.9;5
8.1;1.33;0;1.8;0.082;3;12;0.9964;3.54;0.48;10.9;5
8;0.59;0.16;1.8;0.065;3;16;0.9962;3.42;0.92;10.5;7
6.1;0.38;0.15;1.8;0.072;6;19;0.9955;3.42;0.57;9.4;5
8;0.745;0.56;2;0.118;30;134;0.9968;3.24;0.66;9.4;5
5.6;0.5;0.09;2.3;0.049;17;99;0.9937;3.63;0.63;13;5
5.6;0.5;0.09;2.3;0.049;17;99;0.9937;3.63;0.63;13;5
6.6;0.5;0.01;1.5;0.06;17;26;0.9952;3.4;0.58;9.8;6
7.9;1.04;0.05;2.2;0.084;13;29;0.9959;3.22;0.55;9.9;6
8.4;0.745;0.11;1.9;0.09;16;63;0.9965;3.19;0.82;9.6;5
8.3;0.715;0.15;1.8;0.089;10;52;0.9968;3.23;0.77;9.5;5
7.2;0.415;0.36;2;0.081;13;45;0.9972;3.48;0.64;9.2;5
7.8;0.56;0.19;2.1;0.081;15;105;0.9962;3.33;0.54;9.5;5
7.8;0.56;0.19;2;0.081;17;108;0.9962;3.32;0.54;9.5;5
8.4;0.745;0.11;1.9;0.09;16;63;0.9965;3.19;0.82;9.6;5
8.3;0.715;0.15;1.8;0.089;10;52;0.9968;3.23;0.77;9.5;5
5.2;0.34;0;1.8;0.05;27;63;0.9916;3.68;0.79;14;6
6.3;0.39;0.08;1.7;0.066;3;20;0.9954;3.34;0.58;9.4;5
5.2;0.34;0;1.8;0.05;27;63;0.9916;3.68;0.79;14;6
8.1;0.67;0.55;1.8;0.117;32;141;0.9968;3.17;0.62;9.4;5
5.8;0.68;0.02;1.8;0.087;21;94;0.9944;3.54;0.52;10;5
7.6;0.49;0.26;1.6;0.236;10;88;0.9968;3.11;0.8;9.3;5
6.9;0.49;0.1;2.3;0.074;12;30;0.9959;3.42;0.58;10.2;6
8.2;0.4;0.44;2.8;0.089;11;43;0.9975;3.53;0.61;10.5;6
7.3;0.33;0.47;2.1;0.077;5;11;0.9958;3.33;0.53;10.3;6
9.2;0.52;1;3.4;0.61;32;69;0.9996;2.74;2.0;9.4;4
7.5;0.6;0.03;1.8;0.095;25;99;0.995;3.35;0.54;10.1;5
7.5;0.6;0.03;1.8;0.095;25;99;0.995;3.35;0.54;10.1;5
7.1;0.43;0.42;5.5;0.07;29;129;0.9973;3.42;0.72;10.5;5
7.1;0.43;0.42;5.5;0.071;28;128;0.9973;3.42;0.71;10.5;5
7.1;0.43;0.42;5.5;0.07;29;129;0.9973;3.42;0.72;10.5;5
7.1;0.43;0.42;5.5;0.071;28;128;0.9973;3.42;0.71;10.5;5
7.1;0.68;0;2.2;0.073;12;22;0.9969;3.48;0.5;9.3;5
6.8;0.6;0.18;1.9;0.079;18;86;0.9968;3.59;0.57;9.3;6
7.6;0.95;0.03;2;0.09;7;20;0.9959;3.2;0.56;9.6;5
7.6;0.68;0.02;1.3;0.072;9;20;0.9965;3.17;1.08;9.2;4
7.8;0.53;0.04;1.7;0.076;17;31;0.9964;3.33;0.56;10;6
7.4;0.6;0.26;7.3;0.07;36;121;0.9982;3.37;0.49;9.4;5
7.3;0.59;0.26;7.2;0.07;35;121;0.9981;3.37;0.49;9.4;5
7.8;0.63;0.48;1.7;0.1;14;96;0.9961;3.19;0.62;9.5;5
6.8;0.64;0.1;2.1;0.085;18;101;0.9956;3.34;0.52;10.2;5
7.3;0.55;0.03;1.6;0.072;17;42;0.9956;3.37;0.48;9;4
6.8;0.63;0.07;2.1;0.089;11;44;0.9953;3.47;0.55;10.4;6
7.5;0.705;0.24;1.8;0.36;15;63;0.9964;3;1.59;9.5;5
7.9;0.885;0.03;1.8;0.058;4;8;0.9972;3.36;0.33;9.1;4
8;0.42;0.17;2;0.073;6;18;0.9972;3.29;0.61;9.2;6
8;0.42;0.17;2;0.073;6;18;0.9972;3.29;0.61;9.2;6
7.4;0.62;0.05;1.9;0.068;24;42;0.9961;3.42;0.57;11.5;6
7.3;0.38;0.21;2;0.08;7;35;0.9961;3.33;0.47;9.5;5
6.9;0.5;0.04;1.5;0.085;19;49;0.9958;3.35;0.78;9.5;5
7.3;0.38;0.21;2;0.08;7;35;0.9961;3.33;0.47;9.5;5
7.5;0.52;0.42;2.3;0.087;8;38;0.9972;3.58;0.61;10.5;6
7;0.805;0;2.5;0.068;7;20;0.9969;3.48;0.56;9.6;5
8.8;0.61;0.14;2.4;0.067;10;42;0.9969;3.19;0.59;9.5;5
8.8;0.61;0.14;2.4;0.067;10;42;0.9969;3.19;0.59;9.5;5
8.9;0.61;0.49;2;0.27;23;110;0.9972;3.12;1.02;9.3;5
7.2;0.73;0.02;2.5;0.076;16;42;0.9972;3.44;0.52;9.3;5
6.8;0.61;0.2;1.8;0.077;11;65;0.9971;3.54;0.58;9.3;5
6.7;0.62;0.21;1.9;0.079;8;62;0.997;3.52;0.58;9.3;6
8.9;0.31;0.57;2;0.111;26;85;0.9971;3.26;0.53;9.7;5
7.4;0.39;0.48;2;0.082;14;67;0.9972;3.34;0.55;9.2;5
7.7;0.705;0.1;2.6;0.084;9;26;0.9976;3.39;0.49;9.7;5
7.9;0.5;0.33;2;0.084;15;143;0.9968;3.2;0.55;9.5;5
7.9;0.49;0.32;1.9;0.082;17;144;0.9968;3.2;0.55;9.5;5
8.2;0.5;0.35;2.9;0.077;21;127;0.9976;3.23;0.62;9.4;5
6.4;0.37;0.25;1.9;0.074;21;49;0.9974;3.57;0.62;9.8;6
6.8;0.63;0.12;3.8;0.099;16;126;0.9969;3.28;0.61;9.5;5
7.6;0.55;0.21;2.2;0.071;7;28;0.9964;3.28;0.55;9.7;5
7.6;0.55;0.21;2.2;0.071;7;28;0.9964;3.28;0.55;9.7;5
7.8;0.59;0.33;2;0.074;24;120;0.9968;3.25;0.54;9.4;5
7.3;0.58;0.3;2.4;0.074;15;55;0.9968;3.46;0.59;10.2;5
11.5;0.3;0.6;2;0.067;12;27;0.9981;3.11;0.97;10.1;6
5.4;0.835;0.08;1.2;0.046;13;93;0.9924;3.57;0.85;13;7
6.9;1.09;0.06;2.1;0.061;12;31;0.9948;3.51;0.43;11.4;4

Test data:

# wine_test_40.txt
#
9.6;0.32;0.47;1.4;0.056;9;24;0.99695;3.22;0.82;10.3;7
8.8;0.37;0.48;2.1;0.097;39;145;0.9975;3.04;1.03;9.3;5
6.8;0.5;0.11;1.5;0.075;16;49;0.99545;3.36;0.79;9.5;5
7;0.42;0.35;1.6;0.088;16;39;0.9961;3.34;0.55;9.2;5
7;0.43;0.36;1.6;0.089;14;37;0.99615;3.34;0.56;9.2;6
12.8;0.3;0.74;2.6;0.095;9;28;0.9994;3.2;0.77;10.8;7
12.8;0.3;0.74;2.6;0.095;9;28;0.9994;3.2;0.77;10.8;7
7.8;0.57;0.31;1.8;0.069;26;120;0.99625;3.29;0.53;9.3;5
7.8;0.44;0.28;2.7;0.1;18;95;0.9966;3.22;0.67;9.4;5
11;0.3;0.58;2.1;0.054;7;19;0.998;3.31;0.88;10.5;7
9.7;0.53;0.6;2;0.039;5;19;0.99585;3.3;0.86;12.4;6
8;0.725;0.24;2.8;0.083;10;62;0.99685;3.35;0.56;10;6
11.6;0.44;0.64;2.1;0.059;5;15;0.998;3.21;0.67;10.2;6
8.2;0.57;0.26;2.2;0.06;28;65;0.9959;3.3;0.43;10.1;5
7.8;0.735;0.08;2.4;0.092;10;41;0.9974;3.24;0.71;9.8;6
7;0.49;0.49;5.6;0.06;26;121;0.9974;3.34;0.76;10.5;5
8.7;0.625;0.16;2;0.101;13;49;0.9962;3.14;0.57;11;5
8.1;0.725;0.22;2.2;0.072;11;41;0.9967;3.36;0.55;9.1;5
7.5;0.49;0.19;1.9;0.076;10;44;0.9957;3.39;0.54;9.7;5
7.8;0.53;0.33;2.4;0.08;24;144;0.99655;3.3;0.6;9.5;5
7.8;0.34;0.37;2;0.082;24;58;0.9964;3.34;0.59;9.4;6
7.4;0.53;0.26;2;0.101;16;72;0.9957;3.15;0.57;9.4;5
6.8;0.61;0.04;1.5;0.057;5;10;0.99525;3.42;0.6;9.5;5
8.6;0.645;0.25;2;0.083;8;28;0.99815;3.28;0.6;10;6
8.4;0.635;0.36;2;0.089;15;55;0.99745;3.31;0.57;10.4;4
7.7;0.43;0.25;2.6;0.073;29;63;0.99615;3.37;0.58;10.5;6
8.9;0.59;0.5;2;0.337;27;81;0.9964;3.04;1.61;9.5;6
9;0.82;0.14;2.6;0.089;9;23;0.9984;3.39;0.63;9.8;5
7.7;0.43;0.25;2.6;0.073;29;63;0.99615;3.37;0.58;10.5;6
6.9;0.52;0.25;2.6;0.081;10;37;0.99685;3.46;0.5;11;5
5.2;0.48;0.04;1.6;0.054;19;106;0.9927;3.54;0.62;12.2;7
8;0.38;0.06;1.8;0.078;12;49;0.99625;3.37;0.52;9.9;6
8.5;0.37;0.2;2.8;0.09;18;58;0.998;3.34;0.7;9.6;6
6.9;0.52;0.25;2.6;0.081;10;37;0.99685;3.46;0.5;11;5
8.2;1;0.09;2.3;0.065;7;37;0.99685;3.32;0.55;9;6
7.2;0.63;0;1.9;0.097;14;38;0.99675;3.37;0.58;9;6
7.2;0.63;0;1.9;0.097;14;38;0.99675;3.37;0.58;9;6
7.2;0.645;0;1.9;0.097;15;39;0.99675;3.37;0.58;9.2;6
7.2;0.63;0;1.9;0.097;14;38;0.99675;3.37;0.58;9;6
8.2;1;0.09;2.3;0.065;7;37;0.99685;3.32;0.55;9;6
This entry was posted in Machine Learning. Bookmark the permalink.

Leave a Reply