mirror of
https://github.com/Visualize-ML/Book4_Power-of-Matrix.git
synced 2026-02-03 02:24:03 +08:00
Add files via upload
This commit is contained in:
@@ -21,18 +21,24 @@ with st.sidebar:
|
||||
y_feature = st.radio('Vertical axis',
|
||||
features)
|
||||
|
||||
# Heatmap
|
||||
#%% original data
|
||||
|
||||
with st.expander('Original data'):
|
||||
st.write(df)
|
||||
|
||||
|
||||
#%% Heatmap
|
||||
with st.expander('Heatmap'):
|
||||
fig_1 = px.imshow(df.iloc[:,0:4],
|
||||
color_continuous_scale='RdYlBu_r')
|
||||
st.plotly_chart(fig_1)
|
||||
|
||||
# 2D scatter plot
|
||||
#%% 2D scatter plot
|
||||
with st.expander('2D scatter plot'):
|
||||
fig_2 = px.scatter(df, x=x_feature, y=y_feature, color="species")
|
||||
st.plotly_chart(fig_2)
|
||||
|
||||
# 3D scatter plot
|
||||
#%% 3D scatter plot
|
||||
with st.expander('3D scatter plot'):
|
||||
fig_3 = px.scatter_3d(df,
|
||||
x='sepal_length',
|
||||
|
||||
@@ -41,7 +41,7 @@ b = np.round(b,1)
|
||||
|
||||
show_number = False
|
||||
with st.sidebar:
|
||||
show_number = st.checkbox('Show values:')
|
||||
show_number = st.checkbox('Display values')
|
||||
|
||||
tensor_a_b = a@b.T
|
||||
|
||||
|
||||
@@ -37,9 +37,8 @@ fig_1.update_layout(
|
||||
margin=dict(
|
||||
l=50,
|
||||
r=50,
|
||||
b=100,
|
||||
t=100,
|
||||
pad = 4))
|
||||
b=50,
|
||||
t=50))
|
||||
|
||||
fig_2 = go.Figure(
|
||||
go.Surface(
|
||||
|
||||
@@ -116,11 +116,11 @@ fig.add_trace(go.Scatter(x=A_times_square_array[0,:],
|
||||
|
||||
fig.add_trace(go.Scatter(x=Txvyv[0], y=Txvyv[1],
|
||||
mode="lines", line_width=lw,
|
||||
line_color = 'blue'), 1, 2)
|
||||
line_color = 'red'), 1, 2)
|
||||
|
||||
fig.add_trace(go.Scatter(x=Txhyh[0], y=Txhyh[1],
|
||||
mode="lines", line_width=lw,
|
||||
line_color = 'red'), 1, 2)
|
||||
line_color = 'blue'), 1, 2)
|
||||
fig.update_xaxes(range=[-4, 4])
|
||||
fig.update_yaxes(range=[-4, 4])
|
||||
fig.update_layout(width=800, height=500, showlegend=False, template="none",
|
||||
|
||||
@@ -58,7 +58,7 @@ with st.sidebar:
|
||||
\sin(\theta) & \cos(\theta)
|
||||
\end{bmatrix}''')
|
||||
|
||||
theta = st.slider('Degree',-180, 180, step = 5, value = 0)
|
||||
theta = st.slider('Theta degree: ',-180, 180, step = 5, value = 0)
|
||||
|
||||
theta = theta/180*np.pi
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ with st.sidebar:
|
||||
a = st.slider('a',-2.0, 2.0, step = 0.1, value = 1.0)
|
||||
b = st.slider('b',-2.0, 2.0, step = 0.1, value = 0.0)
|
||||
c = st.slider('c',-2.0, 2.0, step = 0.1, value = 0.0)
|
||||
d = st.slider('c',-2.0, 2.0, step = 0.1, value = 1.0)
|
||||
d = st.slider('d',-2.0, 2.0, step = 0.1, value = 1.0)
|
||||
|
||||
theta = np.pi/6
|
||||
A = np.array([[a, b],
|
||||
|
||||
@@ -67,6 +67,9 @@ st.latex(r'G = ' +
|
||||
bmatrix(np.round(D,2)) + '@' +
|
||||
bmatrix(np.round(V.T,2)))
|
||||
|
||||
st.write('Mapped data:')
|
||||
st.latex('Z = XV')
|
||||
|
||||
#%%
|
||||
|
||||
Z = X@V
|
||||
@@ -79,25 +82,32 @@ df['species'] = df['species'].map(mapping_rule)
|
||||
|
||||
#%%
|
||||
features = df.columns.to_list()[:-1]
|
||||
with st.sidebar:
|
||||
st.write('2D scatter plot')
|
||||
x_feature = st.radio('Horizontal axis',
|
||||
features)
|
||||
y_feature = st.radio('Vertical axis',
|
||||
features)
|
||||
|
||||
# Heatmap
|
||||
#%% Table of mapped data
|
||||
|
||||
with st.expander('Mapped data'):
|
||||
st.write(df)
|
||||
|
||||
#%% Heatmap
|
||||
with st.expander('Heatmap'):
|
||||
fig_1 = px.imshow(df.iloc[:,0:4],
|
||||
color_continuous_scale='RdYlBu_r')
|
||||
st.plotly_chart(fig_1)
|
||||
|
||||
# 2D scatter plot
|
||||
#%% 2D scatter plot
|
||||
|
||||
with st.sidebar:
|
||||
st.write('2D scatter plot')
|
||||
x_feature = st.radio('Horizontal axis',
|
||||
features)
|
||||
y_feature = st.radio('Vertical axis',
|
||||
features)
|
||||
|
||||
with st.expander('2D scatter plot'):
|
||||
fig_2 = px.scatter(df, x=x_feature, y=y_feature, color="species")
|
||||
st.plotly_chart(fig_2)
|
||||
|
||||
# 3D scatter plot
|
||||
#%% 3D scatter plot
|
||||
with st.expander('3D scatter plot'):
|
||||
fig_3 = px.scatter_3d(df,
|
||||
x='PC1',
|
||||
@@ -106,7 +116,7 @@ with st.expander('3D scatter plot'):
|
||||
color='species')
|
||||
st.plotly_chart(fig_3)
|
||||
|
||||
# Pairwise scatter plot
|
||||
#%% Pairwise scatter plot
|
||||
with st.expander('Pairwise scatter plot'):
|
||||
fig_4 = px.scatter_matrix(df,
|
||||
dimensions=["PC1",
|
||||
|
||||
@@ -64,7 +64,7 @@ df = pd.DataFrame(X, columns=['z1','z2', 'color'])
|
||||
|
||||
#%% Scatter
|
||||
|
||||
st.latex(bmatrix(A))
|
||||
st.latex('A = ' + bmatrix(A))
|
||||
|
||||
fig = px.scatter(df,
|
||||
x="z1",
|
||||
|
||||
@@ -102,7 +102,8 @@ st.latex(bmatrix(Sigma) + '=' +
|
||||
fig_surface = go.Figure(go.Surface(
|
||||
x = x1,
|
||||
y = x2,
|
||||
z = PDF_zz))
|
||||
z = PDF_zz,
|
||||
colorscale= 'RdYlBu_r'))
|
||||
fig_surface.update_layout(
|
||||
autosize=False,
|
||||
width=500,
|
||||
@@ -115,7 +116,8 @@ fig_contour = go.Figure(
|
||||
go.Contour(
|
||||
z=PDF_zz,
|
||||
x=x1,
|
||||
y=x2
|
||||
y=x2,
|
||||
colorscale= 'RdYlBu_r'
|
||||
))
|
||||
|
||||
fig_contour.update_layout(
|
||||
|
||||
@@ -82,7 +82,9 @@ ff_x = f_x_fcn(xx1,xx2)
|
||||
fig_surface = go.Figure(go.Surface(
|
||||
x = x1_,
|
||||
y = x2_,
|
||||
z = ff_x))
|
||||
z = ff_x,
|
||||
colorscale= 'RdYlBu_r'))
|
||||
|
||||
fig_surface.update_layout(
|
||||
autosize=False,
|
||||
width=500,
|
||||
@@ -95,7 +97,8 @@ fig_contour = go.Figure(
|
||||
go.Contour(
|
||||
z=ff_x,
|
||||
x=x1_,
|
||||
y=x2_
|
||||
y=x2_,
|
||||
colorscale= 'RdYlBu_r'
|
||||
))
|
||||
|
||||
fig_contour.update_layout(
|
||||
|
||||
Reference in New Issue
Block a user