You are on page 1of 5

11/7/22, 3:11 PM Untitled49

In [2]: #katakam saikumar

#RA2011053010059

#a

import matplotlib.pyplot as plt

import seaborn as sns

sns.set_context('paper')

#load data set

titanic=sns.load_dataset('titanic')

print(titanic)

#create plot

sns.countplot(x='class',hue='who',data=titanic,palette='magma')

plt.title('survivors')

plt.show()

g=sns.catplot(x="age",y="embarked",hue="sex",row="pclass",

data=titanic[titanic.embarked.notnull()],orient="h",height=2,aspect=3
palette={'male':'purple','female':'blue'},kind="violin",split=True,cu

survived pclass sex age sibsp parch fare embarked class \

0 0 3 male 22.0 1 0 7.2500 S Third

1 1 1 female 38.0 1 0 71.2833 C First

2 1 3 female 26.0 0 0 7.9250 S Third

3 1 1 female 35.0 1 0 53.1000 S First

4 0 3 male 35.0 0 0 8.0500 S Third

.. ... ... ... ... ... ... ... ... ...

886 0 2 male 27.0 0 0 13.0000 S Second

887 1 1 female 19.0 0 0 30.0000 S First

888 0 3 female NaN 1 2 23.4500 S Third

889 1 1 male 26.0 0 0 30.0000 C First

890 0 3 male 32.0 0 0 7.7500 Q Third

who adult_male deck embark_town alive alone

0 man True NaN Southampton no False

1 woman False C Cherbourg yes False

2 woman False NaN Southampton yes True

3 woman False C Southampton yes False

4 man True NaN Southampton no True

.. ... ... ... ... ... ...

886 man True NaN Southampton no True

887 woman False B Southampton yes True

888 woman False NaN Southampton no False

889 man True C Cherbourg yes True

890 man True NaN Queenstown no True

[891 rows x 15 columns]

localhost:8888/nbconvert/html/Untitled49.ipynb?download=false 1/5
11/7/22, 3:11 PM Untitled49

In [4]: #b

# strip plot

import seaborn

seaborn.set(style='whitegrid')

fmri = seaborn.load_dataset("fmri")

print(fmri)

seaborn.stripplot(x="timepoint", y="signal",data=fmri)

#swarm plot

import seaborn

seaborn.set(style='whitegrid')

fmri = seaborn.load_dataset("fmri")

print(fmri)

seaborn.swarmplot(x="timepoint", y="signal",size =1.5, data=fmri)

localhost:8888/nbconvert/html/Untitled49.ipynb?download=false 2/5
11/7/22, 3:11 PM Untitled49

subject timepoint event region signal

0 s13 18 stim parietal -0.017552

1 s5 14 stim parietal -0.080883

2 s12 18 stim parietal -0.081033

3 s11 18 stim parietal -0.046134

4 s10 18 stim parietal -0.037970

... ... ... ... ... ...

1059 s0 8 cue frontal 0.018165

1060 s13 7 cue frontal -0.029130

1061 s12 7 cue frontal -0.004939

1062 s11 7 cue frontal -0.025367

1063 s0 0 cue parietal -0.006899

[1064 rows x 5 columns]

subject timepoint event region signal

0 s13 18 stim parietal -0.017552

1 s5 14 stim parietal -0.080883

2 s12 18 stim parietal -0.081033

3 s11 18 stim parietal -0.046134

4 s10 18 stim parietal -0.037970

... ... ... ... ... ...

1059 s0 8 cue frontal 0.018165

1060 s13 7 cue frontal -0.029130

1061 s12 7 cue frontal -0.004939

1062 s11 7 cue frontal -0.025367

1063 s0 0 cue parietal -0.006899

[1064 rows x 5 columns]

<AxesSubplot:xlabel='timepoint', ylabel='signal'>
Out[4]:

In [11]: #c

from sklearn.datasets import load_iris

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

data = load_iris()

X = data.data

# convert features in column 1 from cm to inches

X[:,0] /= 2.54

# convert features in column 2 from cm to meters

X[:,1] /= 100

from sklearn.decomposition import PCA

def scikit_pca(X):

# Standardize

X_std = StandardScaler().fit_transform(X)

# PCA

sklearn_pca = PCA(n_components=2)

localhost:8888/nbconvert/html/Untitled49.ipynb?download=false 3/5
11/7/22, 3:11 PM Untitled49

X_transf = sklearn_pca.fit_transform(X_std)

# Plot the data

plt.figure(figsize=(11,11))

plt.scatter(X_transf[:,0], X_transf[:,1], s=600, color='#8383c4',alpha=0.56)

plt.title('PCA via scikit-learn (using SVD)', fontsize=20)

plt.xlabel('Petal Width', fontsize=15)

plt.ylabel('Sepal Length', fontsize=15)

plt.show()

scikit_pca(X)

In [15]: #d

from numpy import random,argsort,sqrt

from pylab import plot,show

import matplotlib.pyplot as plt

def knn_search(x, data, K):

ndata = data.shape[1]

K = K if K < ndata else ndata

# euclidean distances from the other points

sqd = sqrt(((data - x[:,:ndata])**2).sum(axis=0))

idx = argsort(sqd) # sorting

# return the indexes of K nearest neighbors

return idx[:K]

data = random.rand(2,200) # random dataset

x = random.rand(2,1) # query point

neig_idx = knn_search(x,data,10)

plt.figure(figsize=(12,12))

localhost:8888/nbconvert/html/Untitled49.ipynb?download=false 4/5
11/7/22, 3:11 PM Untitled49

# plotting the data and the input point

plot(data[0,:],data[1,:],'o', x[0,0],x[1,0],'o', color='#9a88a1',markersize=20)

# highlighting the neighbors

plot(data[0,neig_idx],data[1,neig_idx],'o', markerfacecolor='#BBE4B4',markersize=22
show()

In [ ]:

localhost:8888/nbconvert/html/Untitled49.ipynb?download=false 5/5

You might also like