<jupyter_start><jupyter_text>Get Data<jupyter_code>data = pd.read_csv('fremont.csv', index_col='Date', parse_dates=True)
data.head()
data.plot()
#Weekly
data.resample('W').sum().plot()
plt.style.use('seaborn')

data.columns = ['West', 'East']

data.resample('W').sum().plot()
#Rolling daily sum
data['Total'] = data['West'] + data['East']

ax = data.resample('D').sum().rolling(365).sum().plot()
ax.set_ylim(0, None);
#Avg crossings each time of day
data.groupby(data.index.time).mean().plot()
pivoted = data.pivot_table('Total', index=data.index.time, columns=data.index.date)
pivoted.iloc[:5,:5]
pivoted.plot(legend=False, alpha=0.01)<jupyter_output><empty_output><jupyter_text>Principal Component Analysis<jupyter_code>#24 hrs, days
X = pivoted.fillna(0).T.values
X2 = PCA(2, svd_solver='full').fit_transform(X)
pivoted.shape
X2.shape
plt.scatter(X2[:, 0], X2[:,1])
gmm = GaussianMixture(2)
gmm.fit(X)
labels = gmm.predict(X)

plt.scatter(X2[:, 0], X2[:, 1], c = labels, cmap='rainbow')
plt.colorbar()

fig, ax = plt.subplots(1,2, figsize=(14, 6))

pivoted.T[labels == 0].T.plot(legend=False, alpha=0.1, ax=ax[0])
pivoted.T[labels == 1].T.plot(legend=False, alpha=0.1, ax=ax[1])

ax[0].set_title('Purple Cluster')
ax[1].set_title('Red Cluster')<jupyter_output><empty_output><jupyter_text>Comparing with  Day of Week<jupyter_code>#Cluster by day of week
dayofweek = pd.DatetimeIndex(pivoted.columns).dayofweek
pd.DatetimeIndex(pivoted.columns).dayofweek

plt.scatter(X2[:, 0], X2[:, 1], c = dayofweek, cmap='rainbow')
plt.colorbar()<jupyter_output><empty_output><jupyter_text>Analyzing Outliersthe following points are weekdays with holiday-like pattern<jupyter_code>dates = pd.DatetimeIndex(pivoted.columns)
dates[(labels == 0) & (dayofweek < 5)]
#Dates people dont commute<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18826135105204872, 'fraction_numerical': 0.024916943521594685, 'mean_word_length': 7.523584905660377, 'pattern_counts': {'":': 0, '<': 18, '<?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': '238528', 'license': 'MIT', 'n_tokens_mistral': 765, 'n_tokens_neox': 730, 'n_words': 118, 'path': 'JupyterWorkfow.ipynb', 'repo_name': '412Kev/Jupyter-Workflow-Example', 'size': '1806'}