private void Graph(string[] args, double[] x1, double[] y1, double[] x2, double[] y2, double[] x3, double[] y3) { string chartFileName = string.Empty; var pl = new PLStream(); if (args.Length == 1 && args[0] == "svg") { chartFileName = @"Logistic.svg"; pl.sdev("svg"); pl.sfnam("Logistic.svg"); } else { chartFileName = @"Logistic.png"; pl.sdev("pngcairo"); pl.sfnam("Logistic.png"); } pl.spal0("cmap0_alternate.pal"); pl.init(); const int xMin = -4; const int xMax = 4; const int yMin = -5; const int yMax = 20; pl.env(xMin, xMax, yMin, yMax, AxesScale.Independent, AxisBox.BoxTicksLabels); // Set scaling for mail title text 125% size of default pl.lab("X1", "X2", "Title"); pl.col0(3); pl.sym(x1, y1, (char)228); pl.col0(9); pl.sym(x2, y2, (char)228); pl.col0(2); pl.line(x3, y3); pl.eop(); pl.gver(out var verText); var p = new Process(); string chartFileNamePath = @".\" + chartFileName; p.StartInfo = new ProcessStartInfo(chartFileNamePath) { UseShellExecute = true }; p.Start(); }
static void ProcessData(MLContext context, IDataView data) { var houses = context.Data.CreateEnumerable <HouseBlockData>(data, reuseRowObject: false).ToArray(); // plot median house value by longitude var pl = new PLStream(); pl.sdev("pngcairo"); // png rendering pl.sfnam("data.png"); // output filename pl.spal0("cmap0_alternate.pal"); // alternate color palette pl.init(); pl.env( 0, 10, // x-axis range 0, 600000, // y-axis range AxesScale.Independent, // scale x and y independently AxisBox.BoxTicksLabelsAxes); // draw box, ticks, and num ticks pl.lab( "Median Income", // x-axis label "Median House Value", // y-axis label "House value by longitude"); // plot title pl.sym( houses.Select(h => (double)h.MedianIncome).ToArray(), houses.Select(h => (double)h.MedianHouseValue).ToArray(), (char)218 ); pl.eop(); }
static void PlotData(MLContext context, IDataView data) { var transactions = context.Data.CreateEnumerable <CreditCardData>(data, reuseRowObject: false).ToArray(); // plot median house value by longitude var pl = new PLStream(); pl.sdev("pngcairo"); // png rendering pl.sfnam("data.png"); // output filename pl.spal0("cmap0_alternate.pal"); // alternate color palette pl.init(); pl.env( 0, 5000, // x-axis range 0, 2500, // y-axis range AxesScale.Independent, // scale x and y independently AxisBox.BoxTicksLabelsAxes); // draw box, ticks, and num ticks pl.lab( "Time", // x-axis label "Amount", // y-axis label "Transactions by Time"); // plot title pl.sym( transactions.Select(txn => (double)txn.Time).ToArray(), transactions.Select(txn => (double)txn.Amount).ToArray(), (char)218 ); pl.eop(); }
private static void Graph(string[] args, double[] x, double[] y) { string chartFileName = string.Empty; var pl = new PLStream(); if (args.Length == 1 && args[0] == "svg") { chartFileName = @"KNN.svg"; pl.sdev("svg"); pl.sfnam("KNN.svg"); } else { chartFileName = @"KNN.png"; pl.sdev("pngcairo"); pl.sfnam("KNN.png"); } pl.spal0("cmap0_alternate.pal"); pl.init(); const int xMin = 0; const int xMax = 1; const int yMin = 0; const int yMax = 1; pl.env(xMin, xMax, yMin, yMax, AxesScale.Independent, AxisBox.BoxTicksLabelsAxes); pl.schr(0, 0.75); pl.lab("X-axis", "Y-axis", "Title"); pl.col0(3); pl.sym(x, y, (char)210); pl.eop(); pl.gver(out var verText); var p = new Process(); string chartFileNamePath = @".\" + chartFileName; p.StartInfo = new ProcessStartInfo(chartFileNamePath) { UseShellExecute = true }; p.Start(); }
/// <summary> /// The main program entry point. /// </summary> /// <param name="args">The command line arguments</param> static void Main(string[] args) { // create the machine learning context var context = new MLContext(); // load the dataset Console.WriteLine("Loading data..."); var data = context.Data.LoadFromTextFile <HouseBlockData>( path: dataPath, hasHeader: true, separatorChar: ','); // keep only records with a median house value < 500,000 data = context.Data.FilterRowsByColumn( data, "MedianHouseValue", upperBound: 499_999 ); // get an array of housing data var houses = context.Data.CreateEnumerable <HouseBlockData>(data, reuseRowObject: false).ToArray(); // plot median house value by longitude var pl = new PLStream(); pl.sdev("pngcairo"); // png rendering pl.sfnam("data.png"); // output filename pl.spal0("cmap0_alternate.pal"); // alternate color palette pl.init(); pl.env( 0, 10, // x-axis range 0, 600000, // y-axis range AxesScale.Independent, // scale x and y independently AxisBox.BoxTicksLabelsAxes); // draw box, ticks, and num ticks pl.lab( "Median Income", // x-axis label "Median House Value", // y-axis label "House value by longitude"); // plot title pl.sym( houses.Select(h => (double)h.MedianIncome).ToArray(), houses.Select(h => (double)h.MedianHouseValue).ToArray(), (char)218 ); pl.eop(); // build a data loading pipeline // step 1: divide the median house value by 1000 var pipeline = context.Transforms.CustomMapping <HouseBlockData, ToMedianHouseValue>( (input, output) => { output.NormalizedMedianHouseValue = input.MedianHouseValue / 1000; }, contractName: "MedianHouseValue" ); // get a 10-record preview of the transformed data // var model = pipeline.Fit(data); // var transformedData = model.Transform(data); // var preview = transformedData.Preview(maxRows: 10); // show the preview // WritePreview(preview); // step 2: bin the longitude var pipeline2 = pipeline.Append(context.Transforms.NormalizeBinning( inputColumnName: "Longitude", outputColumnName: "BinnedLongitude", maximumBinCount: 10 )) // step 3: bin the latitude .Append(context.Transforms.NormalizeBinning( inputColumnName: "Latitude", outputColumnName: "BinnedLatitude", maximumBinCount: 10 )) // step 4: one-hot encode the longitude .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 var pipeline3 = pipeline2.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" )); // get a 10-record preview of the transformed data var model = pipeline3.Fit(data); var transformedData = model.Transform(data); var preview = transformedData.Preview(maxRows: 10); // show the location vector //WritePreview(preview); WritePreviewColumn(preview, "Location"); }