Skip to content

Instantly share code, notes, and snippets.

@Belgian-Coder
Last active January 12, 2019 22:11
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 Belgian-Coder/2fae84093101af1654cb35d4492b1a05 to your computer and use it in GitHub Desktop.
Save Belgian-Coder/2fae84093101af1654cb35d4492b1a05 to your computer and use it in GitHub Desktop.
Ordina-ML.Net_Recommender_System
using BookRecommenderShared.Configuration;
using Microsoft.ML;
using Microsoft.ML.Data;
using System;
using System.IO;
namespace BookRecommenderTrainer
{
class Program
{
static void Main(string[] args)
{
var mlContext = new MLContext();
var reader = mlContext.Data.CreateTextReader(new TextLoader.Arguments()
{
Separator = ",",
HasHeader = true,
/*
* Define the columns to read be from the csv.
* The indeces are based on the position in the csv file and will receive a new index.
* DataKind is defined as R4 (floating point) instead of integer
* Computers are optimized for processing floating point calculations
* so this will not create performance issues but mitigates some possible issues
*/
Column = new[]
{
new TextLoader.Column(Labels.Label, DataKind.R4, 1), // new index 0
new TextLoader.Column(Labels.User, DataKind.R4, 2), // new index 1
new TextLoader.Column(Labels.BookId, DataKind.R4, 3) // new index 2
}
});
var data = reader.Read(Path.Combine(Environment.CurrentDirectory, Filenames.DataFolder, Filenames.RatingsDataset));
// Split our dataset in 80% training data and 20% testing data to evaluate our model
var (trainData, testData) = mlContext.BinaryClassification.TrainTestSplit(data, testFraction: 0.2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment