#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 Introduction
oops-assignment-4's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.