Skip to content

Instantly share code, notes, and snippets.

@Belgian-Coder
Last active Jan 12, 2019
Embed
What would you like to do?
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