Write a python program to fit and predict based on the KMeans algorithm. 1. Take a random sample of 100 rows 2. Compute KMeans on the first two rows: s_length, s_width (sepal length and width) 3. Print out your predictions for k=5andk-7 4. for k = 3, predict the following os_length = 5.2, s_width = 3.8, os_length = 4.2, s_width = 2.2,

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Pls solve this question correctly in 5 min i will give u like for sure

 

import seaborn as sns

 

import pandas as pd

 

import numpy as np

 

from sklearn.cluster import KMeans

 

from sklearn import datasets

 

# download the iris datafile

 

X,y = datasets.load_iris(return_X_y=True,)

 

cols = ['s_length','s_width','p_length','p_width']

 

df = pd.DataFrame(X, columns=cols)

 

df['class'] = y

 

df

 

sns.scatterplot(data=df, x='s_length', y='p_width', hue='class')

 

from sklearn.model_selection import train_test_split

 

train, test = train_test_split(df, test_size=0.4)

 

X = train[['s_length', 'p_width']].to_numpy()

 

y = train[['class']].to_numpy()

 

k = 3

 

model = KMeans(n_clusters=k)

 

model.fit_predict(X, y)

 

s = model.score(X,y)

Write a python program to fit and predict based on the KMeans algorithm.
1. Take a random sample of 100 rows
2. Compute KMeans on the first two rows: s_length, s_width (sepal length and width)
3. Print out your predictions for k=5andk=7
4. for k= 3, predict the following
os_length = 5.2, s_width = 3.8,
os_length = 4.2, s_width = 2.2,
Transcribed Image Text:Write a python program to fit and predict based on the KMeans algorithm. 1. Take a random sample of 100 rows 2. Compute KMeans on the first two rows: s_length, s_width (sepal length and width) 3. Print out your predictions for k=5andk=7 4. for k= 3, predict the following os_length = 5.2, s_width = 3.8, os_length = 4.2, s_width = 2.2,
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education