Documentation of 'jsat.io.LIBSVMLoader' Java class
LIBSVMLoader
jsat.io

Class LIBSVMLoader



  • public class LIBSVMLoader
    extends java.lang.Object
    Loads a LIBSVM data file into a DataSet. LIVSM files do not indicate whether or not the target variable is supposed to be numerical or categorical, so two different loading methods are provided. For a LIBSVM file to be loaded correctly, it must match the LIBSVM spec without extensions.

    Each line should begin with a numeric value. This is either a regression target or a class label.
    Then, for each non zero value in the data set, a space should precede an integer value index starting from 1 followed by a colon ":" followed by a numeric feature value.
    The single space at the beginning should be the only space. There should be no double spaces in the file.

    LIBSVM files do not explicitly specify the length of data vectors. This can be problematic if loading a testing and training data set, if the data sets do not include the same highest index as a non-zero value, the data sets will have incompatible vector lengths. To resolve this issue, use the loading methods that include the optional vectorLength parameter to specify the length before hand.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static DataWriter getWriter(java.io.OutputStream out, int dim, DataWriter.DataSetType type)
      Returns a DataWriter object which can be used to stream a set of arbitrary datapoints into the given output stream.
      static ClassificationDataSet loadC(java.io.File file)
      Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
      static ClassificationDataSet loadC(java.io.File file, double sparseRatio)
      Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
      static ClassificationDataSet loadC(java.io.File file, double sparseRatio, int vectorLength)
      Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
      static ClassificationDataSet loadC(java.io.InputStreamReader isr, double sparseRatio)
      Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
      static ClassificationDataSet loadC(java.io.Reader reader, double sparseRatio, int vectorLength)
      Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
      static RegressionDataSet loadR(java.io.File file)
      Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
      static RegressionDataSet loadR(java.io.File file, double sparseRatio)
      Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
      static RegressionDataSet loadR(java.io.File file, double sparseRatio, int vectorLength)
      Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
      static RegressionDataSet loadR(java.io.InputStreamReader isr, double sparseRatio)
      Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
      static RegressionDataSet loadR(java.io.Reader reader, double sparseRatio, int vectorLength)
      Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict.
      static void write(ClassificationDataSet data, java.io.OutputStream os)
      Writes out the given classification data set as a LIBSVM data file
      static void write(RegressionDataSet data, java.io.OutputStream os)
      Writes out the given regression data set as a LIBSVM data file
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • loadR

        public static RegressionDataSet loadR(java.io.File file)
                                       throws java.io.FileNotFoundException,
                                              java.io.IOException
        Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
        Parameters:
        file - the file to load
        Returns:
        a regression data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadR

        public static RegressionDataSet loadR(java.io.File file,
                                              double sparseRatio)
                                       throws java.io.FileNotFoundException,
                                              java.io.IOException
        Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
        Parameters:
        file - the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        Returns:
        a regression data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadR

        public static RegressionDataSet loadR(java.io.File file,
                                              double sparseRatio,
                                              int vectorLength)
                                       throws java.io.FileNotFoundException,
                                              java.io.IOException
        Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
        Parameters:
        file - the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        vectorLength - the pre-determined length of each vector. If given a negative value, the largest non-zero index observed in the data will be used as the length.
        Returns:
        a regression data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadR

        public static RegressionDataSet loadR(java.io.InputStreamReader isr,
                                              double sparseRatio)
                                       throws java.io.IOException
        Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict
        Parameters:
        isr - the input stream for the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        Returns:
        a regression data set
        Throws:
        java.io.IOException - if an error occurred reading the input stream
      • loadR

        public static RegressionDataSet loadR(java.io.Reader reader,
                                              double sparseRatio,
                                              int vectorLength)
                                       throws java.io.IOException
        Loads a new regression data set from a LIBSVM file, assuming the label is a numeric target value to predict.
        Parameters:
        reader - the reader for the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        vectorLength - the pre-determined length of each vector. If given a negative value, the largest non-zero index observed in the data will be used as the length.
        Returns:
        a regression data set
        Throws:
        java.io.IOException
      • loadC

        public static ClassificationDataSet loadC(java.io.File file)
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
        Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
        Parameters:
        file - the file to load
        Returns:
        a classification data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadC

        public static ClassificationDataSet loadC(java.io.File file,
                                                  double sparseRatio)
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
        Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
        Parameters:
        file - the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        Returns:
        a classification data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadC

        public static ClassificationDataSet loadC(java.io.File file,
                                                  double sparseRatio,
                                                  int vectorLength)
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
        Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
        Parameters:
        file - the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        vectorLength - the pre-determined length of each vector. If given a negative value, the largest non-zero index observed in the data will be used as the length.
        Returns:
        a classification data set
        Throws:
        java.io.FileNotFoundException - if the file was not found
        java.io.IOException - if an error occurred reading the input stream
      • loadC

        public static ClassificationDataSet loadC(java.io.InputStreamReader isr,
                                                  double sparseRatio)
                                           throws java.io.IOException
        Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
        Parameters:
        isr - the input stream for the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        Returns:
        a classification data set
        Throws:
        java.io.IOException - if an error occurred reading the input stream
      • loadC

        public static ClassificationDataSet loadC(java.io.Reader reader,
                                                  double sparseRatio,
                                                  int vectorLength)
                                           throws java.io.IOException
        Loads a new classification data set from a LIBSVM file, assuming the label is a nominal target value
        Parameters:
        reader - the input stream for the file to load
        sparseRatio - the fraction of non zero values to qualify a data point as sparse
        vectorLength - the pre-determined length of each vector. If given a negative value, the largest non-zero index observed in the data will be used as the length.
        Returns:
        a classification data set
        Throws:
        java.io.IOException - if an error occurred reading the input stream
      • write

        public static void write(ClassificationDataSet data,
                                 java.io.OutputStream os)
        Writes out the given classification data set as a LIBSVM data file
        Parameters:
        data - the data set to write to a file
        os - the output stream to write to. The stream will not be closed or flushed by this method
      • write

        public static void write(RegressionDataSet data,
                                 java.io.OutputStream os)
        Writes out the given regression data set as a LIBSVM data file
        Parameters:
        data - the data set to write to a file
        os - the output stream to write to. The stream will not be closed or flushed by this method
      • getWriter

        public static DataWriter getWriter(java.io.OutputStream out,
                                           int dim,
                                           DataWriter.DataSetType type)
                                    throws java.io.IOException
        Returns a DataWriter object which can be used to stream a set of arbitrary datapoints into the given output stream. This works in a thread safe manner.
        Categorical information dose not need to be specified since LIBSVM files can't store categorical features.
        Parameters:
        out - the location to store all the data
        dim - information on how many numeric features exist
        type - what type of data set (simple, classification, regression) to be written
        Returns:
        the DataWriter that the actual points can be streamed through
        Throws:
        java.io.IOException

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.