import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(color_codes=True)
%matplotlib inline

df = pd.read_csv('iris.data')

df.head()

pd.read_csv?

df = pd.read_csv('iris.data', header=-1)
df.head()

col_name = ['sepal length', 'sepal width', 'petal length', 'petal width', 'class']

df.columns = col_name

df.head()

"""
Explanation: Iris Project
Data Exploration and Analysis
End of explanation
"""


iris = sns.load_dataset('iris')
iris.head()

df.describe()

iris.describe()

print(iris.info())

print(iris.groupby('species').size())

"""
Explanation: Iris Data from Seaborn
End of explanation
"""


sns.pairplot(iris, hue='species', size=3, aspect=1.0)

iris.hist(edgecolor='black', linewidth=1.2, figsize=(12, 8))
plt.show()

iris.hist?

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)

iris.boxplot(by='species', figsize=(12, 8))
plt.show()

pd.scatter_matrix(iris, figsize=(12, 8))
plt.show()

iris.head()

"""
Explanation: Visualisation
End of explanation
"""


x = 10 * np.random.rand(100)

y = 3 * x + np.random.rand(100)

plt.scatter(x, y)

from sklearn.linear_model import LinearRegression

model = LinearRegression(fit_intercept=True)

model

X = x.reshape(-1, 1)
X.shape

model.fit(X, y)

model.coef_

model.intercept_

x_fit = np.linspace(-1, 11)

X_fit = x_fit.reshape(-1, 1)

y_fit = model.predict(X_fit)

plt.scatter(x, y)
plt.plot(x_fit, y_fit)

"""
Explanation: Key Points

Data in the form of a table
Features in the form of a matrix
Label or target array

Scikit-Learn API
General Principles

Consistency. All objects (basic or composite) share a consistent interface composed of a limited set of methods. This interface is documented in a consistent manner for all objects.
Inspection. Constructor parameters and parameter values determined by learning algorithms are stored and exposed as public attributes.
Non-proliferation of classes. Learning algorithms are the only objects to be represented using custom classes. Datasets are represented as NumPy arrays or SciPy sparse matrices. Hyper-parameter names and values are represented as standard Python strings or numbers whenever possible. This keeps scikitlearn easy to use and easy to combine with other libraries.
Composition. Many machine learning tasks are expressible as sequences or combinations of transformations to data. Some learning algorithms are also naturally viewed as meta-algorithms parametrized on other algorithms. Whenever feasible, such algorithms are implemented and composed from existing building blocks.
Sensible defaults. Whenever an operation requires a user-defined parameter, an appropriate default value is defined by the library. The default value should cause the operation to be performed in a sensible way (giving a baseline solution for the task at hand).

Basic Steps of Using Scikit-Learn API

Choose a class of model
Choose model hyperparameters
Arrange data into feature matrix and target array
Fit model to data
Apply trained model to new data

Supervised Learning: Simple Linear Regression
End of explanation
"""


