Last active
October 3, 2018 17:16
-
-
Save CESARDELATORRE/32a4a9aa9803bb0a57911f52c745159f to your computer and use it in GitHub Desktop.
ML.NET static API loading traing DataSet NOT from a file
This file contains 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
var dataReader = TextLoader.CreateReader(env, | |
c => ( | |
CustomerId: c.LoadText(0), | |
ProductId: c.LoadText(1), | |
Quantity: c.LoadFloat(2), | |
Label: c.LoadBool(3)), | |
separator: ',', hasHeader: true); | |
FieldAwareFactorizationMachinePredictor pred = null; | |
var ctx = new BinaryClassificationContext(env); | |
var est = dataReader.MakeNewEstimator() | |
.Append(row => (CustomerId_OHE: row.CustomerId.OneHotEncoding(), ProductId_OHE: row.ProductId.OneHotEncoding(), row.Label)) | |
.Append(row => (Features: row.CustomerId_OHE.ConcatWith(row.ProductId_OHE), row.Label)) | |
.Append(row => (row.Label, | |
preds: ctx.Trainers.FieldAwareFactorizationMachine( | |
row.Label, | |
new[] { row.Features }, | |
advancedSettings: ffmArguments => ffmArguments.Shuffle = false, | |
onFit: p => pred = p))); | |
// NO NEED FOR THIS SINCE I’M NOT READING FROM A FILE | |
//var dataSource = reader.Read(new MultiFileSource(orderItemsLocation)); | |
// Load data in IDataView from a Database | |
IEnumerable<Orders> myData = GetDataFromDatabase(); | |
var trainData = env.CreateStreamingDataView(myData); | |
var model = est.Fit(trainData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment