0% found this document useful (0 votes)
4 views

Assignment 11

Web Technology Assignment

Uploaded by

rp7895798
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 11

Web Technology Assignment

Uploaded by

rp7895798
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

assignment-11

November 3, 2024

[1]: import pandas as pd

[5]: df = pd.read_csv("sales_data_sample.csv", encoding_errors = 'ignore')

[6]: df

[6]: ORDERNUMBER QUANTITYORDERED PRICEEACH ORDERLINENUMBER SALES \


0 10107 30 95.70 2 2871.00
1 10121 34 81.35 5 2765.90
2 10134 41 94.74 2 3884.34
3 10145 45 83.26 6 3746.70
4 10159 49 100.00 14 5205.27
… … … … … …
2818 10350 20 100.00 15 2244.40
2819 10373 29 100.00 1 3978.51
2820 10386 43 100.00 4 5417.57
2821 10397 34 62.24 1 2116.16
2822 10414 47 65.52 9 3079.44

STATUS QTR_ID MONTH_ID YEAR_ID PRODUCTLINE … \


0 Shipped 1 2 2003 Motorcycles …
1 Shipped 2 5 2003 Motorcycles …
2 Shipped 3 7 2003 Motorcycles …
3 Shipped 3 8 2003 Motorcycles …
4 Shipped 4 10 2003 Motorcycles …
… … … … … … …
2818 Shipped 4 12 2004 Ships …
2819 Shipped 1 1 2005 Ships …
2820 Resolved 1 3 2005 Ships …
2821 Shipped 1 3 2005 Ships …
2822 On Hold 2 5 2005 Ships …

ADDRESSLINE1 ADDRESSLINE2 CITY STATE \


0 897 Long Airport Avenue NaN NYC NY
1 59 rue de l'Abbaye NaN Reims NaN
2 27 rue du Colonel Pierre Avia NaN Paris NaN
3 78934 Hillside Dr. NaN Pasadena CA

1
4 7734 Strong St. NaN San Francisco CA
… … … … …
2818 C/ Moralzarzal, 86 NaN Madrid NaN
2819 Torikatu 38 NaN Oulu NaN
2820 C/ Moralzarzal, 86 NaN Madrid NaN
2821 1 rue Alsace-Lorraine NaN Toulouse NaN
2822 8616 Spinnaker Dr. NaN Boston MA

POSTALCODE COUNTRY TERRITORY CONTACTLASTNAME CONTACTFIRSTNAME DEALSIZE


0 10022 USA NaN Yu Kwai Small
1 51100 France EMEA Henriot Paul Small
2 75508 France EMEA Da Cunha Daniel Medium
3 90003 USA NaN Young Julie Medium
4 NaN USA NaN Brown Julie Medium
… … … … … … …
2818 28034 Spain EMEA Freyre Diego Small
2819 90110 Finland EMEA Koskitalo Pirkko Medium
2820 28034 Spain EMEA Freyre Diego Medium
2821 31000 France EMEA Roulet Annette Small
2822 51003 USA NaN Yoshido Juri Medium

[2823 rows x 23 columns]

[7]: x = df[['PRICEEACH', 'SALES']]


x

[7]: PRICEEACH SALES


0 95.70 2871.00
1 81.35 2765.90
2 94.74 3884.34
3 83.26 3746.70
4 100.00 5205.27
… … …
2818 100.00 2244.40
2819 100.00 3978.51
2820 100.00 5417.57
2821 62.24 2116.16
2822 65.52 3079.44

[2823 rows x 2 columns]

[9]: from sklearn.cluster import KMeans

wcss = []

for i in range(1, 11):


kmeans = KMeans(n_clusters = i, init = "k-means++", random_state = 45)

2
kmeans.fit(x)
wcss.append(kmeans.inertia_)

[10]: import matplotlib.pyplot as plt

[11]: plt.figure(figsize = (10, 8))


plt.plot(range(1, 11), wcss)
plt.title("Elbow Method")
plt.xlabel("No. of clusters")
plt.ylabel("WCSS value")
plt.show()

[13]: kmeans = KMeans(n_clusters = 3, init = 'k-means++', n_init = 'auto',␣


↪random_state = 45)

[14]: kmeans.fit_predict(x)

[14]: array([0, 0, 2, …, 2, 0, 0])

3
[ ]:

You might also like