Computer Science  >  STUDY GUIDE  >  kmeans_clusters.cpp University of Michigan ENGR 151 (All)

kmeans_clusters.cpp University of Michigan ENGR 151

Document Content and Description Below

#include <iostream> #include <fstream> #include <string> #include <vector> #include <math.h> using namespace std; // structure for holding data from cars.csv struct car_data { vector<string> ... headers; // stores the headers int N_rows; // stores number of rows // data in the 8 columns in cars.csv vector<double> mpg; vector<double> cylinders; vector<double> cubicinches; vector<double> hp; vector<double> weightlbs; vector<double> time260; vector<double> year; vector<string> region; vector<int> clusters; // cluster 1,2,3 that car is assigned to }; void read_csv(ifstream &fin, car_data &dat); // read data from cars.csv into struct car_data void normalize(car_data &data_norm);// normalize data void unnormalize(car_data &data_norm,car_data &data); // take normalized data_norm and unnormalize it using max/min values from data void initialize(car_data &centroids); // give random initial values for centroids double distance(car_data data, car_data centroids, int carIndex, int centroidIndex); double check_convergence(const car_data &centroids, const car_data &centroids_old); // find sum of squares difference between old and new centroids void assign_clusters(const car_data &centroids, car_data &data_norm); // for each mpg, etc. find nearest cluster void find_new_centroids(car_data &centroids, const car_data &data_norm); // find average position for each cluster to define new centroids void print(ostream &fout, car_data &data); // print to cout or file (ostream can be either) double minVec(vector<double> a); double maxVec(vector<double> a); int main() { car_data data; ifstream fin("cars.csv"); // Step 1 - read in data and verify read_csv(fin, data); data.headers.pop_back(); data.headers.push_back(" cluster"); //print(cout,data); // good to check output for debugging fin.close(); // Step 2 - Normalize vectors - only columns 1-7 car_data data_norm = data; normalize(data_norm); //print(data_no [Show More]

Last updated: 3 years ago

Preview 1 out of 6 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of kmeans_clusters.cpp University of Michigan ENGR 151 document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$6.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

125
0

Document information


Connected school, study & course


About the document


Uploaded On

Nov 17, 2022

Number of pages

6

Written in

All

Seller


Profile illustration for Browsegrades
Browsegrades

Member since 3 years

0 Documents Sold

Additional information

This document has been written for:

Uploaded

Nov 17, 2022

Downloads

 0

Views

 125

Document Keyword Tags

Recommended For You

Get more on STUDY GUIDE »

$6.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·