Giter Club home page Giter Club logo

oops-assignment-4's Introduction

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

class lens{
  public:
  string id;
  vector<int> data;
  lens(vector<string>& arr) {
    int n = arr.size();
    id = arr[0];
    for(int i=1; i<n; i++) data.push_back(stoi(arr[i]));
  }
};

vector<int> types = {3,2,2,2,3};
float min_sup;
unordered_set<string> frequent();

vector<lens> read_data() {
  string temp, word;
  vector<string> arr;
  vector<lens> data;
  fstream fin;

  fin.open("lensesdata.csv", ios::in);
  if(!fin.is_open()) {
    cout << "File not found.\n";
    return data;
  }
  while(fin >> temp) {
    stringstream s(temp);
    while(getline(s, word, ',')) {
      arr.push_back(word);
    }
    data.push_back(lens(arr));
    arr.clear();
  }
  return data;
}

int find_frequency(vector<int> arr, vector<lens>& data){
  int count = 0;
  for(const lens& t: data) {
    bool present = true;
    for(int i=0; i<arr.size(); i++) {
      if(arr[i]!=t.data[i]) present = false;
    }
    if(present) count++;
  }
  return count;
}

void apriori(vector<int> prev, vector<lens>& data) {
  if(prev.size()==5) return;
  for(int i=1; i<=types[prev.size()]; i++) {
    prev.push_back(i);
    int c = find_frequency(prev, data);
    float f = (float) c/(float) data.size();
    if(f>=min_sup) {
      for(const int& j: prev) cout << j << "\t";
      cout << endl;
      apriori(prev, data);
    }
    prev.pop_back();
  }
}



int main() {
  vector<lens> data = read_data();
  

  min_sup = 0.10;
  cout << "\nMin. Support: " << min_sup << endl;
  apriori({}, data);

  min_sup = 0.15;
  cout << "\nMin. Support: " << min_sup << endl;
  apriori({}, data);

  min_sup = 0.20;
  cout << "\nMin. Support: " << min_sup << endl;
  apriori({}, data);


  return 0;
}

oops-assignment-4's People

Contributors

rahulskhatav avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.