<repo_name>11813147ak/Data-science-required-python<file_sep>/README.md
# Data-science-required-python<file_sep>/Seaborn practise.py
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


# In[4]:


tips=sns.load_dataset('tips')


# In[5]:


tips


# In[6]:


tips.head()


# In[9]:


# for categorical data

sns.barplot(x='sex',y='total_bill',data=tips)


# In[16]:


sns.countplot(x='time',data=tips)


# In[17]:


sns.countplot(x='sex',data=tips)


# In[34]:


sns.violinplot(x='day',y='total_bill',data=tips,hue='smoker',split=True)


# In[28]:


sns.boxplot(x='day',y='total_bill',data=tips,hue='smoker')


# In[22]:


tips.columns


# In[24]:


sns.boxplot(x='day',y='total_bill',data=tips)


# In[26]:


sns.pointplot(x='day',y='total_bill',data=tips)


# In[30]:


sns.stripplot(x='day',y='total_bill',data=tips)


# In[31]:


sns.boxenplot(x='day',y='total_bill',data=tips)


# In[39]:


# distribution plot

#it is a univariate


# In[43]:


sns.distplot(tips['total_bill'],kde=False,bins=40)


# In[45]:


sns.kdeplot(tips['total_bill'])


# In[56]:


sns.jointplot(x='total_bill',y='tip',data=tips,kind='kde')


# In[52]:


sns.distplot(tips['tip'],kde=False)


# In[57]:


sns.jointplot(x='total_bill',y='tip',data=tips,kind='reg')


# In[65]:


sns.pairplot(tips,hue='sex')


# In[66]:


sns.pairplot(tips,hue='smoker')


# In[67]:


sns.pairplot(tips)


# In[69]:


tips_corr=tips.corr()


# In[70]:


tips_corr


# In[73]:


sns.heatmap(tips_corr,annot=True)
# only with non categorical variables


# In[ ]:





# In[76]:


flights=sns.load_dataset('flights')


# In[77]:


flights.head()


# In[82]:


x=flights.pivot_table(index='month',columns='year',values="passengers")


# In[83]:


sns.heatmap(x)


# In[ ]:





# In[ ]:





# In[ ]:




<file_sep>/numpy session cb.py
#!/usr/bin/env python
# coding: utf-8

# In[67]:


import numpy as np
np.random.seed(1)


# In[68]:


np.random.randint(1,100,(5,5))


# In[69]:


x=np.array([1,2,4])


# In[70]:


x


# In[71]:


x.shape


# In[72]:


a=np.zeros((3,3))


# In[73]:


a


# In[74]:


b=np.ones((1,2))


# In[75]:


b


# In[76]:


np.full((3,2),5)


# In[77]:


x1=np.eye(4)


# In[78]:


x1


# In[79]:


x1[1,:]=5


# In[80]:


x1


# In[81]:


x=np.array([[1,2],[1,2]])
y=np.array([[1,2],[1,2]])


# In[82]:


np.add(x,y)


# In[83]:


np.subtract(x,y)


# In[84]:


np.divide(x,y)


# In[85]:


np.multiply(x,y)


# In[86]:


np.dot(x,y)


# In[87]:


xe=np.arange(10)+5


# In[88]:


np.random.shuffle(xe)
xe


# In[89]:


a=np.random.randn(2,3)


# In[90]:


a


# In[91]:


b=np.random.randint(5,10,2)


# In[92]:


b


# In[93]:


c=np.arange(66)+1
element=np.random.choice(c)
element


# In[ ]:





# In[97]:


a=np.array([[1,2,5,23,54,658],[65,67,657,7,87]])


# In[101]:


print(np.min(a,axis=0))


# In[104]:


print(np.max(a,axis=0))


# In[109]:


b=np.array([1,2,3,4,5,5,6,7,8,6,5,5,5,5])
m=sum(b)/5


# In[110]:


int(m)


# In[112]:


np.median(b)


# In[115]:


np.std(b)


# In[116]:


np.mean(b)


# In[117]:


np.average(b)


# In[118]:


np.var(b)


# In[ ]:





# In[ ]:





# In[ ]:





# In[ ]:





# In[ ]:




<file_sep>/Normal distribution 1D and 2D.py
#!/usr/bin/env python
# coding: utf-8

# In[2]:


# Generate a ND(1-D)
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


# In[16]:


u=2
sigma=3
vals=u+sigma*np.random.randn(1000)
plt.hist(vals)
plt.show()


# In[17]:


vals=np.round(vals)
z=np.unique(vals,return_counts=True)
print(z)


# In[ ]:





# In[ ]:





# In[24]:


u=5
sigma=5
vals=u+sigma*np.random.randn(100)
plt.hist(vals)
plt.show()


# In[25]:


x=vals
y=np.zeros(x.shape)
plt.scatter(x,y)
plt.show()


# In[ ]:





# In[ ]:


# Generate a ND (MULTI VARIATE)


# In[36]:


mean=np.array([0.0,0.0])
cov=np.array([[1,0.8],[0.8,1]])
mean2=np.array([5.0,6.0])
cov2=np.array([[1.3,0.2],[0.2,1.1]])
dist=np.random.multivariate_normal(mean,cov,500)
dist2=np.random.multivariate_normal(mean2,cov2,500)
print(dist.shape)
plt.scatter(dist[:,0],dist[:,1])
plt.scatter(dist2[:,0],dist2[:,1])
plt.show()


# In[ ]:


b

<file_sep>/Visualization.py
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[10]:


x=np.array([[1,2,3,4,5,1,2,3,4]])


# In[11]:


x


# In[12]:


x.T


# In[14]:


x.reshape(3,3)


# In[18]:


import pandas as pd
import matplotlib.pyplot as plt


# In[23]:


x=np.arange(10)
y=x**2


# In[24]:


plt.plot(x,y)


# In[44]:


plt.plot(x,y,label='graph')
plt.plot(y,x,label='kiwi')
plt.xlabel('graph')
plt.ylabel('kiwi')
plt.legend()


# In[27]:


plt.style.available


# In[32]:


plt.style.use('seaborn')


# In[40]:


get_ipython().run_line_magic('pinfo', 'plt.plot')


# In[42]:


#scatter


# In[49]:


plt.figure(figsize=(5,5))
plt.scatter(x,y,label='graph',marker='o')
plt.scatter(y,x,label='kiwi',marker='^')
plt.xlabel('graph')
plt.ylabel('kiwi')
plt.legend()


# In[50]:


#bar graph


# In[57]:


plt.bar(x,y,width=0.4)


# In[66]:


plt.figure(figsize=(7,5))
x_coordinates=np.array([0,1,2])*2
plt.bar(x_coordinates,[10,20,15],width=0.5,label='Current year',tick_label=['Gold','Platinum','Diamond'])
plt.bar(x_coordinates+0.5,[20,10,12],width=0.5,label='Next year')
plt.legend()
plt.show()


# In[68]:


plt.style.available


# In[71]:


plt.style.use('fivethirtyeight')
plt.figure(figsize=(7,5))
x_coordinates=np.array([0,1,2])*2
plt.bar(x_coordinates,[10,20,15],width=0.5,label='Current year',tick_label=['Gold','Platinum','Diamond'])
plt.bar(x_coordinates+0.5,[20,10,12],width=0.5,label='Next year')
plt.legend()
plt.show()


# In[73]:


#pie


# In[81]:


plt.pie(x,explode=None)
plt.show()


# In[98]:


subjects='Maths','english','hindi','sanskrit'
marks=[20,25,45,64]
plt.pie(marks,labels=subjects,explode=(0,0,0.1,0),shadow=True,counterclock=True,autopct='%1.1f%%')
plt.show()


# In[96]:


get_ipython().run_line_magic('pinfo', 'plt.pie')


# In[99]:


#histogram


# In[118]:


xsn=np.random.randn(100)
sigma=8
u=70
X=np.round(xsn*sigma+u)
X2=np.round(xsn*15+40)
print(X)


# In[112]:


print(xsn)


# In[120]:


plt.style.use('seaborn')
plt.hist(X,alpha=0.8,label='Physics')
plt.hist(X2,alpha=0.9,label="Maths")


# In[ ]:




<file_sep>/Mnist dataset.py
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


# In[5]:


read=pd.read_csv('C:/Users/HP/Desktop/train.csv')


# In[6]:


read.shape


# In[7]:


read.head()


# In[13]:


print(type(read))


# In[37]:


data=read.values
np.random.shuffle(data)


# In[17]:


print(type(data))


# In[18]:


data.shape


# In[19]:


X=data[:,1:]
Y=data[:,0]


# In[20]:


print(X.shape,Y.shape)


# In[21]:


print(X)


# In[23]:


print(Y)


# In[24]:


#to visualise one image


# In[25]:


X[0].shape


# In[40]:


def drawimg(X,Y,i):
    plt.imshow(X[i].reshape(28,28),cmap='gray')
    plt.title("Label "+str(Y[i]))
    plt.show()



for i in range(5):
    drawimg(X,Y,i)


# In[34]:


split=int(0.80*X.shape[0])
print(split)


# In[48]:


from sklearn.model_selection import train_test_split
XT,Xt,YT,Yt=train_test_split(X,Y,test_size=0.2,random_state=5)
print(XT.shape,YT.shape)
print(Xt.shape,Yt.shape)


# In[47]:


plt.figure(figsize=(10,10))
for i in range(25):
    plt.subplot(5,5,i+1)
    plt.imshow(XT[i].reshape(28,28))
    plt.title(YT[i])
    plt.axis("off")


# In[ ]:




