# -*- coding: utf-8 -*-
"""apartment_newsletter_clusters.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1KnGLoqQuMbVGH420PyTqGVbPxiLSFcTy
"""

import pandas as pd

import nltk

!pip install urlopen

nltk.download('punkt')

import nltk

from urllib.request import urlopen

from bs4 import BeautifulSoup

url=('which ever webpage')

html = urlopen(url).read()

import ast

raw = BeautifulSoup(html).get_text()

tokens = nltk.word_tokenize(raw)

print(tokens)

print(raw)







from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.cluster import KMeans

vectorizer = TfidfVectorizer(stop_words='english')

x = vectorizer.fit_transform(tokens)

true_k = 7

model = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1)

model.fit(x)

ordered_centroids = model.cluster_centers_.argsort()[:, ::-1]

print(ordered_centroids)

b =ordered_centroids

print(model.cluster_centers_)

import numpy as np

terms = vectorizer.get_feature_names

terms()

print(f"cluster_centers:\n{model.cluster_centers_}")

y = vectorizer.transform(["Interesting Reviews"])

predicted = model.predict(y)

print(predicted)

v = vectorizer.transform(["Apartement newlsetters is not forever"])

predicted1 = model.predict(v)

print(predicted1)

x= x.reshape(1,-1)
y = y.reshape(1,-1)

x.shape

y.shape

true_k

import matplotlib.pyplot as plt
plt.figure(figsize=(16,10))
plt.scatter(b[:,0],b[:,0], color='k', label='ordred centorids' )
plt.scatter(predicted, predicted1, color='g',label='predicted clusters although both predictions were assigned to the same cluster at cluster 16')
plt.title("Appropriate Title")
plt.legend(loc='upper left')
plt.show()

# -*- coding: utf-8 -*-
"""apartment_newsletter_clusters.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1KnGLoqQuMbVGH420PyTqGVbPxiLSFcTy
"""

import pandas as pd

import nltk

!pip install urlopen

nltk.download('punkt')

import nltk

from urllib.request import urlopen

from bs4 import BeautifulSoup

url=('which ever webpage')

html = urlopen(url).read()

import ast

raw = BeautifulSoup(html).get_text()

tokens = nltk.word_tokenize(raw)

print(tokens)

print(raw)







from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.cluster import KMeans

vectorizer = TfidfVectorizer(stop_words='english')

x = vectorizer.fit_transform(tokens)

true_k = 7

model = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1)

model.fit(x)

ordered_centroids = model.cluster_centers_.argsort()[:, ::-1]

print(ordered_centroids)

b =ordered_centroids

print(model.cluster_centers_)

import numpy as np

terms = vectorizer.get_feature_names

terms()

print(f"cluster_centers:\n{model.cluster_centers_}")

y = vectorizer.transform(["Interesting Reviews"])

predicted = model.predict(y)

print(predicted)

v = vectorizer.transform(["Apartement newlsetters is not forever"])

predicted1 = model.predict(v)

print(predicted1)

x= x.reshape(1,-1)
y = y.reshape(1,-1)

x.shape

y.shape

true_k

import matplotlib.pyplot as plt
plt.figure(figsize=(16,10))
plt.scatter(b[:,0],b[:,0], color='k', label='ordred centorids' )
plt.scatter(predicted, predicted1, color='g',label='predicted clusters although both predictions were assigned to the same cluster at cluster 16')
plt.title("Appropriate Title")
plt.legend(loc='upper left')
plt.show()

# -*- coding: utf-8 -*- apartment_newsletter_clusters.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/1KnGLoqQuMbVGH420PyTqGVbPxiLSFcTy