Falln87 commited on
Commit
b370abb
·
verified ·
1 Parent(s): 0cac12c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from pandas_profiling import ProfileReport
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.linear_model import LinearRegression
6
+ from sklearn.tree import DecisionTreeRegressor
7
+ from sklearn.ensemble import RandomForestRegressor
8
+ import plotly.express as px
9
+
10
+ # Data Ingestion
11
+ uploaded_file = st.file_uploader("Upload your dataset:", type=["csv",_"xlsx",_"json"])
12
+ if uploaded_file:
13
+ df = pd.read_csv(uploaded_file)
14
+ st.write("Data Preview:")
15
+ st.write(df.head())
16
+
17
+ # Data Preparation
18
+ st.write("Data Preparation:")
19
+ profile = ProfileReport(df, title="Data Profiling Report")
20
+ st.write(profile)
21
+
22
+ # Data Cleaning
23
+ st.write("Data Cleaning:")
24
+ handle_missing_values = st.selectbox("Handle missing values:", ["Mean",_"Median",_"Imputation"])
25
+ handle_outliers = st.selectbox("Handle outliers:", ["Standardization",_"_Winsorization"])
26
+
27
+ # Model Training
28
+ st.write("Model Training:")
29
+ model_type = st.selectbox("Choose a model:", ["Linear_Regression",_"Decision_Trees",_"Random_Forest"])
30
+ hyperparams = {}
31
+ if model_type == "Linear Regression":
32
+ hyperparams["alpha"] = st.slider("Regularization strength:", 0.1, 10.0)
33
+ elif model_type == "Decision Trees":
34
+ hyperparams["max_depth"] = st.slider("Maximum depth:", 1, 10)
35
+ elif model_type == "Random Forest":
36
+ hyperparams["n_estimators"] = st.slider("Number of estimators:", 10, 100)
37
+
38
+ X_train, X_test, y_train, y_test = train_test_split(df.drop("target", axis=1), df["target"], test_size=0.2, random_state=42)
39
+
40
+ if model_type == "Linear Regression":
41
+ model = LinearRegression(**hyperparams)
42
+ elif model_type == "Decision Trees":
43
+ model = DecisionTreeRegressor(**hyperparams)
44
+ elif model_type == "Random Forest":
45
+ model = RandomForestRegressor(**hyperparams)
46
+
47
+ model.fit(X_train, y_train)
48
+ y_pred = model.predict(X_test)
49
+
50
+ # Model Evaluation
51
+ st.write("Model Evaluation:")
52
+ st.write("Accuracy:", model.score(X_test, y_test))
53
+ st.write("Confusion Matrix:")
54
+ conf_mat = pd.crosstab(y_test, y_pred, rownames=["Actual"], colnames=["Predicted"])
55
+ st.plotly(px.imshow(conf_mat, color_continuous_scale="blues"), use_container_width=True)
56
+
57
+ # Model Deployment
58
+ st.write("Model Deployment:")
59
+ download_model = st.download_button("Download trained model", data=model, file_name="model.py")
60
+ deploy_to_cloud = st.button("Deploy to cloud platform")