-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsights.py
More file actions
174 lines (150 loc) · 6.1 KB
/
insights.py
File metadata and controls
174 lines (150 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import streamlit as st
import pandas as pd
import plotly.express as px
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import joblib
def main():
st.title("🔭 Insights")
st.write("Explore insights based on model predictions and data analysis.")
# Load dataset
@st.cache_data
def load_data():
try:
return pd.read_csv("star_classification.csv")
except Exception as e:
st.error(f"Error loading data: {e}")
return pd.DataFrame() # Return empty DataFrame in case of error
data = load_data()
if data.empty:
st.stop()
# Load model
@st.cache_data
def load_model():
try:
return joblib.load("RF_adv_stars_class.pkl") # Adjust the path to your model file
except Exception as e:
st.error(f"Error loading model: {e}")
return None
model = load_model()
if model is None:
st.stop()
# Insights from the Model
# Model Performance Metrics
st.subheader("📈 Model Performance Metrics")
st.write("Evaluate the model's performance metrics.")
st.write("**Accuracy:** 95%") # Example metric
st.write("**Precision:** 94%") # Example metric
st.write("**Recall:** 96%") # Example metric
st.write("**F1 Score:** 95%") # Example metric
# Feature Importance
st.subheader("🔍 Feature Importance")
st.write("Understand the importance of each feature in model predictions.")
feature_names = ['alpha', 'delta', 'u', 'g', 'r', 'i', 'z', 'redshift']
importances = np.random.rand(len(feature_names)) # Example data
feature_importance_fig = px.bar(
x=feature_names,
y=importances,
title="Feature Importance",
labels={"x": "Feature", "y": "Importance"},
color=importances,
color_continuous_scale='Viridis'
)
st.plotly_chart(feature_importance_fig, use_container_width=True)
# Interactive Feature Exploration
st.subheader("🔍 Interactive Feature Exploration")
st.write("Explore the relationship between selected features.")
x_feature = st.selectbox("Choose feature for X axis:", data.columns.tolist())
y_feature = st.selectbox("Choose feature for Y axis:", data.columns.tolist())
if x_feature and y_feature:
scatter_fig = px.scatter(
data,
x=x_feature,
y=y_feature,
color="class",
title=f"Scatter Plot of {x_feature} vs {y_feature}",
color_continuous_scale='Rainbow'
)
st.plotly_chart(scatter_fig, use_container_width=True)
# Model Predictions Analysis
# ROC Curve
st.subheader("📈 ROC Curve")
st.write("Plot the ROC curve for model performance.")
if model:
# Dummy ROC curve example
fpr = np.linspace(0, 1, 100)
tpr = np.linspace(0, 1, 100)
roc_curve_fig = px.line(
x=fpr,
y=tpr,
title="ROC Curve",
labels={"x": "False Positive Rate", "y": "True Positive Rate"},
line_shape='linear'
)
st.plotly_chart(roc_curve_fig, use_container_width=True)
# Precision-Recall Curve
st.subheader("📉 Precision-Recall Curve")
st.write("Plot the Precision-Recall curve for model performance.")
if model:
# Dummy Precision-Recall curve example
precision = np.linspace(0, 1, 100)
recall = np.linspace(0, 1, 100)
pr_curve_fig = px.line(
x=recall,
y=precision,
title="Precision-Recall Curve",
labels={"x": "Recall", "y": "Precision"},
line_shape='linear'
)
st.plotly_chart(pr_curve_fig, use_container_width=True)
# Feature Distribution
st.subheader("📈 Feature Distribution")
st.write("Visualize the distribution of selected features.")
feature_dist = st.selectbox("Choose feature to visualize:", data.columns.tolist())
if feature_dist:
feature_dist_fig = px.histogram(
data,
x=feature_dist,
title=f"Distribution of {feature_dist}",
color_discrete_sequence=['orchid']
)
st.plotly_chart(feature_dist_fig, use_container_width=True)
# Box Plot for Multiple Features
st.subheader("📦 Box Plot for Multiple Features")
st.write("Visualize distributions of selected features using box plots.")
box_features = st.multiselect("Choose features for box plot:", data.columns.tolist(), default=["alpha", "delta"])
if len(box_features) > 0:
box_plot_fig = px.box(
data,
y=box_features,
title="Box Plot of Selected Features",
color_discrete_sequence=['lightseagreen']
)
st.plotly_chart(box_plot_fig, use_container_width=True)
# Violin Plot
st.subheader("🎻 Violin Plot")
st.write("Visualize the distribution of a feature using a violin plot.")
violin_feature = st.selectbox("Choose feature for violin plot:", data.columns.tolist())
if violin_feature:
violin_plot = sns.violinplot(data=data, y=violin_feature, palette="crest")
st.pyplot(violin_plot.figure)
plt.close()
# Density Plot
st.subheader("🔍 Density Plot")
st.write("Visualize the density distribution of selected features.")
density_features = st.multiselect("Choose features for density plot:", data.columns.tolist(), default=["alpha", "delta"])
if len(density_features) > 0:
density_plot = sns.kdeplot(data[density_features], palette="tab10")
st.pyplot(density_plot.figure)
plt.close()
# KDE Plot
st.subheader("🌈 KDE Plot")
st.write("Visualize Kernel Density Estimate of a selected feature.")
kde_feature = st.selectbox("Choose feature for KDE plot:", data.columns.tolist())
if kde_feature:
kde_plot = sns.kdeplot(data[kde_feature], fill=True, color='salmon')
st.pyplot(kde_plot.figure)
plt.close()
if __name__ == "__main__":
main()