import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

"""
Explanation: Crash Course Review Exercises
 Import numpy, pandas, matplotlib, and sklearn. Also set visualizations to be shown inline in the notebook.
End of explanation
"""


np.random.seed(101)

"""
Explanation: Set Numpy's Random Seed to 101
End of explanation
"""


random_integers = np.random.randint(low = 1, 
                                    high = 101, 
                                    size = (100, 5))

"""
Explanation: Create a NumPy Matrix of 100 rows by 5 columns consisting of random integers from 1-100. (Keep in mind that the upper limit may be exclusive.
End of explanation
"""


fig = plt.figure(figsize = (12, 12))
plt.imshow(random_integers, aspect = 0.05)
plt.colorbar()
plt.title("2D visualisation")

"""
Explanation: Create a 2-D visualization using plt.imshow of the numpy matrix with a colorbar. Add a title to your plot. Bonus: Figure out how to change the aspect of the imshow() plot.
End of explanation
"""


df = pd.DataFrame(random_integers)
df.head()

"""
Explanation: Now use pd.DataFrame() to read in this numpy array as a dataframe. Simple pass in the numpy array into that function to get back a dataframe. Pandas will auto label the columns to 0-4
End of explanation
"""


df.plot(x = 0, 
        y = 1, 
        kind = 'scatter', figsize = (12, 8))

"""
Explanation: Now create a scatter plot using pandas of the 0 column vs the 1 column.
End of explanation
"""


from sklearn.preprocessing import MinMaxScaler

minmax = MinMaxScaler()

scaled_random_int = minmax.fit_transform(df)
type(scaled_random_int)

scaled_df = pd.DataFrame(scaled_random_int)
scaled_df.head()

"""
Explanation: Now scale the data to have a minimum of 0 and a maximum value of 1 using scikit-learn.
End of explanation
"""


from sklearn.model_selection import train_test_split

df.columns = ['f1','f2','f3','f4','label']
df.head()

X = df.iloc[:, df.columns != 'label']
Y = df['label']

X.shape

Y.shape

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, 
                                                    test_size = 0.3, 
                                                    random_state = 101)

X_train.shape

X_test.shape

Y_train.shape

Y_test.shape

"""
Explanation: Using your previously created DataFrame, use df.columns = [...] to rename the pandas columns to be ['f1','f2','f3','f4','label']. Then perform a train/test split with scikitlearn.
End of explanation
"""


