In [2]:
from sklearn import decomposition
from sklearn import datasets
In [3]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
In [4]:
np.random.seed(5)
centers = [[1, 1], [-1, -1], [1, -1]]
iris = datasets.load_iris()
X = iris.data
y = iris.target
In [5]:
X
Out[5]:
In [7]:
y
Out[7]:
In [9]:
import pandas as pd
In [10]:
adult=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",header=None)
In [11]:
adult.columns=["age ",
"workclass ",
"fnlwgt",
"education ",
"education-num",
"marital-status",
"occupation",
"relationship",
"race",
"sex",
"capital-gain",
"capital-loss",
"hours-per-week",
"native-country",
"income",
]
In [16]:
adult.dtypes
Out[16]:
In [13]:
y=adult.income.values
y
Out[13]:
In [17]:
#Only numeric data for PCA
X=adult[["age ","fnlwgt","education-num","capital-gain","capital-loss","hours-per-week"]].values
X
Out[17]:
fig = plt.figure(1, figsize=(4, 3)) plt.clf() ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134) plt.cla()
In [18]:
pca = decomposition.PCA(n_components=3)
pca.fit(X)
X = pca.transform(X)
In [19]:
X
Out[19]:
for name, label in [('Setosa', 0), ('Versicolour', 1), ('Virginica', 2)]: ax.text3D(X[y == label, 0].mean(), X[y == label, 1].mean() + 1.5, X[y == label, 2].mean(), name, horizontalalignment='center', bbox=dict(alpha=.5, edgecolor='w', facecolor='w'))
y = np.choose(y, [1, 2, 0]).astype(np.float) ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=y, cmap=plt.cm.spectral, edgecolor='k')
ax.w_xaxis.set_ticklabels([]) ax.w_yaxis.set_ticklabels([]) ax.w_zaxis.set_ticklabels([])
In [20]:
%matplotlib inline
In [21]:
import seaborn as sns
iris = sns.load_dataset("iris")
sns.pairplot(iris)
Out[21]:
In [22]:
import matplotlib
import matplotlib.pyplot as plt
In [23]:
x=[1,2,3]
y=[5,6,9]
In [24]:
plt.plot(x,y)
Out[24]:
In [28]:
plt.plot(x,y)
plt.xlabel('Customers')
plt.ylabel('Age')
plt.title('First Graph')
Out[28]:
In [29]:
iris=pd.read_csv('https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/iris.csv')
In [30]:
iris.columns
Out[30]:
In [39]:
iris.columns=['Unnamed: 0', 'Sepal_Length', 'Sepal_Width', 'Petal_Length','Petal_Width', 'Species']
In [45]:
y=iris.groupby('Species').Sepal_Length.mean().reset_index()
In [49]:
y.Sepal_Length
Out[49]:
In [50]:
x=iris.Species
In [55]:
plt.plot(iris.Sepal_Length,iris.Petal_Length)
Out[55]:
In [59]:
plt.bar(iris.Sepal_Length,iris.Petal_Length,label='bar1',color='blue')
Out[59]:
In [62]:
iris.plot(x='Sepal_Length',y='Petal_Length')
Out[62]:
In [67]:
import seaborn as sns
In [69]:
def sinplot(flip=1):
x = np.linspace(0, 14, 100)
for i in range(1, 7):
plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip)
In [70]:
sinplot()
In [71]:
diamonds=pd.read_csv('https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/Ecdat/Diamond.csv')
In [72]:
diamonds.head()
Out[72]:
In [75]:
diamonds=diamonds.drop( 'Unnamed: 0',1)
In [76]:
diamonds.head()
Out[76]:
In [77]:
sns.distplot(diamonds.price,kde=True,rug=True)
Out[77]:
In [78]:
sns.kdeplot(diamonds.price,shade=True)
Out[78]:
In [79]:
import os as os
In [80]:
os.getcwd()
Out[80]:
In [81]:
os.chdir('C:\\Users\\KOGENTIX\\Desktop\\trainingWeek2')
In [83]:
diamonds.to_csv("diamonds2.csv")
In [84]:
sns.jointplot(x='price',y='carat',data=diamonds)
Out[84]:
In [86]:
sns.jointplot(x='price',y='carat',kind="hex",data=diamonds)
Out[86]:
In [87]:
sns.jointplot(x='price',y='carat',kind="kde",data=diamonds)
Out[87]:
In [88]:
sns.pairplot(iris)
Out[88]:
In [89]:
sns.pairplot(diamonds)
Out[89]:
In [90]:
sns.regplot(x='price',y='carat',data=diamonds)
Out[90]:
In [91]:
sns.lmplot(x='price',y='carat',data=diamonds)
Out[91]:
In [93]:
sns.lmplot(x='price',y='carat',hue='colour',data=diamonds)
Out[93]:
In [94]:
sns.stripplot(x='colour',y='carat',data=diamonds)
Out[94]:
In [95]:
sns.stripplot(x='colour',y='price',data=diamonds)
Out[95]:
In [98]:
sns.stripplot(x='clarity',y='price',data=diamonds)
Out[98]:
In [97]:
diamonds.head()
Out[97]:
In [99]:
sns.swarmplot(x='clarity',y='price',data=diamonds)
Out[99]:
In [100]:
sns.swarmplot(x='clarity',y='price',hue='colour',data=diamonds)
Out[100]:
In [102]:
sns.boxplot(x='clarity',y='price',hue='colour',data=diamonds)
Out[102]:
In [103]:
sns.boxplot(hue='clarity',y='price',x='colour',data=diamonds)
Out[103]:
In [104]:
sns.boxplot(y='price',x='colour',data=diamonds)
Out[104]:
In [105]:
sns.violinplot(hue='clarity',y='price',x='colour',data=diamonds)
Out[105]:
In [106]:
sns.violinplot(y='price',x='colour',data=diamonds)
Out[106]:
In [107]:
sns.barplot(hue='clarity',y='price',x='colour',data=diamonds)
Out[107]:
In [108]:
sns.barplot(y='price',x='colour',data=diamonds)
Out[108]:
In [109]:
sns.countplot(x='colour',data=diamonds)
Out[109]:
In [110]:
sns.pointplot(hue='clarity',y='price',x='colour',data=diamonds)
Out[110]:
In [112]:
sns.factorplot(hue='clarity',x='colour',y='price',col='certification',data=diamonds)
Out[112]:
In [113]:
sns.factorplot(hue='clarity',x='colour',y='price',col='certification',data=diamonds,kind='bar')
Out[113]:
In [ ]: