Offer类:
using System.Collections.Generic; using System.IO; using System.Linq; namespace CustomerSegmentation.DataStructures { public class Offer { //Offer #,Campaign,Varietal,Minimum Qty (kg),Discount (%),Origin,Past Peak public string OfferId { get; set; } public string Campaign { get; set; } public string Varietal { get; set; } public float Minimum { get; set; } public float Discount { get; set; } public string Origin { get; set; } public string LastPeak { get; set; } public static IEnumerable<Offer> ReadFromCsv(string file) { return File.ReadAllLines(file) .Skip(1) // skip header .Select(x => x.Split(',')) .Select(x => new Offer() { OfferId = x[0], Campaign = x[1], Varietal = x[2], Minimum = float.Parse(x[3]), Discount = float.Parse(x[4]), Origin = x[5], LastPeak = x[6] }); } } }Transaction类:
using System.Collections.Generic; using System.IO; using System.Linq; namespace CustomerSegmentation.DataStructures { public class Transaction { //Customer Last Name,Offer # //Smith,2 public string LastName { get; set; } public string OfferId { get; set; } public static IEnumerable<Transaction> ReadFromCsv(string file) { return File.ReadAllLines(file) .Skip(1) // skip header .Select(x => x.Split(',')) .Select(x => new Transaction() { LastName = x[0], OfferId = x[1], }); } } }PivotData类:
namespace CustomerSegmentation.DataStructures { public class PivotData { public float[] Features; public string LastName; } }ClusteringPrediction类:
using Microsoft.ML.Runtime.Api; using System; using System.Collections.Generic; using System.Text; namespace CustomerSegmentation.DataStructures { public class ClusteringPrediction { [ColumnName("PredictedLabel")] public uint SelectedClusterId; [ColumnName("Score")] public float[] Distance; [ColumnName("PCAFeatures")] public float[] Location; [ColumnName("LastName")] public string LastName; } }