Ticker

6/recent/ticker-posts

Sklearn Prediction Model - KMeans


In this post, we are gonna make a machine learning program using KMeans prediction model and implement this on breast_cancer dataset. Then we are gonna check our accuracy score.

We are gonna use machine learning libraries like Pandas and Sklearn.

There's is no need to download Breast Cancer dataset as its preinstalled with Sklearn. Just load the dataset in any variable.


 Preview:

  import pandas as pd
  from sklearn.cluster import KMeans
  from sklearn.model_selection import train_test_split
  from sklearn import datasets
  from sklearn.metrics import accuracy_score


  bc= datasets.load_breast_cancer()

  x= bc.data
  y= bc.target

  model= KMeans(n_clusters=2, random_state=0)

  x_train, x_test, y_train, y_test= train_test_split(x, y, test_size=0.2)

  model.fit(x_train)

  predictions= model.predict(x_test)
  labels= model.labels_
  print(predictions)
  print("accuracy : ", accuracy_score(y_test, predictions))
  print(y_test)

  print(pd.crosstab(y_train,labels))

Post a Comment

0 Comments