This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #training k-means model | |
| from sklearn.cluster import KMeans | |
| kmeans = KMeans(n_clusters=4) | |
| kmeans.fit(data) | |
| #predictions from kmeans | |
| pred = kmeans.predict(data) | |
| frame = pd.DataFrame(data) | |
| frame['cluster'] = pred | |
| frame.columns = ['Weight', 'Height', 'cluster'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| #Loading dataset – User_Data | |
| dataset = pd.read_csv('...\\User_Data.csv') | |
| #Now, to predict whether a user will purchase the product or not, one needs to find out the relationship between Age and Estimated Salary. Here User ID and Gender are not important factors for finding out this. | |
| # input | |
| x = dataset.iloc[:, [2, 3]].values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| #Loading dataset – User_Data | |
| dataset = pd.read_csv('...\\User_Data.csv') | |
| #Now, to predict whether a user will purchase the product or not, one needs to find out the relationship between Age and Estimated Salary. Here User ID and Gender are not important factors for finding out this. | |
| # input | |
| x = dataset.iloc[:, [2, 3]].values |