public void RunPipelineTest() { // Creates learning api object LearningApi api = new LearningApi(TestHelpers.GetDescriptor()); // Initialize data provider api.UseCsvDataProvider(m_iris_data_path, ',', 1); // Use mapper for data, which will extract (map) required columns api.UseDefaultDataMapper(); // Use MinMax data normalizer //api.UseMinMaxNormalizer(m_stats.Select(x => x.Min).ToArray(), m_stats.Select(x => x.Max).ToArray()); // We could also use some other normalizer like Gaus data normalizer //api.UseGaussNormalizer(m_stats.Select(x => x.Mean).ToArray(), m_stats.Select(x => x.StDev).ToArray()); // Prepares the ML Algoritm and setup parameters api.UseBackPropagation(1, 0.2, 1.0, null); //start process of learning api.Run(); // api.Train(); // api.TrainSample(); IScore status = api.GetScore(); //api.Train(vector) return; }
public bool InitNeuralBackPropagationTest() { // InitIrisMapperInJsonFormat_helper(); // Creates learning api object LearningApi api = new LearningApi(TestHelpers.GetDescriptor()); // Initialize data provider api.UseCsvDataProvider(m_IrisDataPath, ',', false, 1); // Use mapper for data, which will extract (map) required columns api.UseDefaultDataMapper(); // Use MinMax data normalizer //api.UseMinMaxNormalizer(); // We could also use some other normalizer like Gaus data normalizer //api.UseGaussNormalizer(m_stats.Select(x => x.Mean).ToArray(), m_stats.Select(x => x.StDev).ToArray()); // Prepares the ML Algoritm and setup parameters api.UseBackPropagation(1, 0.2, 1.0, null); api.Run(); IScore status = api.GetScore(); //api.Train(vector) return(true); }
public void LogisticRegression_Test_iterations_20_learningrate_015() { var desc = loadMetaData(); LearningApi api = new LearningApi(desc); //Real dataset must be defined as object type, because data can be numeric, binary and classification api.UseActionModule <object[][], object[][]>((input, ctx) => { return(loadRealDataSample()); }); // Use mapper for data, which will extract (map) required columns api.UseDefaultDataMapper(); api.UseMinMaxNormalizer(); //run logistic regression for 10 iteration with learningRate=0.15 api.UseLogisticRegression(0.15, 20); api.Run(); IScore score = api.GetScore(); //Errors during each iteration Assert.Equal(Math.Round(score.Errors[0], 5), 0.24236); Assert.Equal(Math.Round(score.Errors[1], 5), 0.23707); Assert.Equal(Math.Round(score.Errors[2], 5), 0.23358); Assert.Equal(Math.Round(score.Errors[3], 5), 0.23001); Assert.Equal(Math.Round(score.Errors[4], 5), 0.22806); Assert.Equal(Math.Round(score.Errors[5], 5), 0.22506); Assert.Equal(Math.Round(score.Errors[6], 5), 0.22409); Assert.Equal(Math.Round(score.Errors[7], 5), 0.22134); Assert.Equal(Math.Round(score.Errors[8], 5), 0.22105); Assert.Equal(Math.Round(score.Errors[9], 5), 0.21840); Assert.Equal(Math.Round(score.Errors[10], 5), 0.21857); Assert.Equal(Math.Round(score.Errors[11], 5), 0.21595); Assert.Equal(Math.Round(score.Errors[12], 5), 0.21640); Assert.Equal(Math.Round(score.Errors[13], 5), 0.21381); Assert.Equal(Math.Round(score.Errors[14], 5), 0.21439); Assert.Equal(Math.Round(score.Errors[15], 5), 0.21189); Assert.Equal(Math.Round(score.Errors[16], 5), 0.21251); Assert.Equal(Math.Round(score.Errors[17], 5), 0.21015); Assert.Equal(Math.Round(score.Errors[18], 5), 0.21076); Assert.Equal(Math.Round(score.Errors[19], 5), 0.20860); //LG Model Best Found model in 20 iteration Assert.Equal(Math.Round(score.Weights[0], 5), 0.28363); Assert.Equal(Math.Round(score.Weights[1], 5), 0.37424); Assert.Equal(Math.Round(score.Weights[2], 5), 1.41890); Assert.Equal(Math.Round(score.Weights[3], 5), 1.01207); Assert.Equal(Math.Round(score.Weights[4], 5), -0.33841); Assert.Equal(Math.Round(score.Weights[5], 5), -0.33841); Assert.Equal(Math.Round(score.Weights[6], 5), -1.62489); }
public void LogisticsRegression_Test_iterations_10_learningrate_013() { var desc = loadMetaData(); LearningApi api = new LearningApi(desc); //Real dataset must be defined as object type, because data can be numeric, binary and classification api.UseActionModule <object[][], object[][]>((input, ctx) => { return(loadRealDataSample()); }); // Use mapper for data, which will extract (map) required columns api.UseDefaultDataMapper(); api.UseMinMaxNormalizer(); //run logistic regression for 10 iterations with learningRate=0.13 api.UseLogisticRegression(0.13, 10); api.Run(); IScore score = api.GetScore(); //Errors during each iteration. IF the learningRate is suitable erros is descrising for every next iteration Assert.Equal(Math.Round(score.Errors[0], 5), 0.24278); Assert.Equal(Math.Round(score.Errors[1], 5), 0.23749); Assert.Equal(Math.Round(score.Errors[2], 5), 0.23359); Assert.Equal(Math.Round(score.Errors[3], 5), 0.23010); Assert.Equal(Math.Round(score.Errors[4], 5), 0.22740); Assert.Equal(Math.Round(score.Errors[5], 5), 0.22476); Assert.Equal(Math.Round(score.Errors[6], 5), 0.22271); Assert.Equal(Math.Round(score.Errors[7], 5), 0.22065); Assert.Equal(Math.Round(score.Errors[8], 5), 0.21902); Assert.Equal(Math.Round(score.Errors[9], 5), 0.21739); //LG Model Best Found model in 10 iteration Assert.Equal(Math.Round(score.Weights[0], 5), 0.06494); Assert.Equal(Math.Round(score.Weights[1], 5), 0.21584); Assert.Equal(Math.Round(score.Weights[2], 5), 0.89901); Assert.Equal(Math.Round(score.Weights[3], 5), 0.51497); Assert.Equal(Math.Round(score.Weights[4], 5), -0.30213); Assert.Equal(Math.Round(score.Weights[5], 5), -0.30213); Assert.Equal(Math.Round(score.Weights[6], 5), -0.85624); }
public void LogisticsRegression_Test_iterations_10_learningrate_013() { var desc = loadMetaData(); LearningApi api = new LearningApi(desc); //Real dataset must be defined as object type, because data can be numeric, binary and classification api.UseActionModule <object[][], object[][]>((input, ctx) => { return(loadRealDataSample()); }); // Use mapper for data, which will extract (map) required columns api.UseDefaultDataMapper(); api.UseMinMaxNormalizer(); //run logistic regression for 10 iterations with learningRate=0.13 api.UseLogisticRegression(0.13, 10); api.Run(); LogisticRegressionScore score = api.GetScore() as LogisticRegressionScore; //Errors during each iteration. IF the learningRate is suitable errors is describing for every next iteration Assert.Equal(Math.Round(score.Errors[0], 5), 0.24278); Assert.Equal(Math.Round(score.Errors[1], 5), 0.23749); Assert.Equal(Math.Round(score.Errors[2], 5), 0.23359); Assert.Equal(Math.Round(score.Errors[3], 5), 0.23010); Assert.Equal(Math.Round(score.Errors[4], 5), 0.22740); Assert.Equal(Math.Round(score.Errors[5], 5), 0.22476); Assert.Equal(Math.Round(score.Errors[6], 5), 0.22271); Assert.Equal(Math.Round(score.Errors[7], 5), 0.22065); Assert.Equal(Math.Round(score.Errors[8], 5), 0.21902); Assert.Equal(Math.Round(score.Errors[9], 5), 0.21739); //LG Model Best Found model in 10 iteration Assert.Equal(Math.Round(score.Weights[0], 5), 0.06494); Assert.Equal(Math.Round(score.Weights[1], 5), 0.21584); Assert.Equal(Math.Round(score.Weights[2], 5), 0.89901); Assert.Equal(Math.Round(score.Weights[3], 5), 0.51497); Assert.Equal(Math.Round(score.Weights[4], 5), -0.30213); Assert.Equal(Math.Round(score.Weights[5], 5), -0.30213); Assert.Equal(Math.Round(score.Weights[6], 5), -0.85624); //define data for testing (prediction) LearningApi apiPrediction = new LearningApi(desc); //Real dataset must be defined as object type, because data can be numeric, binary and classification apiPrediction.UseActionModule <object[][], object[][]>((input, ctx) => { var data = new object[4][] { new object[] { 0.202, "blue", "male", 13, "yes" }, new object[] { 0.447, "green", "female", 37, "no" }, new object[] { 0.120, "red", "male", "21", "yes" }, new object[] { 0.313, "green", "male", 22, "yes" }, }; return(data); }); // Use mapper for data, which will extract (map) required columns apiPrediction.UseDefaultDataMapper(); var testData = apiPrediction.Run(); //use previous trained model var result = api.Algorithm.Predict(testData as double[][], api.Context) as LogisticRegressionResult; Assert.Equal(Math.Round(result.PredictedValues[0], 5), 1E-05); Assert.Equal(Math.Round(result.PredictedValues[1], 5), 0); Assert.Equal(Math.Round(result.PredictedValues[2], 5), 0); Assert.Equal(Math.Round(result.PredictedValues[3], 5), 0); }