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
For some metal alloy, the following engineering stresses produce the corresponding engineering plastic strains prior to necking.
kirza4 [7]

Answer:

203.0160

Explanation:

Because you add then subtract then multiply buy 7 the subtract then divide then you add that to the other numbers you got than boom

7 0
2 years ago
How does the human body use phospholipids ?
Shtirlitz [24]
Phospholipids are crucial for building the protective barrier, or membrane, around your body's cells. In fact, phospholipids are synthesized in the body to form cell and organelle membranes. In blood and body fluids, phospholipids form structures in which fat is enclosed and transported throughout the bloodstream.
6 0
3 years ago
Read 2 more answers
If a particle moving in a circular path of radius 5 m has a velocity function v = 4t2 m/s, what is the magnitude of its total ac
rjkz [21]

Answer:

8.62m/s²

Explanation:

the particle is experiencing both translational and circular motion

v=4t²

a_{t}=\frac{dv}{dt}=8t

at t=1s, \frac{dv}{dt}=8(1)=8m/s²

a_{c} = \frac{v^{2} }{r}

at t=1, v= 4(1)² = 4m/s

a_{c}=4²/5

a_{c}=3.2m/s²

∴ magnitude of total acceleration, a

a=\sqrt{a_{t} ^{2} + a_{c} {2} }

a=\sqrt{8^{2} +3.2^{2}  }

a=\sqrt{64+10.24}

a=\sqrt{74.24}

a=8.62m/s²

5 0
3 years ago
Read 2 more answers
Technician A says that a voltage drop of 0.8 volts on the starter ground circuit is within specifications. Technician B says tha
Romashka-Z-Leto [24]

Answer:

Technician A is wrong

Technician B is right

Explanation:

voltage drop of 0.8 volts on the starter ground circuit is not within specifications. Voltage drop should be within the range of 0.2 V to 0.6 V but not more than that.

A spun bearing can seize itself around the crankshaft journal causing it not to move. As the car ignition system is turned on, the stater may draw high current in order to counter this seizure.

8 0
4 years ago
What is the solution to the system of equations?<br><br>2x-y=7<br>y=2x+3​
AleksAgata [21]

Answer:

No solution.

Explanation:

Solve with substitution or elimination.

If you use substitution, plug the expression for y in the second equation into the first equation.

2x − (2x + 3) = 7

2x − 2x − 3 = 7

-3 = 7

No solution.

If you use elimination, add the equations together to eliminate y.

2x − y + y = 7 + 2x + 3

2x = 10 + 2x

0 = 10

No solution.

There is no solution.

6 0
4 years ago
Other questions:
  • For H2O, determine the specified property at the indicated state.
    15·1 answer
  • PLEASE HELP, TEST MULTIPLE CHOICE QUESTIONS
    12·2 answers
  • Human settlement has 5 elements. How do you observe those 5 elements around you. Give examples.
    9·1 answer
  • Complete swap_bits function which swaps bits at odd and even positions of an integer (32 bits). In other words, every even posit
    15·1 answer
  • The acceleration of a point is given. a = 20 t m/s2 When t=0, s = 50 m and v = -8 m/s. What are the position and velocity of the
    13·1 answer
  • Why is it important for engineers to consider both short and long term implications of their work?
    9·1 answer
  • Pleaseeeeeeeeeeeeee answer
    15·2 answers
  • Which of the following would NOT be an enforcement responsibility of a local police officer?
    15·1 answer
  • 4. Set the height of the cutting tool tip
    5·1 answer
  • The metal control joints used to relieve stresses caused by expansion and contraction in large ceiling or wall expenses in inter
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!