static void Main(string[] args) { SaveRateToFileTrainData("USD"); SaveRateToFileTestData("USD"); Global.UseEngine(SiaNet.Backend.ArrayFire.SiaNetBackend.Instance, DeviceType.CUDA, true); var train = PreparingExchangeRateData.LoadTrain(); var test = PreparingExchangeRateData.LoadTest(); var model = new Sequential(); model.EpochEnd += Model_EpochEnd; model.Add(new Dense(60, ActType.Sigmoid)); model.Add(new Dense(60, ActType.Sigmoid)); model.Add(new Dense(1, ActType.Linear)); //Compile with Optimizer, Loss and Metric model.Compile(OptimizerType.SGD, LossType.MeanSquaredError, MetricType.MSE); // Train for 1000 epoch with batch size of 2 model.Train(train, epochs: 1000, batchSize: 32); //Create prediction data to evaluate DataFrame2D predX = new DataFrame2D(2); predX.Load(0, 0, 0, 1, 1, 0, 1, 1); //Result should be 0, 1, 1, 0 var rawPred = model.Predict(test); Console.ReadLine(); }
static void Main(string[] args) { //Setup Engine Global.UseEngine(SiaNet.Backend.MxNetLib.SiaNetBackend.Instance, DeviceType.CPU); //Prep Data var(x, y) = PrepDataset(); x.Head(); DataFrameIter trainSet = new DataFrameIter(x, y); //Build model with simple fully connected layers var model = new Sequential(); model.EpochEnd += Model_EpochEnd; model.Add(new Dense(64, ActType.ReLU)); model.Add(new Dense(1, ActType.Sigmoid)); //Compile with Optimizer, Loss and Metric model.Compile(OptimizerType.SGD, LossType.MeanSquaredError, MetricType.BinaryAccurary); // Train for 100 epoch with batch size of 2 model.Train(trainSet, 1000, 2); //Create prediction data to evaluate DataFrame2D predX = new DataFrame2D(2); predX.Load(0, 0, 0, 1); //Result should be 0 and 1 var rawPred = model.Predict(predX); Console.ReadLine(); }
public static DataFrame LoadTest() { //string projectDirectory = System.IO.Path.GetFullPath(@"..\..\..\"); //var frame = Frame.ReadCsv(projectDirectory + "/Data/USDRateTest.csv"); //frame.DropColumn("Date"); string projectDirectory = System.IO.Path.GetFullPath(@"..\..\..\"); List <float> datas = new List <float>(); using (StreamReader readFile = new StreamReader(projectDirectory + "/Data/USDRateTest.csv")) { string line; string[] row; while ((line = readFile.ReadLine()) != null) { row = line.Split('\t'); for (int i = 1; i < row.Length; i++) { datas.Add(float.Parse(row[i])); } } } //var data = frame.ToArray2D<float>().Cast<float>().ToArray(); DataFrame2D df = new DataFrame2D(8); df.Load(datas.ToArray()); return(df); }
private static DataFrame LoadTest() { var x = new DataFrame2D(2); x.Load(new float[] { 0, 1, 1, 1 }); return(x); }
public static (DataFrame2D, DataFrame2D) PrepareDataSet() { DataFrame2D x = new DataFrame2D(2); x.Load(new float[] { 0, 0, 0, 1, 1, 0, 1, 1 }); DataFrame2D y = new DataFrame2D(1); y.Load(new float[] { 0, 1, 1, 0 }); return(x, y); }
private static (DataFrame, DataFrame) LoadTrain() { var x = new DataFrame2D(2); x.Load(new float[] { 0, 0, 0, 1, 1, 0, 1, 1 }); var y = new DataFrame2D(1); y.Load(new float[] { 0, 1, 1, 0 }); return(x, y); }
private static (DataFrame2D, DataFrame2D) PrepDataset() { var K = Global.CurrentBackend; Tensor x = K.RandomNormal(new long[] { 900, 10 }, 0.25f, 1); Tensor y = K.RandomUniform(new long[] { 900, 1 }, 0, 25); DataFrame2D X = new DataFrame2D(10); DataFrame2D Y = new DataFrame2D(1); X.Load(x.DataFloat); Y.Load(y.DataFloat); return(X, Y); }
private static (DataFrame2D, DataFrame2D) PrepDataset() { // We will prepare XOR gate dataset which will be treated as classification problem. // More about this: https://medium.com/@jayeshbahire/the-xor-problem-in-neural-networks-50006411840b DataFrame2D x = new DataFrame2D(2); x.Load(new float[] { 0, 0, 0, 1, 1, 0, 1, 1 }); DataFrame2D y = new DataFrame2D(1); y.Load(new float[] { 0, 1, 1, 0 }); return(x, y); }
private static DataFrame LoadTest() { //Using deedle which is similar to Pandas in python var frame = Frame.ReadCsv("./BostonHousing/test.csv", true); frame.DropColumn("ID"); //Load Deedle frame to Tensor frame var data = frame.ToArray2D <float>().Cast <float>().ToArray(); var test = new DataFrame2D(frame.ColumnCount); test.Load(data); return(test); }
private static DataFrame LoadTest() { //Using deedle which is similar to Pandas in python var frame = Frame.ReadCsv("test.csv", true); //Preprocess the data by handling missing values, converting string to numbers frame = PreProcesData(frame, true); //Load Deedle frame to Tensor frame var data = frame.ToArray2D <float>().Cast <float>().ToArray(); DataFrame2D df = new DataFrame2D(frame.ColumnCount); df.Load(data); return(df); }
private static DataFrameIter LoadTrain() { //Using deedle which is similar to Pandas in python var frame = Frame.ReadCsv("train.csv", true); //Preprocess the data by handling missing values, converting string to numbers frame = PreProcesData(frame); //Load Deedle frame to Tensor frame var data = frame.ToArray2D <float>().Cast <float>().ToArray(); DataFrame2D df = new DataFrame2D(frame.ColumnCount); df.Load(data); //Split X and Y var x = df[0, 6]; var y = df[7]; return(new DataFrameIter(x, y)); }
private static (DataFrame, DataFrame) LoadTrain() { //Using deedle which is similar to Pandas in python var frame = Frame.ReadCsv("./BostonHousing/train.csv", true); frame.DropColumn("ID"); //Load Deedle frame to Tensor frame var yData = frame["medv"].Values.Select(i => ((float)i)).ToArray(); frame.DropColumn("medv"); var data = frame.ToArray2D <float>().Cast <float>().ToArray(); var x = new DataFrame2D(frame.ColumnCount); x.Load(data); var y = new DataFrame2D(1); y.Load(yData); return(x, y); }