1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elanso [62]
4 years ago
12

1. Implement the k-means clustering algorithm either in Java or Python. • The program should be executable with at least 3 param

eters: the name of the dataset file, k, and the name of the output file. • The output file should contain numerical class labels (formatted as one number per row) for all the records in the test dataset and report the sum squared error (SSE) and silhouette coefficient in the last row. • You only need to handle numerical attributes (categorical attributes are not required).
Engineering
1 answer:
givi [52]4 years ago
4 0

Answer:

The code for this Question in Python is as follows:

matplotlib inline

from copy import deepcopy

import numpy as np

import pandas as pd

from matplotlib import pyplot as plt

plt.rcParams['figure.figsize'] = (16, 9)

plt.style.use('ggplot')

# Importing the dataset

data = pd.read_csv('xclara.csv')

print(data.shape)

data.head()

# Getting the values and plotting it

f1 = data['V1'].values

f2 = data['V2'].values

X = np.array(list(zip(f1, f2)))

plt.scatter(f1, f2, c='black', s=7)

# Number of clusters

k = 3

# X coordinates of random centroids

C_x = np.random.randint(0, np.max(X)-20, size=k)

# Y coordinates of random centroids

C_y = np.random.randint(0, np.max(X)-20, size=k)

C = np.array(list(zip(C_x, C_y)), dtype=np.float32)

print(C)

# To store the value of centroids when it updates

C_old = np.zeros(C.shape)

# Cluster Lables(0, 1, 2)

clusters = np.zeros(len(X))

# Error func. - Distance between new centroids and old centroids

error = dist(C, C_old, None)

# Loop will run till the error becomes zero

while error != 0:

   # Assigning each value to its closest cluster

   for i in range(len(X)):

       distances = dist(X[i], C)

       cluster = np.argmin(distances)

       clusters[i] = cluster

   # Storing the old centroid values

   C_old = deepcopy(C)

   # Finding the new centroids by taking the average value

   for i in range(k):

       points = [X[j] for j in range(len(X)) if clusters[j] == i]

       C[i] = np.mean(points, axis=0)

   error = dist(C, C_old, None)

# Initializing KMeans

kmeans = KMeans(n_clusters=4)

# Fitting with inputs

kmeans = kmeans.fit(X)

# Predicting the clusters

labels = kmeans.predict(X)

# Getting the cluster centers

C = kmeans.cluster_centers_

fig = plt.figure()

ax = Axes3D(fig)

ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=y)

ax.scatter(C[:, 0], C[:, 1], C[:, 2], marker='*', c='#050505', s=1000)

You might be interested in
A train travels 650 meters in 25 seconds. What is the train's velocity?
frosja888 [35]

The train is traveling 26 meters A second .

3 0
3 years ago
Tires can be recycled instead of thrown out.<br> True<br> False
Arisa [49]

Answer:

True :)

Explanation:

You can recycle it! Tire recycling is the most practical and environment-friendly way of disposing of old and worn-out tires. Due to their inherent durability, large volume and environment and health risks, tires are one of the most problematic sources of solid wastes.

Hope it helped have a nice day! :)

8 0
3 years ago
A rod that was originally 100-cm-long experiences a strain of 82%. What is the new length of the rod?
Ierofanga [76]

Answer: (b)

Explanation:

Given

Original length of the rod is L=100\ cm

Strain experienced is \epsilon=82\%=0.82

Strain is the ratio of the change in length to the original length

\Rightarrow \epsilon =\dfrac{\Delta L}{L}\\\\\Rightarrow 0.82=\dfrac{\Delta L}{100}\\\\\Rightarrow \Delta L=82\ cm

Therefore, new length is given by (Considering the load is tensile in nature)

\Rightarrow L'=\Delta L+L\\\Rightarrow L'=82+100=182\ cm

Thus, option (b) is correct.

8 0
3 years ago
What did the discovery of the Cumberland Gap mean for exploration? PLEASE HELP ILL GIVE YOU BRAINLEIST!
Flauer [41]

Answer: D. Many more people crossed the mountains and settled between the Appalachians and the Mississippi

Explanation:

It was quite difficult to cross the Appalachian mountains at the time of the American colonies which led to the colonies being confined to the east of it.

This was until the late 1700s when Daniel Boone and a team of explorers heard that a path existed through the Appalachians and had been used by natives for a long time. After discovering this ''gap'' which was then named after an English prince, many more people were able to use it to settle more to the west of the continent.

6 0
3 years ago
Daisy received a class assignment for writing statements in first-order logic form. What option should Daisy use to represent th
Kay [80]
Choose the one you feel that right
5 0
4 years ago
Other questions:
  • Microchips found inside most electronic devices today are examples of what material A. Polymers B. Alloys C. Composites D. None
    10·2 answers
  • A car is towed into a shop with a no-start problem. The engine cranks but will not fire and run on its own power. The car has a
    9·2 answers
  • The streamlines for an incompressible, inviscid, two dimensional flow field are all concentric circles, and the velocity varies
    8·1 answer
  • When the rope is at an angle of α = 30°, the 1-kg sphere A has a speed v0 = 0.6 m/s. The coefficient of restitution between A an
    8·1 answer
  • What is the mechanical advantage of a simple block and tackle with one rope?
    7·2 answers
  • While rowing across a lake, John does 3960 ft-lbs of work over 120 ft. How much force is John using?
    13·1 answer
  • 3) The box lands on the surface of the earth.​
    8·2 answers
  • An electric iron has a resistance of 12Ω and takes a current of 2A. Therefore the supply voltage will be
    11·1 answer
  • How to find the ima of a wedge
    11·2 answers
  • Based on your client's request, you will now create a sketch model of your designed pet toy. You will use your technical sketch
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!