from sklearn import datasets

%pylab inline

"""
Explanation: Sklearn
sklearn.datasets
документация: http://scikit-learn.org/stable/datasets/
End of explanation
"""


circles = datasets.make_circles()

print "features: {}".format(circles[0][:10])
print "target: {}".format(circles[1][:10])

from matplotlib.colors import ListedColormap

colors = ListedColormap(['red', 'yellow'])

pyplot.figure(figsize(8, 8))
pyplot.scatter(map(lambda x: x[0], circles[0]), map(lambda x: x[1], circles[0]), c = circles[1], cmap = colors)

def plot_2d_dataset(data, colors):
    pyplot.figure(figsize(8, 8))
    pyplot.scatter(map(lambda x: x[0], data[0]), map(lambda x: x[1], data[0]), c = data[1], cmap = colors)

noisy_circles = datasets.make_circles(noise = 0.15)

plot_2d_dataset(noisy_circles, colors)

"""
Explanation: Генерация выборок
Способы генерации данных: 
* make_classification
* make_regression
* make_circles
* make_checkerboard
* etc
datasets.make_circles
End of explanation
"""


simple_classification_problem = datasets.make_classification(n_features = 2, n_informative = 1, 
                                                            n_redundant = 1, n_clusters_per_class = 1,
                                                            random_state = 1 )

plot_2d_dataset(simple_classification_problem, colors)

classification_problem = datasets.make_classification(n_features = 2, n_informative = 2, n_classes = 4, 
                                                      n_redundant = 0, n_clusters_per_class = 1, random_state = 1)

colors = ListedColormap(['red', 'blue', 'green', 'yellow'])

plot_2d_dataset(classification_problem, colors)

"""
Explanation: datasets.make_classification
End of explanation
"""


iris = datasets.load_iris()

iris

iris.keys()

print iris.DESCR

print "feature names: {}".format(iris.feature_names)
print "target names: {names}".format(names = iris.target_names)

iris.data[:10]

iris.target

"""
Explanation: "Игрушечные" наборы данных
Наборы данных: 
* load_iris 
* load_boston
* load_diabetes
* load_digits
* load_linnerud
* etc
datasets.load_iris
End of explanation
"""


from pandas import DataFrame

iris_frame = DataFrame(iris.data)
iris_frame.columns = iris.feature_names
iris_frame['target'] = iris.target

iris_frame.head()

iris_frame.target = iris_frame.target.apply(lambda x : iris.target_names[x])

iris_frame.head()

iris_frame[iris_frame.target == 'setosa'].hist('sepal length (cm)')

pyplot.figure(figsize(20, 24))

plot_number = 0
for feature_name in iris['feature_names']:
    for target_name in iris['target_names']:
        plot_number += 1
        pyplot.subplot(4, 3, plot_number)
        pyplot.hist(iris_frame[iris_frame.target == target_name][feature_name])
        pyplot.title(target_name)
        pyplot.xlabel('cm')
        pyplot.ylabel(feature_name[:-4])

"""
Explanation: Визуализация выбокри
End of explanation
"""


import seaborn as sns

sns.pairplot(iris_frame, hue = 'target')

?sns.set()

sns.set(font_scale = 1.3)
data = sns.load_dataset("iris")
sns.pairplot(data, hue = "species")

"""
Explanation: Бонус: библиотека seaborn
End of explanation
"""


