Weka ARFF生成

我正在尝试从一个CSV数据文件生成一个.arff文件。我对Weka完全是新手,刚开始使用它才一天。我正在尝试一个简单的Twitter情感分析作为起点。我已经生成了CSV格式的训练数据。CSV文件的内容如下:

  tweet,affinScore,polarity ATAUTHORcfoblog is giving away a $25 Amex gift card (enter to win over $600 in prizes!) http://t.co/JD8EP14c ,4,4"American Express has always been my dark horse acquirer of  ATAUTHORFoursquare. Bundle in Square-like payments & its a lite-retailer platform, no? ",0,1African-American Demos Express Ethnic Identity Differently http://t.co/gInv4bKj via  ATAUTHORmediapost ,0,3Google ???????? Visa ? American Express  http://t.co/eEZTSiHY ,0,4Secrets to Success from Small-Business Owners : Lifestyle :: American Express OPEN Forum http://t.co/b85F8JX0 via  ATAUTHOROpenForum ,2,1RT  ATAUTHORhunterwalk: American Express has always been my dark horse acquirer of  ATAUTHORFoursquare. Bundle in Square-like payments & its a lite ... ,0,1Winning Surveys $1500 american express Huggies Sweeps http://t.co/WoaTFowp ,4,1I root for Square mostly because a small business that takes Square is also one that takes American Express. ,0,1I dont know how bitch be acting American Express but they cards be saying DEBIT ON IT HAVE A ?? PLEASE!!! ,-5,2Uh oh... RT  ATAUTHORBlackArrowBella: I dont know how bitch be acting American Express but they cards be saying DEBIT ON IT HAVE A ?? PLEASE!!! ,-5,2Just got another credit card. A Blue Sky card with American Express. Its gonna help pay for the honeymoon!  ATAUTHORAmericanExpress ,-1,1Follow  ATAUTHORShaveMagazine and ReTweet this msg to be entered to #Win an American Express Gift card. Winners contacted bi-weekly by direct msg! ,2,4American Express Gold zakelijk aanvragen: http://t.co/xheZwmbt ,0,3RT  ATAUTHORhunterwalk: American Express has always been my dark horse acquirer of  ATAUTHORFoursquare. Bundle in Square-like payments & its a lite ... ,0,1

这里的第一个属性是实际的推文,第二个是AFFIN分数,第三个是实际的分类类别(1-积极,2-消极,3-中性,4-垃圾信息)

现在我尝试使用以下代码从中生成.arff格式:

import weka.core.Instances;import weka.core.converters.ArffSaver;import weka.core.converters.CSVLoader;import java.io.File;public class CSV2Arff {  /**   * takes 2 arguments:   * - CSV input file   * - ARFF output file   */  public static void main(String[] args) throws Exception {    if (args.length != 2) {      System.out.println("\nUsage: CSV2Arff <input.csv> <output.arff>\n");      System.exit(1);    }    // load CSV    CSVLoader loader = new CSVLoader();    loader.setSource(new File(args[0]));    Instances data = loader.getDataSet();    // save ARFF    ArffSaver saver = new ArffSaver();    saver.setInstances(data);    saver.setFile(new File(args[1]));    saver.setDestination(new File(args[1]));    saver.writeBatch();  }}

这会生成一个看起来像这样的.arff文件:

   @relation file@attribute tweet {_ATAUTHORcfoblog_is_giving_away_a_$25_Amex_gift_card_(enter_to_win_over_$600_in_prizes!)_http://t.co/JD8EP14c_,'American_Express_has_always_been_my_dark_horse_acquirer_of__ATAUTHORFoursquare._Bundle_in_Square-like_payments_&_its_a_lite-retailer_platform,_no?_',African-American_Demos_Express_Ethnic_Identity_Differently_http://t.co/gInv4bKj_via__ATAUTHORmediapost_,Google_????????_Visa_?_American_Express__http://t.co/eEZTSiHY_,Secrets_to_Success_from_Small-Business_Owners_:_Lifestyle_::_American_Express_OPEN_Forum_http://t.co/b85F8JX0_via__ATAUTHOROpenForum_,RT__ATAUTHORhunterwalk:_American_Express_has_always_been_my_dark_horse_acquirer_of__ATAUTHORFoursquare._Bundle_in_Square-like_payments_&_its_a_lite_..._@data_ATAUTHORcfoblog_is_giving_away_a_$25_Amex_gift_card_(enter_to_win_over_$600_in_prizes!)_http://t.co/JD8EP14c_,4,4'American_Express_has_always_been_my_dark_horse_acquirer_of__ATAUTHORFoursquare._Bundle_in_Square-like_payments_&_its_a_lite-retailer_platform,_no?_',0,1African-American_Demos_Express_Ethnic_Identity_Differently_http://t.co/gInv4bKj_via__ATAUTHORmediapost_,0,3Google_????????_Visa_?_American_Express__http://t.co/eEZTSiHY_,0,4Secrets_to_Success_from_Small-Business_Owners_:_Lifestyle_::_American_Express_OPEN_Forum_http://t.co/b85F8JX0_via__ATAUTHOROpenForum_,2,1RT__ATAUTHORhunterwalk:_American_Express_has_always_been_my_dark_horse_acquirer_of__ATAUTHORFoursquare._Bundle_in_Square-like_payments_&_its_a_lite_..._,0,1

我对Weka是新手,但从我所读到的内容来看,我怀疑这个ARFF文件的格式可能不正确。有人可以对此发表评论吗?

如果格式不对,有人能指出我具体错在哪里吗?


回答:

请确保将tweet属性的类型设置为任意字符串,而不是默认的分类属性。这样做是因为如果不这样设置,每条推文的副本都会被放入类型定义中,这会导致扩展性问题。

请注意,对于推文内容的实际分析,你可能需要进一步预处理。你可能会想要使用文本的稀疏向量表示,而不是长字符串。

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中创建了一个多类分类项目。该项目可以对…

发表回复

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