- Hands-On Machine Learning with ML.NET
- Jarred Capellman
- 88字
- 2021-06-24 16:43:34
The FeatureExtractor class
This newly added class provides our feature extraction for the given folder of files. Once extraction is complete, the classification and strings data is written out to the sampledata file:
using System;
using System.IO;
using chapter03_logistic_regression.Common;
using chapter03_logistic_regression.ML.Base;
namespace chapter03_logistic_regression.ML
{
public class FeatureExtractor : BaseML
{
public void Extract(string folderPath)
{
var files = Directory.GetFiles(folderPath);
using (var streamWriter =
new StreamWriter(Path.Combine(AppContext.BaseDirectory, $"../../../Data/{Constants.SAMPLE_DATA}")))
{
foreach (var file in files)
{
var strings = GetStrings(File.ReadAllBytes(file));
streamWriter.WriteLine($"{file.ToLower().Contains("malicious")}\t{strings}");
}
}
Console.WriteLine($"Extracted {files.Length} to {Constants.SAMPLE_DATA}");
}
}
}