Icon

kn_​example_​python_​graphic_​interactive_​view_​node

Sharing Component with Interactive Visualisation using Python view node with Plotly package (adapted)

This workflow is built to showcase the Component that uses Python View node to generate interactive view. The component trains a lasso regression to predict the housing prices. Further we use the Python View node to visualise the effect of features on price of the house using intercative scatter plot

adapted from:
https://hub.knime.com/-/spaces/-/latest/~MP4Bt25b1GCPQ_H9/
by Mahantesh Pattadkal



Read Data Visualise the Lasso Regression Workflow Inside of Component Lasso Regression for Housing Prices(Displayed here for KNIME Hub Inspection) adapted from:https://hub.knime.com/-/spaces/-/latest/~MP4Bt25b1GCPQ_H9/by Mahantesh Pattadkal Image export Image export import knime.scripting.io as knioimport plotly.express as pximport pandas as pdimport plotly.io as piofrom io import BytesIOdf = knio.input_tables[0].to_pandas()# Compute the center of all pointscenter = {"lat": (df["Latitude"].max() + df["Latitude"].min()) / 2,"lon": (df["Longitude"].max() + df["Longitude"].min()) / 2,}fig = px.scatter_mapbox( df, lat="Latitude", lon="Longitude", mapbox_style="carto-positron", center=center, zoom=5, size="Population", color="MedHouseVal", custom_data=[df.index])knio.output_view = knio.view(fig)fig.update_layout( width=1920, # Adjust the width height=1080, # Adjust the height margin=dict(l=0, r=0, t=0, b=0))knio.output_images[0] = pio.to_image(fig, format="svg", scale=5)# .decode("utf-8")# Save the figure as an SVG file# pio.write_image(fig, "scatter_mapbox.svg", format="svg")# Save the figure as a PNG file# pio.write_image(fig, "scatter_mapbox.png", format="png") Real house valueagainst predicted valuepartition intrain and validationdatasetsData points ona mapFit a sklearnLasso modelwith the selectedregularizationstrengthPredict onvalidationdataCaliforniaHosuing DatasetregularizationstrengthNode 23Node 30py3_knime1.920 x 1.080PNG filefrom_knime_housing_prices.pngfrom_knime_housing_prices.svgfrom_knime_housing_prices_2.png1.920 x 1.080PNG file Scatter Plot (Labs) Partitioning Python View Python Script Python Script Lasso Regressionfor Housing Prices Table Reader Double Widget RefreshButton Widget Table View (Labs) Row Sampling Conda EnvironmentPropagation Image To Table Renderer to Image Table To Image Image Writer (Port) Image Writer (Port) Image To Table Table To Image Image Writer (Port) Renderer to Image Read Data Visualise the Lasso Regression Workflow Inside of Component Lasso Regression for Housing Prices(Displayed here for KNIME Hub Inspection) adapted from:https://hub.knime.com/-/spaces/-/latest/~MP4Bt25b1GCPQ_H9/by Mahantesh Pattadkal Image export Image export import knime.scripting.io as knioimport plotly.express as pximport pandas as pdimport plotly.io as piofrom io import BytesIOdf = knio.input_tables[0].to_pandas()# Compute the center of all pointscenter = {"lat": (df["Latitude"].max() + df["Latitude"].min()) / 2,"lon": (df["Longitude"].max() + df["Longitude"].min()) / 2,}fig = px.scatter_mapbox( df, lat="Latitude", lon="Longitude", mapbox_style="carto-positron", center=center, zoom=5, size="Population", color="MedHouseVal", custom_data=[df.index])knio.output_view = knio.view(fig)fig.update_layout( width=1920, # Adjust the width height=1080, # Adjust the height margin=dict(l=0, r=0, t=0, b=0))knio.output_images[0] = pio.to_image(fig, format="svg", scale=5)# .decode("utf-8")# Save the figure as an SVG file# pio.write_image(fig, "scatter_mapbox.svg", format="svg")# Save the figure as a PNG file# pio.write_image(fig, "scatter_mapbox.png", format="png") Real house valueagainst predicted valuepartition intrain and validationdatasetsData points ona mapFit a sklearnLasso modelwith the selectedregularizationstrengthPredict onvalidationdataCaliforniaHosuing DatasetregularizationstrengthNode 23Node 30py3_knime1.920 x 1.080PNG filefrom_knime_housing_prices.pngfrom_knime_housing_prices.svgfrom_knime_housing_prices_2.png1.920 x 1.080PNG file Scatter Plot (Labs) Partitioning Python View Python Script Python Script Lasso Regressionfor Housing Prices Table Reader Double Widget RefreshButton Widget Table View (Labs) Row Sampling Conda EnvironmentPropagation Image To Table Renderer to Image Table To Image Image Writer (Port) Image Writer (Port) Image To Table Table To Image Image Writer (Port) Renderer to Image

Nodes

Extensions

Links