Skip to content

Instantly share code, notes, and snippets.

@thezaza101
Created October 25, 2020 23:27
Show Gist options
  • Save thezaza101/9564597254c34410f4b8fd97f6188673 to your computer and use it in GitHub Desktop.
Save thezaza101/9564597254c34410f4b8fd97f6188673 to your computer and use it in GitHub Desktop.
Medium_ML.NET ShowData.cs
public void ShowData(IDataView data, int colWidth = 15, int numRows = 10)
{
var previewObject = data.Preview(numRows);
int NumberOfColumns = previewObject.ColumnView.Length;
string output ="";
int rowWidth = (NumberOfColumns*(colWidth-1));
for (int i = 0; i < NumberOfColumns; i++)
{
output += ColValue(previewObject.ColumnView[i].Column.Name.ToString()) + '|';
}
output += Environment.NewLine;
output += new String('-', rowWidth).ToString();
output += MakeRows();
string MakeRows()
{
string outRow = "";
foreach (DataDebuggerPreview.RowInfo row in previewObject.RowView)
{
outRow += Environment.NewLine;
foreach (var item in row.Values){
outRow += ColValue(item.Value.ToString())+ '|';
}
}
return outRow;
}
string ColValue(string value, char fill = ' ')
{
int valLength = value.Length;
string valueToWrite = "";
if (valLength > colWidth-4)
{
valueToWrite = value.Substring(0,colWidth-4);
}
else
{
if(valLength%2==0)
{
int numspaces = ((colWidth-4) - valLength)/2;
valueToWrite = (new String(fill, numspaces)) + value + (new String(fill, numspaces));
}
else
{
int numspaces = ((colWidth-4) - valLength-1)/2;
valueToWrite = (new String(' ', numspaces)) + value + (new String(' ', numspaces))+" ";
}
}
return " "+valueToWrite+" ";
}
System.Console.WriteLine(output);
}
/*useage
ShowData(_trainData);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment