text_plain_output_1.png
from sklearn.decomposition import PCA

import io

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import numpy as np

import pandas as pd

import pandas as pd

import requests

import pandas as pd
data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data', header=None)
data.columns = ['Sample code', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape', 'Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin', 'Normal Nucleoli', 'Mitoses', 'Class']
data = data.drop(['Sample code'], axis=1)

import numpy as np
data = data.replace('?', np.NaN)

data2 = data['Bare Nuclei']
data2 = data2.fillna(data2.median())

data2 = data.dropna()

Z = (data2 - data2.mean()) / data2.std()
Z[20:25]

dups = data.duplicated()
data.loc[[11, 28]]

data2 = data.drop_duplicates()

#modified to load from remote URL, Ye 2021
import requests
import io
url = "https://cgi.luddy.indiana.edu/~yye/b565/data/DTW_prec.csv"
s=requests.get(url).content
daily = pd.read_csv(io.StringIO(s.decode('utf-8')), header='infer')
daily.index = pd.to_datetime(daily['DATE'])
daily = daily['PRCP']
ax = daily.plot(kind='line',figsize=(15,3))
ax.set_title('Daily Precipitation (variance = %.4f)' % (daily.var()))

monthly = daily.groupby(pd.Grouper(freq='M')).sum()
ax = monthly.plot(kind='line',figsize=(15,3))
ax.set_title('Monthly Precipitation (variance = %.4f)' % (monthly.var()))

annual = daily.groupby(pd.Grouper(freq='Y')).sum()
ax = annual.plot(kind='line',figsize=(15,3))
ax.set_title('Annual Precipitation (variance = %.4f)' % (annual.var()))

sample = data.sample(n=3)
sample

sample = data.sample(frac=0.01, random_state=1)
sample

sample = data.sample(frac=0.01, replace=True, random_state=1)
sample

bins = pd.cut(data['Clump Thickness'], 4)
bins.value_counts(sort=False)

bins = pd.qcut(data['Clump Thickness'], 4)
bins.value_counts(sort=False)

import pandas as pd
from sklearn.decomposition import PCA
numComponents = 2
pca = PCA(n_components=numComponents)
pca.fit(imgData)
projected = pca.transform(imgData)
projected = pd.DataFrame(projected, columns=['pc1', 'pc2'], index=range(1, numImages + 1))
projected['food'] = ['burger', 'burger', 'burger', 'burger', 'drink', 'drink', 'drink', 'drink', 'pasta', 'pasta', 'pasta', 'pasta', 'chicken', 'chicken', 'chicken', 'chicken']
projected

import matplotlib.pyplot as plt
colors = {'burger': 'b', 'drink': 'r', 'pasta': 'g', 'chicken': 'k'}
markerTypes = {'burger': '+', 'drink': 'x', 'pasta': 'o', 'chicken': 's'}
for foodType in markerTypes:
    d = projected[projected['food'] == foodType]
    plt.scatter(d['pc1'], d['pc2'], c=colors[foodType], s=60, marker=markerTypes[foodType])