コード例 #1
0
ファイル: Test.aspx.cs プロジェクト: Fpisti-dev/MLFSQLIAD
        private string UseModelWithSingleItem(TextBox txtResult, String sTestSql)
        {
            // Create Predict Engine
            //PredictionEngine<SqlData, SqlPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine<SqlData, SqlPrediction>(model);

            var predictor = _mlContext.Model.CreatePredictionEngine <AppInput, AppPrediction>(_model);


            // Create Issue
            AppInput issueSql = new AppInput
            {
                Text = sTestSql
            };

            // Predict
            var resultPrediction = predictor.Predict(issueSql);

            // Too many record have to save in short time so we must create a long sql strint instead use ony-by-one insert to history database
            string sSQL = sTestSql.Replace("'", "''");

            string str = "INSERT INTO [dbo].[history] ([TestNumber], [CatalogName], [TrainerName], [DatabaseName], [SqlCommand], [Label], [Prediction], [Probability], [Recorded])"
                         + " VALUES (" + iTestNumber + ", N'" + sCatalog + "', N'" + sTrainer + "', N'" + sDatabase + "', N'" + sSQL + "', " + iLabel.ToString() + ", " + resultPrediction.Label
                         + ", 0, '" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "');";

            // Output Prediction
            txtResult.Text += Environment.NewLine + "=============== Prediction Test of model with a single sample and test dataset ===============" + Environment.NewLine;

            txtResult.Text += $"SQL Command: {sTestSql}" + Environment.NewLine +
                              $"Prediction: {((resultPrediction.Label == "1") ? "Positive" : "Negative")}" + Environment.NewLine;

            txtResult.Text += "=============== End of Predictions ===============" + Environment.NewLine;

            return(str);
        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: Fpisti-dev/MLFSQLIAD
        private void UseModelWithSingleItem(TextBox txtResult, String sTestSql)
        {
            // Create Predictio nEngine1
            //PredictionEngine<SqlData, SqlPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine<SqlData, SqlPrediction>(_model);

            var predictor = _mlContext.Model.CreatePredictionEngine <AppInput, AppPrediction>(_model);


            // Create Issue
            AppInput issueSql = new AppInput
            {
                Text = sTestSql
            };

            // Predict
            var resultPrediction = predictor.Predict(issueSql);

            Logs lo = new Logs();

            if (bUrlRequest)
            {
                int iLog = lo.RecordLogFromURL(sCatalog, sTrainer, sDatabase, sTestSql, iLabel, Convert.ToInt32(resultPrediction.Label));
            }
            else
            {
                int iLog = lo.RecordLogFromInput(sCatalog, sTrainer, sDatabase, sTestSql, Convert.ToInt32(resultPrediction.Label));
            }


            // Output Prediction
            txtResult.Text += Environment.NewLine + "=============== Prediction Test of model with a single sample and test dataset ===============" + Environment.NewLine;

            txtResult.Text += $"SQL Command: {sTestSql}" + Environment.NewLine +
                              $"Prediction: {((resultPrediction.Label == "1") ? "Positive" : "Negative")}" + Environment.NewLine;

            txtResult.Text += "=============== End of Predictions ===============" + Environment.NewLine;
        }