<jupyter_start><jupyter_text>Key elements:* a dataset of student grades and other info * histograms (w/ & w/o multiple columns) * scatter plots (2D & 3D)* the iris dataset from Scikit-learn * parallel coordinate plot * Andrews plot* random data generation * correlation coefficients * 2D plot of DataFrame* plot style setting<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>students' grade dataset<jupyter_code># load data
flc = '/Users/pinqingkan/Desktop/Codes/Course_edX_PythonDataScience/Cached_Datasets/'
fname = flc + 'students.data'
X = pd.read_csv(fname, index_col = 0)
X.columns
# plot
plt.style.use('seaborn-pastel')
A = X.G3
plt.hist(A)
plt.show()
A.plot.hist(alpha = 0.5)
plt.show()
# plot several columns
B = X[['G1', 'G2', 'G3']]
B = B.as_matrix()
plt.hist(B, histtype = 'bar', label = ['G1', 'G2', 'G3'])
plt.legend()
plt.show()
# scatter plot
plt.scatter(X.G1, X.G3)
plt.xlabel('G1')
plt.ylabel('G3')
plt.show()
# 3D scatter plot
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.set_xlabel('First Grade')
ax.set_ylabel('Final Grade')
ax.set_zlabel('Daily Alcohol')
ax.scatter(X.G1, X.G3, X.Dalc)

plt.show()<jupyter_output><empty_output><jupyter_text>SKLearn's iris dataset<jupyter_code># plot using SKLean's Iris Dataset
from sklearn.datasets import load_iris
data = load_iris()
Y = pd.DataFrame(data.data, columns = data.feature_names)
# expand the dataframe to include target_names
Y['target_names'] = [data.target_names[i] for i in data.target]
Y.columns
# parallel coordinate plots
from pandas.tools.plotting import parallel_coordinates

plt.figure()
parallel_coordinates(Y, 'target_names')
plt.show()
# Andrews chart
# f(t) = y1/sqrt(2) + y2 sin(t) + y3 cos(t) + y4 sin(2t) + y5 cos(2t) + ...
from pandas.tools.plotting import andrews_curves

plt.figure()
andrews_curves(Y, 'target_names')
plt.show()<jupyter_output><empty_output><jupyter_text>random data generation & correlation<jupyter_code># generate random data and calculate correlation
import numpy as np

Z = pd.DataFrame(np.random.randn(1000, 5), columns = ['a', 'b', 'c', 'd', 'e'])
Zcor = Z.corr()
# 2D plot
plt.imshow(Zcor, cmap = plt.cm.Blues)
plt.colorbar()
tick_marks = [i for i in range(len(Z.columns))]
plt.xticks(tick_marks, Z.columns)
plt.yticks(tick_marks, Z.columns)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14516129032258066, 'fraction_numerical': 0.016542597187758478, 'mean_word_length': 5.872159090909091, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '564115', 'license': 'MIT', 'n_tokens_mistral': 978, 'n_tokens_neox': 925, 'n_words': 221, 'path': 'lecture3_FeatureVisualization.ipynb', 'repo_name': 'rongqingpin/Python_Data_Science_edX_DAT210x', 'size': '2418'}