Created
January 25, 2020 01:15
-
-
Save sudipto80/6ca71fe97e892d6f39ed1f5078b36687 to your computer and use it in GitHub Desktop.
Code to create ModelInput from CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
string csvFile = @"C:\MLDOTNET\iris.csv"; | |
var columns = File.ReadLines(csvFile) | |
.Take(1) | |
.First() | |
.Split(new char[] { ',' }); | |
var firstLine = File.ReadLines(csvFile) | |
.Skip(1) | |
.Take(1) | |
.First() | |
.Split(new char[] { ',' }); | |
StringBuilder propertyBuilder = new StringBuilder (); | |
for (int i = 0; i <columns.Length; i++) | |
{ | |
string column = columns[i]; | |
//[ColumnName("mpg"), LoadColumn(0)] | |
propertyBuilder.AppendLine($"[ColumnName(\"{column}\"), LoadColumn({i})]"); | |
if(firstLine.ElementAt(i).ToCharArray().All(m => Char.IsDigit(m) || m == '.')) | |
{ | |
propertyBuilder.AppendLine($"public float {column.Substring(0, 1).ToUpper() + column.Substring(1)}"); | |
} | |
else | |
{ | |
propertyBuilder.AppendLine($"public string {column.Substring(0, 1).ToUpper() + column.Substring(1)}"); | |
} | |
propertyBuilder.AppendLine("{ get; set; }"); | |
} | |
string classCode = @"public class ModelInput " + Environment.NewLine | |
+ "{" + Environment.NewLine + propertyBuilder.ToString() | |
+ Environment.NewLine + "}"; | |
Console.WriteLine(classCode); | |
} | |
// Define other methods and classes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment