Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- dataset.csv +44 -0
- ml_code.py +170 -0
- model.pkl +3 -0
- scaler.pkl +3 -0
dataset.csv
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Timestamp,1. Name ,2. How interested are you in the event topic? , 3. How close are you to the event location? ,4. How many similar events have you attended in the past year? , 5. How much free time do you have during the event timing? , 6. Are you willing to attend this event?
|
| 2 |
+
6/21/2025 9:52:30,Luffy,2,1,5,2,Yes
|
| 3 |
+
6/21/2025 9:53:07,S.Shalini,2,2,1,1,Yes
|
| 4 |
+
6/21/2025 9:53:12,Anachi,2,1,100,2,Yes
|
| 5 |
+
6/21/2025 9:53:57,Madhumitha,2,1,2,2,Yes
|
| 6 |
+
6/21/2025 9:54:16,Anantha Krishnan R ,2,1,2,2,Yes
|
| 7 |
+
6/21/2025 9:54:27,Stark,1,2,19,2,Prefer not to Say
|
| 8 |
+
6/21/2025 9:54:55,Reehan,2,1,50,2,Yes
|
| 9 |
+
6/21/2025 9:55:58,Ram,1,2,2,2,Yes
|
| 10 |
+
6/21/2025 9:57:24,Deepika ,2,2,2,2,No
|
| 11 |
+
6/21/2025 9:59:29,Hari,2,2,59,2,No
|
| 12 |
+
6/21/2025 10:00:40,prabhu,2,1,3,2,No
|
| 13 |
+
6/21/2025 10:00:44,Rajesh,2,1,45,1,Prefer not to Say
|
| 14 |
+
6/21/2025 10:01:00,sonia,2,2,3,2,Yes
|
| 15 |
+
6/21/2025 10:01:14,zoro,1,2,78,2,Yes
|
| 16 |
+
6/21/2025 10:01:39,Sanji,1,2,72,2,No
|
| 17 |
+
6/21/2025 10:01:40,pradeep,1,1,4,2,No
|
| 18 |
+
6/21/2025 10:01:44,yoga chandra shir,2,2,4,2,Yes
|
| 19 |
+
6/21/2025 10:02:04,Shanks,2,1,8,2,Yes
|
| 20 |
+
6/21/2025 10:02:12,vairaselvi,1,1,2,1,No
|
| 21 |
+
6/21/2025 10:02:28,Manikandan.K,2,2,7,2,Yes
|
| 22 |
+
6/21/2025 10:02:29,Aswin,1,1,3,1,Yes
|
| 23 |
+
6/21/2025 10:02:39,nami,1,2,45,2,No
|
| 24 |
+
6/21/2025 10:03:13,pavithra.V,2,1,7,1,No
|
| 25 |
+
6/21/2025 10:04:00,charan.s,2,1,6,2,Yes
|
| 26 |
+
6/21/2025 10:04:24,vishali,1,1,3,1,Yes
|
| 27 |
+
6/21/2025 10:04:28,Suriya,2,2,10,2,Yes
|
| 28 |
+
6/21/2025 10:04:45,surya prakash.s,2,1,9,2,No
|
| 29 |
+
6/21/2025 10:05:06,Naruto,1,1,5,1,Yes
|
| 30 |
+
6/21/2025 10:05:24,saranaya,2,2,5,2,No
|
| 31 |
+
6/21/2025 10:05:34,Stark,2,1,60,2,Prefer not to Say
|
| 32 |
+
6/21/2025 10:05:57,Garp,1,2,16,2,No
|
| 33 |
+
6/21/2025 10:06:03,mahesh,2,1,5,2,Yes
|
| 34 |
+
6/21/2025 10:06:19,Vivi,2,1,30,2,Yes
|
| 35 |
+
6/21/2025 10:06:32,malathi,2,1,6,1,Yes
|
| 36 |
+
6/21/2025 10:07:04,durga,2,2,6,1,Yes
|
| 37 |
+
6/21/2025 10:07:14,PraveenD,2,2,50,2,Yes
|
| 38 |
+
6/21/2025 10:07:38,Guts,1,2,50,2,Yes
|
| 39 |
+
6/21/2025 10:07:40,pandi selvi,2,2,5,2,Yes
|
| 40 |
+
6/21/2025 10:08:17,Ananth,1,2,20,2,Pr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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""ml_code.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1tETflt1JmWJudI-SDbtBiVIqjgCnaSU8
|
| 8 |
+
|
| 9 |
+
Import Packages :
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import numpy as np
|
| 14 |
+
from sklearn.linear_model import LogisticRegression
|
| 15 |
+
from sklearn.semi_supervised import SelfTrainingClassifier
|
| 16 |
+
from sklearn.preprocessing import StandardScaler
|
| 17 |
+
import joblib
|
| 18 |
+
|
| 19 |
+
"""Dataset Load :"""
|
| 20 |
+
|
| 21 |
+
# Load dataset
|
| 22 |
+
df = pd.read_csv("data.csv")
|
| 23 |
+
|
| 24 |
+
# Clean column names
|
| 25 |
+
df.columns = df.columns.str.strip()
|
| 26 |
+
|
| 27 |
+
# Rename relevant columns
|
| 28 |
+
df = df.rename(columns={
|
| 29 |
+
'2. How interested are you in the event topic?': 'interest',
|
| 30 |
+
'3. How close are you to the event location?': 'proximity',
|
| 31 |
+
'4. How many similar events have you attended in the past year?': 'past_attendance',
|
| 32 |
+
'5. How much free time do you have during the event timing?': 'free_time',
|
| 33 |
+
'6. Are you willing to attend this event?': 'willingness'
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
df.head()
|
| 37 |
+
|
| 38 |
+
"""Dataset Preprocess :"""
|
| 39 |
+
|
| 40 |
+
# Normalize values from linear scale 1–2 → 0–1
|
| 41 |
+
df[['interest', 'proximity', 'free_time']] = df[['interest', 'proximity', 'free_time']].apply(lambda x: (x - 1) / (2 - 1))
|
| 42 |
+
|
| 43 |
+
# Convert willingness to numerical values
|
| 44 |
+
df['willingness'] = df['willingness'].map({'Yes': 1, 'No': 0})
|
| 45 |
+
|
| 46 |
+
# Features and labels
|
| 47 |
+
X = df[['interest', 'proximity', 'past_attendance', 'free_time']].values
|
| 48 |
+
y = df['willingness'].values
|
| 49 |
+
|
| 50 |
+
"""Dataset into unlabeled :"""
|
| 51 |
+
|
| 52 |
+
# Unlabeled samples = -1
|
| 53 |
+
y_semi = np.array([label if not np.isnan(label) else -1 for label in y])
|
| 54 |
+
|
| 55 |
+
# Feature scaling
|
| 56 |
+
scaler = StandardScaler()
|
| 57 |
+
X_scaled = scaler.fit_transform(X)
|
| 58 |
+
|
| 59 |
+
"""Train the model :"""
|
| 60 |
+
|
| 61 |
+
# Base model
|
| 62 |
+
base_model = LogisticRegression()
|
| 63 |
+
|
| 64 |
+
# Self-Training Wrapper
|
| 65 |
+
self_training_model = SelfTrainingClassifier(base_model, criterion='k_best', k_best=3, max_iter=10)
|
| 66 |
+
|
| 67 |
+
# Train on partially labeled data
|
| 68 |
+
self_training_model.fit(X_scaled, y_semi)
|
| 69 |
+
|
| 70 |
+
print("✅ Self-training complete!")
|
| 71 |
+
|
| 72 |
+
"""Prediction :"""
|
| 73 |
+
|
| 74 |
+
# Predict on all samples
|
| 75 |
+
predicted = self_training_model.predict(X_scaled)
|
| 76 |
+
|
| 77 |
+
# Add predictions to DataFrame
|
| 78 |
+
df['predicted_attendance'] = predicted
|
| 79 |
+
|
| 80 |
+
# Save model and predictions
|
| 81 |
+
joblib.dump(self_training_model, "model.pkl")
|
| 82 |
+
joblib.dump(scaler, "scaler.pkl")
|
| 83 |
+
df.to_csv("predictions.csv", index=False)
|
| 84 |
+
|
| 85 |
+
print("✅ Model and predictions saved as model.pkl and predictions.csv")
|
| 86 |
+
|
| 87 |
+
"""Test the model:"""
|
| 88 |
+
|
| 89 |
+
# Load saved model and scaler
|
| 90 |
+
model = joblib.load("model.pkl")
|
| 91 |
+
scaler = joblib.load("scaler.pkl")
|
| 92 |
+
|
| 93 |
+
# 👇 Define your test input
|
| 94 |
+
# Format: [interest (0-1), proximity (0-1), past_attendance (integer), free_time (0-1)]
|
| 95 |
+
test_input = np.array([[0.0, 0.0, 0, 0.0]])
|
| 96 |
+
# You can change these values
|
| 97 |
+
|
| 98 |
+
# Scale input the same way training data was scaled
|
| 99 |
+
test_scaled = scaler.transform(test_input)
|
| 100 |
+
|
| 101 |
+
# Make prediction
|
| 102 |
+
prediction = model.predict(test_scaled)[0]
|
| 103 |
+
|
| 104 |
+
# Show result
|
| 105 |
+
if prediction == 1:
|
| 106 |
+
print("✅ The person is likely to ATTEND the event.")
|
| 107 |
+
else:
|
| 108 |
+
print("❌ The person is NOT likely to attend the event.")
|
| 109 |
+
|
| 110 |
+
"""Accuracy, Precision, Recall , F1(for classification):"""
|
| 111 |
+
|
| 112 |
+
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
|
| 113 |
+
|
| 114 |
+
# Filter only rows with actual labels (i.e., labeled data)
|
| 115 |
+
labeled_mask = y_semi != -1
|
| 116 |
+
X_labeled = X_scaled[labeled_mask]
|
| 117 |
+
y_true = y_semi[labeled_mask]
|
| 118 |
+
y_pred = self_training_model.predict(X_labeled)
|
| 119 |
+
|
| 120 |
+
# Classification Metrics
|
| 121 |
+
acc = accuracy_score(y_true, y_pred)
|
| 122 |
+
prec = precision_score(y_true, y_pred)
|
| 123 |
+
rec = recall_score(y_true, y_pred)
|
| 124 |
+
f1 = f1_score(y_true, y_pred)
|
| 125 |
+
|
| 126 |
+
# Display results
|
| 127 |
+
print(f"📊 Model Evaluation on Labeled Data:")
|
| 128 |
+
print(f"✅ Accuracy: {acc:.4f}")
|
| 129 |
+
print(f"✅ Precision: {prec:.4f}")
|
| 130 |
+
print(f"✅ Recall: {rec:.4f}")
|
| 131 |
+
print(f"✅ F1 Score: {f1:.4f}")
|
| 132 |
+
|
| 133 |
+
import gradio as gr
|
| 134 |
+
import joblib
|
| 135 |
+
import numpy as np
|
| 136 |
+
|
| 137 |
+
# Load model and scaler
|
| 138 |
+
model = joblib.load("model.pkl")
|
| 139 |
+
scaler = joblib.load("scaler.pkl")
|
| 140 |
+
|
| 141 |
+
# Prediction function
|
| 142 |
+
def predict_attendance(interest_pct, proximity_pct, past_attendance, free_time_pct):
|
| 143 |
+
# Convert % (0 to 100) to scale 1 to 2, then normalize to 0–1
|
| 144 |
+
interest = (interest_pct / 100)
|
| 145 |
+
proximity = (proximity_pct / 100)
|
| 146 |
+
free_time = (free_time_pct / 100)
|
| 147 |
+
|
| 148 |
+
# Prepare and scale input
|
| 149 |
+
input_data = np.array([[interest, proximity, past_attendance, free_time]])
|
| 150 |
+
input_scaled = scaler.transform(input_data)
|
| 151 |
+
|
| 152 |
+
# Predict
|
| 153 |
+
prediction = model.predict(input_scaled)[0]
|
| 154 |
+
return "✅ Will Attend" if prediction == 1 else "❌ Will Not Attend"
|
| 155 |
+
|
| 156 |
+
# Gradio UI
|
| 157 |
+
iface = gr.Interface(
|
| 158 |
+
fn=predict_attendance,
|
| 159 |
+
inputs=[
|
| 160 |
+
gr.Slider(0, 100, step=10, label="Interest in Topic (%)"),
|
| 161 |
+
gr.Slider(0, 100, step=10, label="Proximity to Event (%)"),
|
| 162 |
+
gr.Slider(0, 10, step=1, label="Similar Events Attended"),
|
| 163 |
+
gr.Slider(0, 100, step=10, label="Free Time Availability (%)"),
|
| 164 |
+
],
|
| 165 |
+
outputs="text",
|
| 166 |
+
title="🎯 Event Attendance Predictor",
|
| 167 |
+
description="Enter your info to find out if you're likely to attend this event. Sliders use percent to indicate strength or availability."
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
iface.launch()
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a49cf98b439fa45ec267bcfd68cb5f5c3d387de5f3bcfd0358b0866b4d06a7d
|
| 3 |
+
size 2064
|
scaler.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d6fabef7b51f48aa5fd1a94f31e52e8cd8d68e7f34dc9c3902ec23014a094bfe
|
| 3 |
+
size 711
|