在Weka分类器中缩放训练数据

我在使用Weka分类器进行训练集的分类,但我想在构建模型之前对数据进行缩放。问题是我不知道如何操作。以下是构建分类器和进行预测的代码。”trainPath” 和 “predictPath” 中的文件是arff格式的。

void classify(String trainPath, String predictPath) {    try {        DataSource trainData = new DataSource(trainPath);        Instances train = trainData.getDataSet();        if(train.classIndex() == -1)            train.setClassIndex(train.numAttributes() -1);        DataSource predictData = new DataSource(predictPath);        Instances predict = predictData.getDataSet();        if(predict.classIndex() == -1)            predict.setClassIndex(predict.numAttributes() -1);        Classifier cls = new LibSVM();        cls.buildClassifier(train);        Instances labeled = new Instances(predict);        for (int c=0; c<predict.numInstances(); c++) {            double clsLabel = cls.classifyInstance(predict.instance(c));            labeled.instance(c).setClassValue(clsLabel);        }        BufferedWriter bw = new BufferedWriter(new FileWriter("files/labeled.arff"));        bw.write(labeled.toString());        bw.newLine();        bw.flush();        bw.close();    } catch (Exception e) {e.printStackTrace();}}

我知道在Libsvm中有svm-scale函数,但我不知道如何使用它。


回答:

Weka为您提供了数据预处理的方法,特别是

  • weka.filters.unsupervised.attribute.Normalize
  • weka.filters.unsupervised.attribute.Standardize

标准化器的使用示例,它将数据缩放到[0,1]区间(默认情况下):

Normalize norm = new Normalize();norm.setInputFormat(train);Instances processed_train = Filter.useFilter(train, norm);

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注