File size: 1,223 Bytes
79c3e86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
# coding: utf-8

# In[8]:


#!/usr/bin/env python
# coding: utf-8

# In[6]:


# app.py
import gradio as gr
import joblib
import json
import numpy as np

# Load the model and scaler
model = joblib.load('xgboost_breast_cancer_model.joblib')
scaler = joblib.load('scaler.joblib')

# Load feature names
with open('feature_names.json', 'r') as f:
    feature_names = json.load(f)

def predict_cancer(*features):
    # Convert inputs to numpy array
    input_data = np.array(features).reshape(1, -1)
    
    # Scale the input data
    scaled_input = scaler.transform(input_data)
    
    # Make prediction
    prediction_proba = model.predict_proba(scaled_input)[0, 1]
    
    # Apply threshold
    prediction = "Malignant" if prediction_proba >= 0.4 else "Benign"
    
    return f"Prediction: {prediction}\nProbability of being malignant: {prediction_proba:.2f}"

# Create Gradio interface
iface = gr.Interface(
    fn=predict_cancer,
    inputs=[gr.Number(label=name) for name in feature_names],
    outputs="text",
    title="Breast Cancer Prediction",
    description="Enter the feature values to predict whether a breast mass is benign or malignant."
)

iface.launch()


# In[ ]:






# In[ ]: