<jupyter_start><jupyter_text>Data Loading Get some data to play with<jupyter_code>from sklearn.datasets import fetch_openml
blood = fetch_openml('blood-transfusion-service-center')
print(blood.DESCR)
blood.data.shape
blood.data
import pandas as pd
X = pd.DataFrame(blood.data, columns=['recency', 'frequency', 'total_amount', 'since_first'])
blood.target.shape
blood.target
y = pd.Series(blood.target)
y.value_counts()
import matplotlib.pyplot as plt
pd.plotting.scatter_matrix(X, c=y=='2', cmap='Paired', figsize=(10, 10));<jupyter_output><empty_output><jupyter_text>**Data is always a numpy array (or sparse matrix) of shape (n_samples, n_features)** Split the data to get going<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)
#can set random state as seed as argument in train_test split
X.shape
X_train.shape
X_test.shape<jupyter_output><empty_output><jupyter_text>Exercises Exercise 1Load the iris dataset from the ``sklearn.datasets`` module using the ``load_iris`` function.The function returns a dictionary-like object that has the same attributes as ``blood``.What is the number of classes, features and data points in this dataset?Use a scatterplot to visualize the dataset.You can look at ``DESCR`` attribute to learn more about the dataset.``print(iris.DESCR)``Split the data into training and test set. Exercise 2Usually data doesn't come in that nice a format. You can find the csv file that contains the iris dataset at the following path:```pythonimport sklearn.datasetsimport osiris_path = os.path.join(sklearn.datasets.__path__[0], 'data', 'iris.csv')```Load the data from there using pandas ``pd.read_csv`` method and bring it into the same format as before with the data in a variable X and the labels in a variable y. The first few lines of ``iris.csv`` file looks like:```150,4,setosa,versicolor,virginica5.1,3.5,1.4,0.2,04.9,3.0,1.4,0.2,04.7,3.2,1.3,0.2,04.6,3.1,1.5,0.2,0```<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

iris = load_iris()
X, y = iris.data, iris.target

print("Dataset size: %d  number of features: %d  number of classes: %d"
      % (X.shape[0], X.shape[1], len(np.unique(y))))

X_train, X_test, y_train, y_test = train_test_split(X, y)

plt.scatter(X_train[:, 0], X_train[:, 1], c=y_train)
plt.xlabel(iris.feature_names[0])
plt.ylabel(iris.feature_names[1])

plt.figure()
plt.scatter(X_train[:, 2], X_train[:, 3], c=y_train)
plt.xlabel(iris.feature_names[2])
plt.ylabel(iris.feature_names[3])

import sklearn.datasets
import os
import pandas as pd
iris_path = os.path.join(sklearn.datasets.__path__[0], 'data', 'iris.csv')
iris_df =  pd.read_csv(iris_path, header=None)
display(iris_df.head())

iris_df = pd.read_csv(iris_path, skiprows=1, header=None)
display(iris_df.head())

features = iris_df.iloc[:, :4]
target = iris_df.iloc[:, 4]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup