// ---
// jupyter:
//   jupytext:
//     text_representation:
//       extension: .cs
//       format_name: light
//       format_version: '1.5'
//       jupytext_version: 1.14.4
//   kernelspec:
//     display_name: .NET (C#)
//     language: C#
//     name: .net-csharp
// ---

#r "nuget:Microsoft.ML,1.4.0-preview"
#r "nuget:Microsoft.ML.AutoML"
#r "nuget:Microsoft.Data.DataFrame,0.1.1-e190920-1"

using Microsoft.Data;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.AutoML;

using Microsoft.AspNetCore.Html;
Formatter<DataFrame>.Register((df, writer) =>
{
    var headers = new List<IHtmlContent>();
    headers.Add(th(i("index")));
    headers.AddRange(df.Columns.Select(c => (IHtmlContent) th(c)));
    var rows = new List<List<IHtmlContent>>();
    var take = 10;
    for (var i = 0; i < Math.Min(take, df.RowCount); i++)
    {
        var cells = new List<IHtmlContent>();
        cells.Add(td(i));
        foreach (var obj in df[i])
        {
            cells.Add(td(obj));
        }
        rows.Add(cells);
    }
    
    var t = table(
        thead(
            headers),
        tbody(
            rows.Select(
                r => tr(r))));
    
    writer.Write(t);
}, "text/html");

var data = DataFrame.ReadCsv("./housing.csv");
data

data.Description()

data = data.DropNulls()

// +
var context = new MLContext();

var experiment = context.Auto().CreateRegressionExperiment(maxExperimentTimeInSeconds: 10);

var result = experiment.Execute((IDataView)data, labelColumnName:"median_house_value");
// -

result.BestRun.TrainerName

result.BestRun.ValidationMetrics.RSquared

StarcoderdataJupyterScriptsDedupFiltered