Spaces:
Sleeping
Sleeping
ci-cd-bot commited on
Commit ·
cec776e
1
Parent(s): 65d1dd8
Initial commit with LFS model
Browse files- .idea/.gitignore +3 -0
- .idea/AdClickPredictor.iml +8 -0
- .idea/inspectionProfiles/Project_Default.xml +13 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app/app.py +59 -0
- app/requirements.txt +4 -0
- metrics/classification_report.txt +8 -0
- metrics/confusion_matrix.png +0 -0
- metrics/metrics.json +1 -0
- src/model.pkl +3 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
.idea/AdClickPredictor.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="inheritedJdk" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
+
</component>
|
| 8 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<profile version="1.0">
|
| 3 |
+
<option name="myName" value="Project Default" />
|
| 4 |
+
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
| 5 |
+
<option name="ignoredIdentifiers">
|
| 6 |
+
<list>
|
| 7 |
+
<option value="streamlit" />
|
| 8 |
+
<option value="pandas" />
|
| 9 |
+
</list>
|
| 10 |
+
</option>
|
| 11 |
+
</inspection_tool>
|
| 12 |
+
</profile>
|
| 13 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
| 4 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/AdClickPredictor.iml" filepath="$PROJECT_DIR$/.idea/AdClickPredictor.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app/app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
ROOT = os.path.dirname(os.path.abspath(__file__))
|
| 8 |
+
if os.path.basename(ROOT) == "app":
|
| 9 |
+
ROOT = os.path.dirname(ROOT)
|
| 10 |
+
METRICS_DIR = os.path.join(ROOT, "metrics")
|
| 11 |
+
MODEL_PATH = os.path.join(ROOT, "src", "model.pkl")
|
| 12 |
+
DATA_PATH = os.path.join(ROOT, "data", "ad_click_dataset.csv")
|
| 13 |
+
|
| 14 |
+
model = joblib.load(MODEL_PATH)
|
| 15 |
+
with open(os.path.join(METRICS_DIR, 'metrics.json')) as f:
|
| 16 |
+
metrics = json.load(f)
|
| 17 |
+
|
| 18 |
+
df = pd.read_csv(DATA_PATH)
|
| 19 |
+
cat_options = {col: df[col].dropna().unique().tolist() for col in df.columns if col not in ['id', 'full_name', 'click', 'age']}
|
| 20 |
+
|
| 21 |
+
st.title("Ad Click Predictor")
|
| 22 |
+
st.markdown(
|
| 23 |
+
"Wprowadź dane użytkownika i sprawdź, czy kliknie w reklamę!<br>"
|
| 24 |
+
"<sup>Model został wybrany automatycznie na podstawie walidacji krzyżowej spośród Random Forest, Logistic Regression oraz Gradient Boosting (Pipeline).</sup>",
|
| 25 |
+
unsafe_allow_html=True,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
age = st.slider("Wiek użytkownika", 18, 64, 30)
|
| 29 |
+
gender = st.selectbox("Płeć", cat_options['gender'])
|
| 30 |
+
device_type = st.selectbox("Typ urządzenia", cat_options['device_type'])
|
| 31 |
+
ad_position = st.selectbox("Pozycja reklamy", cat_options['ad_position'])
|
| 32 |
+
browsing_history = st.selectbox("Poprzednia aktywność", cat_options['browsing_history'])
|
| 33 |
+
time_of_day = st.selectbox("Pora dnia", cat_options['time_of_day'])
|
| 34 |
+
|
| 35 |
+
user_input = pd.DataFrame([{
|
| 36 |
+
"age": age,
|
| 37 |
+
"gender": gender,
|
| 38 |
+
"device_type": device_type,
|
| 39 |
+
"ad_position": ad_position,
|
| 40 |
+
"browsing_history": browsing_history,
|
| 41 |
+
"time_of_day": time_of_day
|
| 42 |
+
}])
|
| 43 |
+
|
| 44 |
+
if st.button("Sprawdź czy użytkownik kliknie w reklamę"):
|
| 45 |
+
proba = model.predict_proba(user_input)[0][1]
|
| 46 |
+
st.success("Kliknie!" if proba > 0.5 else "Nie kliknie.")
|
| 47 |
+
st.markdown(f"**Prawdopodobieństwo kliknięcia:** `{proba:.2%}`")
|
| 48 |
+
|
| 49 |
+
st.markdown("---")
|
| 50 |
+
st.markdown("#### Wybrany model (na podstawie walidacji krzyżowej):")
|
| 51 |
+
st.write(f"- Model: `{metrics['best_model']}`")
|
| 52 |
+
st.write(f"- Średni F1-score (cross-val): `{metrics['cv_f1_score']:.2%}`")
|
| 53 |
+
|
| 54 |
+
st.markdown("#### Wyniki metryk na zbiorze testowym:")
|
| 55 |
+
st.write(f"- Accuracy: `{metrics['accuracy']:.2%}`")
|
| 56 |
+
st.write(f"- F1-score: `{metrics['f1_score']:.2%}`")
|
| 57 |
+
|
| 58 |
+
st.markdown("#### Macierz pomyłek (Confusion Matrix):")
|
| 59 |
+
st.image(os.path.join(METRICS_DIR, 'confusion_matrix.png'))
|
app/requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
joblib
|
| 4 |
+
scikit-learn
|
metrics/classification_report.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
precision recall f1-score support
|
| 2 |
+
|
| 3 |
+
0 0.74 0.14 0.24 700
|
| 4 |
+
1 0.68 0.97 0.80 1300
|
| 5 |
+
|
| 6 |
+
accuracy 0.68 2000
|
| 7 |
+
macro avg 0.71 0.56 0.52 2000
|
| 8 |
+
weighted avg 0.70 0.68 0.60 2000
|
metrics/confusion_matrix.png
ADDED
|
metrics/metrics.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"accuracy": 0.6825, "f1_score": 0.7992412266835283, "best_model": "GradientBoosting", "cv_f1_score": 0.8046270813874387}
|
src/model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2c1da853e8732b81b3ce8a71e0c9d0e46ac46361e0e085c51bcce01664386239
|
| 3 |
+
size 275892
|