当前位置: 首页 > news >正文

按类别DF特征词选择算法

声明:

 

ExpandedBlockStart.gif 按类别特征词选择算法声明
vector < pair < string , double >   > LocalDFFeatureSelectionForPerclass(DICTIONARY &  mymap,CONTINGENCY &  contingencyTable, string  classLabel); // 局部DF法针对每个词对每个类别进行排序
         void  DFFeatureSelection(vector < string >  classLabels,DICTIONARY  & mymap,CONTINGENCY &  contingencyTable, int  N, char   * address); // 调用局部DF特征词选择函数

 

函数实现:

 

ExpandedBlockStart.gif 对词典中的每个词,统计其在某一个类别中出现的次数,并按词频从大到小排序
/* ********************************************************************** */
/*   按类别的DF特征词选择法                                                */
/* ********************************************************************** */
vector
< pair < string , double >   >  Preprocess::LocalDFFeatureSelectionForPerclass(DICTIONARY &  mymap,CONTINGENCY &  contingencyTable , string  classLabel)
{
    
// int finalKeyWordsCount=0; // 计算共取了多少个关键词
    clock_t start,finish;
    
double  totaltime;
    start
= clock();
    vector
< pair < string , double >   > DFinfo;
    
for (map < string ,vector < pair < int , int >>> ::iterator it = mymap.begin();it != mymap.end(); ++ it)
    {
        
        pair
< string , string > compoundKey = make_pair(it -> first,classLabel);
        
double  classCount = ( double )contingencyTable[compoundKey].first;
        DFinfo.push_back(make_pair(it
-> first,classCount));
        
    }

    stable_sort(DFinfo.begin(),DFinfo.end(),isLarger);
    finish
= clock();
    totaltime
= ( double )(finish - start) / CLOCKS_PER_SEC;
    cout
<< " 为类别 " << classLabel << " 遴选特征词共用了 " << totaltime << endl;

    
return  DFinfo;


}

 

 

DF特征词选择法:

 

ExpandedBlockStart.gif 代码
/* ********************************************************************** */
/*  DF特征词选择法                                                                      */
/* ********************************************************************** */
void  Preprocess:: DFFeatureSelection(vector < string   > classLabels,DICTIONARY  & mymap,CONTINGENCY &  contingencyTable, int  N, char   * address)
{
    clock_t start,finish;
    
double  totaltime;
    
int  totalTraingingCorpus = endIndex - beginIndex + 1 ; // 训练语料库总共的文章数目
     set < string > finalKeywords; // 存放最终遴选出的特征词
    vector < pair < string , double >> DFInfo;
    start
= clock();
    
for (vector < string > ::iterator it = classLabels.begin();it != classLabels.end();it ++ )
    {
        
// 训练语料库中某个类别的文章数目
         int  N_subClassCnt = getCategorizationNum( * it, " TrainingCorpus " );
        
// threshold决定每个类别遴选多少个特征词
         int  threshold = N_subClassCnt * N / totalTraingingCorpus;
        DFInfo
= LocalDFFeatureSelectionForPerclass(mymap,contingencyTable, * it);
        
for (vector < pair < string , double >   > ::size_type j = 0 ;j < threshold;j ++ )
        {
            finalKeywords.insert(DFInfo[j].first);

        }
        DFInfo.clear();




    }


    ofstream outfile(address);
    
int  finalKeyWordsCount = finalKeywords.size();
    
for  ( set < string > ::iterator it = finalKeywords.begin();it != finalKeywords.end();it ++ )
    {
        outfile
<<* it << endl;

    }
    outfile.close();
    cout
<< " 最后共选择特征词 " << finalKeyWordsCount << endl;
    finish
= clock();
    totaltime
= ( double )(finish - start) / CLOCKS_PER_SEC;
    cout
<< " 遴选特征词共有了 " << totaltime << endl;

}

 主函数调用:

 

ExpandedBlockStart.gif 代码
p.LoadDictionary(mymap, " F:\\finallyliuyu\\dict.dat " );
    p.LoadContingencyTable(contingenyTable,
" F:\\finallyliuyu\\contingency.dat " );
    p.DFFeatureSelection(labels,mymap,contingenyTable,
2000 , " F:\\finallyliuyu\\keywords.dat " );

 

 

 

相关文章:

  • Dell Insprion 6400坏
  • Makefile相关资料
  • 浅谈角色与权限
  • Exchange2007如何给邮件通讯组Distribution Group设置Send As与Behalf 权限
  • 错误与修正
  • 转: CRT检测内存泄漏技巧以及注意问题
  • RIP协议拓扑结构变化-收敛
  • Redhat 下不重启系统发现LUN
  • asp.net导出数据到EXCEL简单有效
  • RedHat 6.0环境下Oracle 8.0.5的安装
  • Windows 7下用无线网卡自建热点共享Internet访问
  • Oracle发布更新使数据库性能优化达到75%
  • tip
  • 关于MySQL备份还原的几种方案
  • DLL导入
  • CEF与代理
  • CSS实用技巧
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • Js基础知识(一) - 变量
  • laravel with 查询列表限制条数
  • python大佬养成计划----difflib模块
  • rabbitmq延迟消息示例
  • vuex 笔记整理
  • 半理解系列--Promise的进化史
  • 飞驰在Mesos的涡轮引擎上
  • 基于axios的vue插件,让http请求更简单
  • 解析 Webpack中import、require、按需加载的执行过程
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 设计模式走一遍---观察者模式
  • 使用 QuickBI 搭建酷炫可视化分析
  • 手写一个CommonJS打包工具(一)
  • 中文输入法与React文本输入框的问题与解决方案
  • 你对linux中grep命令知道多少?
  • ionic入门之数据绑定显示-1
  • Mac 上flink的安装与启动
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • #单片机(TB6600驱动42步进电机)
  • #图像处理
  • $NOIp2018$劝退记
  • (windows2012共享文件夹和防火墙设置
  • (六)vue-router+UI组件库
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • (算法)Game
  • (算法)N皇后问题
  • (原創) 人會胖會瘦,都是自我要求的結果 (日記)
  • .NET Core6.0 MVC+layui+SqlSugar 简单增删改查
  • .Net Core和.Net Standard直观理解
  • .Net Memory Profiler的使用举例
  • .NET 设计模式—简单工厂(Simple Factory Pattern)
  • .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖
  • .net6 webapi log4net完整配置使用流程
  • .pyc文件是什么?
  • @Builder用法