正态分布3σ原则,把3倍方差之外的点设想为噪声数据来排除。

归一化,将数据经过处理之后限定到一定的范围内,一般都会将数据限定到[0,1]。

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <fstream>
#include <sstream>

template <class DataType>
void ReadDataFromFile(std::string &filename, std::vector<std::vector<DataType> > &lines_feat) {
  std::ifstream vm_info(filename.c_str());
  std::string lines;
  DataType var;
  std::vector<DataType> row;

  lines_feat.clear();

  while(!vm_info.eof()) {
    getline(vm_info, lines);
    if(lines.empty())
      break;
    std::stringstream stringin(lines);
    row.clear();

    while(stringin >> var) {
      row.push_back(var);
    }
    lines_feat.push_back(row);
  }
}

template <class DataType>
void Display2DVector(std::vector<std::vector<DataType> > &vv) {
  std::cout<<"the total rows of 2d vector_data: "<<vv.size()<<"\n";

  for(size_t i=0;i<vv.size();++i) {
    for(typename::std::vector<DataType>::const_iterator it=vv[i].begin();it!=vv[i].end();++it) {
      std::cout<<*it<<" ";
    }
    std::cout<<"\n";
  }
  std::cout<<"--------the end of the Display2DVector()--------\n";
}

template <class DataType>
void ProcessVector(std::vector<std::vector<DataType> > &vv) {
  std::vector<double> temp;
  double u[3]={0.0}, sum[3]={0.0}, sigma[3]={0.0};
  for(size_t j=0; j<3; ++j) {
    temp.clear();
    for(size_t i=0; i<vv.size(); ++i) {
      temp.push_back(vv[i][j]);
    }
    sum[j]=std::accumulate(temp.begin(), temp.end(), 0);
    u[j]=sum[j]/vv.size();
  }

  for(size_t j=0;j<3;++j) {
    temp.clear();
    sum[j]=0.0;
    for(size_t i=0;i<vv.size();++i) {
      temp.push_back(std::pow(vv[i][j]-u[j], 2.0));
    }
    sum[j]=std::accumulate(temp.begin(), temp.end(), 0.0);
    sigma[j]=sum[j]/vv.size();
    sigma[j]=sqrt(sigma[j]);
  }

  double MaxValue[3]={0.0}, MinValue[3]={0.0};
  for(size_t j=0;j<3;++j) {
    temp.clear();
    for(size_t i=0;i<vv.size();++i) {
      if((vv[i][j]>(u[j]-3*sigma[j])) && (vv[i][j]<(u[j]+3*sigma[j]))) {
        std::cout<<vv[i][j]<<" ";
      temp.push_back(vv[i][j]);
      }
    }
    std::cout<<"\n";
    MaxValue[j]=*std::max_element(temp.begin(), temp.end());
    MinValue[j]=*std::min_element(temp.begin(), temp.end());
  }

  for(size_t j=0;j<3;++j) {
    for(size_t i=0;i<vv.size();++i) {
      if((vv[i][j]>(u[j]-3*sigma[j])) && (vv[i][j]<(u[j]+3*sigma[j]))) {
        std::cout<<(vv[i][j]-MinValue[j])/(MaxValue[j]-MinValue[j])<<" ";
      }
    }
    std::cout<<"\n";
  }
}

int main() {
  std::vector<std::vector<int> > lines_feat;
  std::string filename="vm.data";

  /*read data from file to 2d vector*/
  ReadDataFromFile(filename, lines_feat);

  /*display the raw data*/
  Display2DVector(lines_feat);

  /*process the data*/
  ProcessVector(lines_feat);

  std::cout<<"--------The end of main()--------\n";

  return 0;
}

源数据如下(cat vm.data):

19 26 63
13 62 65
16 69 15
14 56 17
19 6 15
11 42 15
18 58 36
12 77 33
10 75 47
15 54 70
10017 1421077 4196

c++ 数据预处理(数据去噪,归一化)的更多相关文章

  1. Python数据预处理(sklearn.preprocessing)—归一化(MinMaxScaler),标准化(StandardScaler),正则化(Normalizer, normalize)

      关于数据预处理的几个概念 归一化 (Normalization): 属性缩放到一个指定的最大和最小值(通常是1-0)之间,这可以通过preprocessing.MinMaxScaler类实现. 常 ...

  2. sklearn中的数据预处理----good!! 标准化 归一化 在何时使用

    RESCALING attribute data to values to scale the range in [0, 1] or [−1, 1] is useful for the optimiz ...

  3. spark 数据预处理 特征标准化 归一化模块

    #We will also standardise our data as we have done so far when performing distance-based clustering. ...

  4. Python数据预处理:机器学习、人工智能通用技术(1)

    Python数据预处理:机器学习.人工智能通用技术 白宁超  2018年12月24日17:28:26 摘要:大数据技术与我们日常生活越来越紧密,要做大数据,首要解决数据问题.原始数据存在大量不完整.不 ...

  5. 机器学习PAL数据预处理

    机器学习PAL数据预处理 本文介绍如何对原始数据进行数据预处理,得到模型训练集和模型预测集. 前提条件 完成数据准备,详情请参见准备数据. 操作步骤 登录PAI控制台. 在左侧导航栏,选择模型开发和训 ...

  6. Python数据挖掘——数据预处理

    Python数据挖掘——数据预处理 数据预处理 数据质量 准确性.完整性.一致性.时效性.可信性.可解释性 数据预处理的主要任务 数据清理 数据集成 数据归约 维归约 数值归约 数据变换 规范化 数据 ...

  7. 机器学习实战基础(八):sklearn中的数据预处理和特征工程(一)简介

    1 简介 数据挖掘的五大流程: 1. 获取数据 2. 数据预处理 数据预处理是从数据中检测,纠正或删除损坏,不准确或不适用于模型的记录的过程 可能面对的问题有:数据类型不同,比如有的是文字,有的是数字 ...

  8. Python数据预处理—归一化,标准化,正则化

    关于数据预处理的几个概念 归一化 (Normalization): 属性缩放到一个指定的最大和最小值(通常是1-0)之间,这可以通过preprocessing.MinMaxScaler类实现. 常用的 ...

  9. 关于使用sklearn进行数据预处理 —— 归一化/标准化/正则化

    一.标准化(Z-Score),或者去除均值和方差缩放 公式为:(X-mean)/std  计算时对每个属性/每列分别进行. 将数据按期属性(按列进行)减去其均值,并处以其方差.得到的结果是,对于每个属 ...

随机推荐

  1. SQL server 2005中无法新建作用(Job)的问题

    1.在使用sqlserver2005创建作业时,创建不了,提示 无法将类型为“Microsoft.SqlServer.Management.Smo.SimpleObjectKey”的对象强制转换为类型 ...

  2. CNN结构:Windows使用FasterRCNN-C++版本

    参考文章:Windows下VS2013 C++编译测试faster-rcnn. 本文与作者的所写方法有些许不同,欲速则不达,没有按照作者的推荐方法,绕了个弯弯. Windows版本纯C++版本的Fas ...

  3. Lazarus 1.6 增加了新的窗体编辑器——Sparta_DockedFormEditor.ipk

    一下是该控件官网的介绍 "Hello A package for a docked form editor can be found in : components/sparta/docke ...

  4. webstrom常用键

    常用快捷键—Webstorm入门指南 提高代码编写效率,离不开快捷键的使用,Webstorm拥有丰富的代码快速编辑功能,你可以自由配置功能快捷键. 快捷键配置 点击“File”-> “setti ...

  5. js 弹出div窗口 可移动 可关闭

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. swift-UINavigationController纯代码自定义导航控制器及底部工具栏的使用

    step1:自定义一个类  NTViewController,该类继承UITabBarController: // // NTViewController.swift // Housekeeper / ...

  7. java web 基本属性

    page指令 属性 描述 默认值 language 指定JSP页面使用的脚本语言 java import contenType include指令 taglib注释 <!--我是html注释-- ...

  8. Codeforces 919C - Seat Arrangements

    传送门:http://codeforces.com/contest/919/problem/C 给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位.求选择的方法数. H ...

  9. js调用ro的webservice

    Enabling JavaScript Access on the Server Drop the JavaScriptHttpDispatcher component onto the server ...

  10. 【Mail.Ru Cup 2018 Round 2 B】 Alice and Hairdresser

    [链接] 我是链接,点我呀:) [题意] [题解] 因为只会增加. 所以. 一开始暴力算出来初始答案 每次改变一个点的话. 就只需要看看和他相邻的数字的值就好. 看看他们是不是大于l 分情况增加.减少 ...