In [4]:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(color_codes=True)
%matplotlib inline
In [5]:
df = pd.read_csv('iris.data')
In [6]:
df.head()
Out[6]:
In [7]:
pd.read_csv?
In [8]:
df = pd.read_csv('iris.data', header=-1)
df.head()
Out[8]:
In [9]:
col_name = ['sepal length', 'sepal width', 'petal length', 'petal width', 'class']
In [10]:
df.columns = col_name
In [11]:
df.head()
Out[11]:
In [12]:
iris = sns.load_dataset('iris')
iris.head()
Out[12]:
In [13]:
df.describe()
Out[13]:
In [14]:
iris.describe()
Out[14]:
In [15]:
print(iris.info())
In [16]:
print(iris.groupby('species').size())
In [17]:
sns.pairplot(iris, hue='species', size=3, aspect=1.0)
Out[17]:
In [18]:
iris.hist(edgecolor='black', linewidth=1.2, figsize=(12, 8))
plt.show()
In [19]:
iris.hist?
In [20]:
plt.figure(figsize=(12, 8))
plt.subplot(2, 2, 1)
sns.violinplot(x='species', y='sepal_length', data=iris)
plt.subplot(2, 2, 2)
sns.violinplot(x='species', y='sepal_width', data=iris)
plt.subplot(2, 2, 3)
sns.violinplot(x='species', y='petal_length', data=iris)
plt.subplot(2, 2, 4)
sns.violinplot(x='species', y='petal_width', data=iris)
Out[20]:
In [21]:
iris.boxplot(by='species', figsize=(12, 8))
plt.show()
In [23]:
pd.scatter_matrix(iris, figsize=(12, 8))
plt.show()
In [24]:
iris.head()
Out[24]:
In [25]:
x = 10 * np.random.rand(100)
In [26]:
y = 3 * x + np.random.rand(100)
In [27]:
plt.scatter(x, y)
Out[27]:
In [29]:
from sklearn.linear_model import LinearRegression
In [30]:
model = LinearRegression(fit_intercept=True)
In [31]:
model
Out[31]:
In [32]:
X = x.reshape(-1, 1)
X.shape
Out[32]:
In [33]:
model.fit(X, y)
Out[33]:
In [34]:
model.coef_
Out[34]:
In [35]:
model.intercept_
Out[35]:
In [36]:
x_fit = np.linspace(-1, 11)
In [37]:
X_fit = x_fit.reshape(-1, 1)
In [38]:
y_fit = model.predict(X_fit)
In [39]:
plt.scatter(x, y)
plt.plot(x_fit, y_fit)
Out[39]:
In [ ]: