aman77singh / Aman-Singh

0 stars 1 forks source link

FRONTEND #3

Open aman77singh opened 1 month ago

aman77singh commented 1 month ago

import streamlit as st import pandas as pd import numpy as np import pennylane as qml from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import classification_report, accuracy_score from sklearn.decomposition import PCA import matplotlib.pyplot as plt

Set up the Streamlit interface

st.title("Quantum vs Traditional Model Comparison") st.write("Upload your dataset and see how the Quantum model compares with a Traditional ML model.")

File upload

uploaded_file = st.file_uploader("Upload CSV", type="csv") if uploaded_file is not None: data = pd.read_csv(uploaded_file)

# Assuming last column is target and the rest are features
X = data.iloc[:, :-1].values  # All columns except the last one as features
y = data.iloc[:, -1].values   # The last column as the target

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Dimensionality reduction using PCA (optional based on qubits)
num_features = X_train.shape[1]
num_qubits = min(num_features, 4)  # Limit qubits
if num_features > num_qubits:
    pca = PCA(n_components=num_qubits)
    X_train = pca.fit_transform(X_train)
    X_test = pca.transform(X_test)

### Quantum Model Setup ###

dev = qml.device('default.qubit', wires=num_qubits)

@qml.qnode(dev)
def quantum_circuit(x, weights):
    # Encode classical data into quantum states
    for i in range(num_qubits):
        qml.RX(x[i], wires=i)

    # Variational circuit
    for i in range(num_qubits):
        qml.RY(weights[i], wires=i)
    qml.CNOT(wires=[0, 1])
    if num_qubits > 2:
        qml.CNOT(wires=[1, 2])
    if num_qubits > 3:
        qml.CNOT(wires=[2, 3])

    return [qml.expval(qml.PauliZ(i)) for i in range(num_qubits)]

# Quantum model's prediction
def quantum_predict(X, weights):
    predictions = []
    for x in X:
        output = quantum_circuit(x, weights)
        predictions.append(np.sign(output[0]))  # Binary classification (sign function)
    return np.array(predictions)

# Initialize weights for the quantum model
weight_shapes = {"w": (num_qubits,)}
quantum_weights = np.random.uniform(low=-np.pi, high=np.pi, size=weight_shapes["w"])

### Traditional Model Setup (Logistic Regression) ###

# Fit Logistic Regression as the traditional model
traditional_model = LogisticRegression()
traditional_model.fit(X_train, y_train)
traditional_pred = traditional_model.predict(X_test)

### Train Quantum Model (Simplified Version) ###
st.write("Training Quantum Model...")
quantum_pred = quantum_predict(X_test, quantum_weights)

### Results Comparison ###

# Quantum Model Evaluation
quantum_accuracy = accuracy_score(y_test, quantum_pred)
st.write(f"Quantum Model Accuracy: {quantum_accuracy:.2f}")

# Traditional Model Evaluation
traditional_accuracy = accuracy_score(y_test, traditional_pred)
st.write(f"Traditional Model (Logistic Regression) Accuracy: {traditional_accuracy:.2f}")

# Show a classification report for both models
st.write("### Quantum Model Classification Report")
st.text(classification_report(y_test, quantum_pred))

st.write("### Traditional Model Classification Report")
st.text(classification_report(y_test, traditional_pred))

### Plot Results ###

# Bar plot comparing the accuracy of the models
fig, ax = plt.subplots()
models = ['Quantum Model', 'Traditional Model']
accuracy = [quantum_accuracy, traditional_accuracy]

ax.bar(models, accuracy, color=['blue', 'green'])
ax.set_ylim([0, 1])
ax.set_ylabel("Accuracy")
ax.set_title("Quantum vs Traditional Model Accuracy")

# Display the plot in Streamlit
st.pyplot(fig)
Lilpro0802 commented 1 month ago

/ General Styles / body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; / Prevent scrolling / }

.background { position: relative; width: 100%; height: 100%; background-color: black; / Set background color / }

spline-viewer { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }

.overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; color: white; / Text color / }

h1 { font-size: 3em; margin-bottom: 20px; color: #00bfa6; }

p { font-size: 1.2em; margin-bottom: 40px; max-width: 600px; color: #ddd; }

.cta-button { background-color: #00bfa6; color: black; padding: 15px 30px; border-radius: 30px; text-decoration: none; font-size: 1em; transition: background-color 0.3s ease; }

.cta-button:hover { background-color: #00a98f; }

Lilpro0802 commented 1 month ago

<!DOCTYPE html>

Welcome to QuantumGuard

Welcome to QuantumGuard

Pioneering Financial Security with Quantum Precision. Enhance anomaly detection in financial transactions using the power of quantum machine learning.

Get Started
aaditya-029 commented 1 month ago

<!DOCTYPE html>

QuantumGuard – Pioneering Financial Security with Quantum Precision

QuantumGuard

Pioneering Financial Security with Quantum Precision

Enhancing anomaly detection in financial transactions using quantum machine learning

Upload Your Dataset

Lilpro0802 commented 1 month ago

<!DOCTYPE html>

Upload Your Dataset – QuantumGuard

QuantumGuard

Enhancing anomaly detection in financial transactions using quantum machine learning

Upload Your Dataset

aaditya-029 commented 1 month ago

<!DOCTYPE html>

QuantumGuard – Pioneering Financial Security with Quantum Precision

QuantumGuard

Pioneering Financial Security with Quantum Precision

Enhancing anomaly detection in financial transactions using quantum machine learning

Upload Your Dataset

aaditya-029 commented 1 month ago

<!DOCTYPE html>

QuantumGuard – Pioneering Financial Security

Welcome to QuantumGuard

Pioneering Financial Security with Quantum Precision. Enhance anomaly detection in financial transactions using the power of quantum machine learning.

Get Started About Feedback
aaditya-029 commented 1 month ago

<!DOCTYPE html>

QuantumGuard – Pioneering Financial Security with Quantum Precision

QuantumGuard

Pioneering Financial Security with Quantum Precision

Enhancing anomaly detection in financial transactions using quantum machine learning

Upload Your Dataset