Skip to content

Instantly share code, notes, and snippets.

@mdfarragher
Created November 8, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdfarragher/a41971907f1ddb08418028096d706a92 to your computer and use it in GitHub Desktop.
Save mdfarragher/a41971907f1ddb08418028096d706a92 to your computer and use it in GitHub Desktop.
/// <summary>
/// The main program class.
/// </summary>
public class Program
{
// filenames for data set
private static string dataPath = Path.Combine(Environment.CurrentDirectory, "spam.tsv");
/// <summary>
/// The main program entry point.
/// </summary>
/// <param name="args">The command line parameters.</param>
static void Main(string[] args)
{
// set up a machine learning context
var context = new MLContext();
// load the spam dataset in memory
Console.WriteLine("Loading data...");
var data = context.Data.LoadFromTextFile<SpamData>(
path: dataPath,
hasHeader: true,
separatorChar: '\t');
// use 80% for training and 20% for testing
var partitions = context.Data.TrainTestSplit(data, testFraction: 0.3);
// set up a pipeline to featurize the text
Console.WriteLine("Featurizing text...");
var pipeline = context.Transforms.Text.FeaturizeText(
outputColumnName: "Features",
inputColumnName: nameof(SpamData.Message));
// the rest of the code goes here...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment