Skip to content

Instantly share code, notes, and snippets.

@Remonhasan
Created September 25, 2019 06:49
Show Gist options
  • Save Remonhasan/ede43a6b9d7d64e924cd301d12c475de to your computer and use it in GitHub Desktop.
Save Remonhasan/ede43a6b9d7d64e924cd301d12c475de to your computer and use it in GitHub Desktop.
Algorithm: Applewatch dataset with KMeans / research
# Author Remon Hasan, University of Asia Pacific
# Applewatch dataset solve with unsupervised way
# using KMeans
# implementation with google Colab
import pandas as pd
import numpy as np
data = pd.read_csv('AppleWatch.csv')
# mapping gender
data['Gender'].replace(to_replace ="M", value ="2", inplace = True)
data['Gender'].replace(to_replace ="F", value ="1", inplace = True)
#print(data['Gender'].head())
#data['Gender'].astype(int)
#mapping Activity
data['Activity'].replace(to_replace ="0.Sleep", value ="0", inplace = True)
data['Activity'].replace(to_replace ="1.Sedentary", value ="1", inplace = True)
data['Activity'].replace(to_replace ="2.Light", value ="2", inplace = True)
data['Activity'].replace(to_replace ="3.Moderate", value ="3", inplace = True)
data['Activity'].replace(to_replace ="4.Vigorous", value ="4", inplace = True)
#print(data['Activity'].head())
# Number of clusters
kmeans = KMeans(n_clusters=2)
# Fitting the input data
kmeans = kmeans.fit(data)
# Getting the cluster labels
labels = kmeans.predict(data)
print(labels)
# Centroid values
# centroids = kmeans.cluster_centers_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment