Created
April 21, 2021 02:26
-
-
Save shubham0204/16193d5eef6c6faaa12a0dcc8102561b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Helper class to load data from given CSV file and transform it into a Array<FeatureColumn> | |
class DataFrame( context: Context , assetsFileName : String ) { | |
// HashMap which stores the CSV data in the form ( Column_Name , Float[] ). Where Float[] holds | |
// the feature value for all samples. | |
private var featureColumnData = HashMap<String,ArrayList<Float>>() | |
// Variable to store the parsed CSV file from `CSVReader`. | |
private var rawData : List<Array<String>> | |
// Variable to store column names which are rawData[0]. | |
private var columnNames : Array<String> | |
... | |
init { | |
// Create a CSVReader object | |
val csvReader = CSVReader( InputStreamReader( context.assets.open( assetsFileName ) ) ) | |
// Call csvReader.readAll() which outputs the contents of the CSV in the form List<String[]>. | |
// Every String[] corresponds to a single row. | |
rawData = csvReader.readAll() | |
// Get the column names. | |
columnNames = getColumnNames() | |
// Initialize variables like `numFeatures` and `numSamples`. | |
// Also initialize `featureColumnData` by setting the keys as column names of this Hashmap. | |
initTable() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment