import streamlit as st import pandas as pd import numpy as np import pickle import base64 import seaborn as sns import matplotlib.pyplot as plt st.write(""" # Breast Cancer Prediction App Kanker payudara adalah kanker paling umum di kalangan wanita di dunia. Ini menyumbang 25% dari semua kasus kanker, dan mempengaruhi lebih dari 2,1 Juta orang pada tahun 2015 saja. Ini dimulai ketika sel-sel di payudara mulai tumbuh di luar kendali. Sel-sel ini biasanya membentuk tumor yang dapat dilihat melalui sinar-X atau dirasakan sebagai benjolan di area payudara. Tantangan utama untuk mendeteksinya adalah bagaimana mengklasifikasikan tumor menjadi ganas (kanker) atau jinak (non kanker). """) url_dataset = f'Download Dataset CSV File' st.markdown(url_dataset, unsafe_allow_html=True) def user_input_features() : radius_mean = st.sidebar.slider('radius_mean', 6.981,28.11) texture_mean = st.sidebar.slider('texture_mean', 9.71,39.28) perimeter_mean = st.sidebar.slider('perimeter_mean', 43.79,188.5) area_mean = st.sidebar.slider('area_mean', 143.5,2501.0) smoothness_mean = st.sidebar.slider('smoothness_mean', 0.05263,0.1634) compactness_mean = st.sidebar.slider('compactness_mean', 0.01938,0.3454) concavity_mean = st.sidebar.slider('concavity_mean', 0.0,4268.0) concave_points_mean = st.sidebar.slider('concave_points_mean', 0.0,0.2012) symmetry_mean = st.sidebar.slider('symmetry_mean', 0.106,0.304) fractal_dimension_mean = st.sidebar.slider('fractal_dimension_mean', 0.04996,0.09744) radius_se = st.sidebar.slider('radius_se', 0.1115,2.873) texture_se = st.sidebar.slider('texture_se', 0.3602,4.885) perimeter_se = st.sidebar.slider('perimeter_se', 0.757,21.98) area_se = st.sidebar.slider('area_se', 6.802,542.2) smoothness_se = st.sidebar.slider('smoothness_se', 0.001713,0.03113) compactness_se = st.sidebar.slider('compactness_se', 0.002252,0.1354) concavity_se = st.sidebar.slider('concavity_se', 0.0,0.396) concave_points_se = st.sidebar.slider('concave_points_se', 0.0,0.05279) symmetry_se = st.sidebar.slider('symmetry_se', 0.007882,0.07895) fractal_dimension_se = st.sidebar.slider('fractal_dimension_se', 0.000895,0.02984) radius_worst = st.sidebar.slider('radius_worst', 7.93,36.04) texture_worst = st.sidebar.slider('texture_worst', 12.02,49.54) radius_worst = st.sidebar.slider('radius_worst', 0.1115,2.873) perimeter_worst = st.sidebar.slider('perimeter_worst', 50.41,251.2) area_worst = st.sidebar.slider('area_worst', 185.2,4254.0) smoothness_worst = st.sidebar.slider('smoothness_worst', 0.07117,0.2226) compactness_worst = st.sidebar.slider('compactness_worst', 0.02729,1.058) concavity_worst = st.sidebar.slider('concavity_worst', 0.0,1.252) concave_points_worst = st.sidebar.slider('concave_points_worst', 0.0,0.291) symmetry_worst = st.sidebar.slider('symmetry_worst', 0.1565,0.6638) fractal_dimension_worst = st.sidebar.slider('fractal_dimension_worst', 0.1565,0.2075) data = {'radius_mean':[radius_mean], 'texture_mean':[texture_mean], 'radius_mean':[radius_mean], 'perimeter_mean':[perimeter_mean], 'radius_mean':[radius_mean], 'area_mean':[area_mean], 'smoothness_mean':[smoothness_mean], 'compactness_mean':[compactness_mean], 'concavity_mean':[concavity_mean], 'concave_points_mean':[concave_points_mean], 'symmetry_mean':[symmetry_mean], 'fractal_dimension_mean':[fractal_dimension_mean], 'radius_se':[radius_se], 'texture_se':[texture_se], 'perimeter_se':[perimeter_se], 'area_se':[area_se], 'smoothness_se':[smoothness_se], 'compactness_se':[compactness_se], 'concavity_se':[concavity_se], 'concave_points_se':[concave_points_se], 'symmetry_se':[symmetry_se], 'fractal_dimension_se':[fractal_dimension_se], 'fractal_dimension_se':[fractal_dimension_se], 'radius_worst':[radius_worst], 'texture_worst':[texture_worst], 'perimeter_worst':[perimeter_worst], 'area_worst':[area_worst], 'smoothness_worst':[smoothness_worst], 'compactness_worst':[compactness_worst], 'concavity_worst':[concavity_worst], 'concave_points_worst':[concave_points_worst], 'symmetry_worst':[symmetry_worst], 'fractal_dimension_worst':[fractal_dimension_worst] } features = pd.DataFrame(data) return features input_df = user_input_features() breast_raw = pd.read_csv('breast_cancer.csv') breast_raw.fillna(0, inplace=True) breast = breast_raw.drop(columns=['diagnosis']) df = pd.concat([input_df,breast],axis=0) df = df[:1] # Selects only the first row (the user input data) df.fillna(0, inplace=True) features = ['radius_mean', 'texture_mean', 'perimeter_mean', 'area_mean', 'smoothness_mean', 'compactness_mean', 'concavity_mean', 'concave points_mean', 'symmetry_mean', 'fractal_dimension_mean', 'radius_se', 'texture_se', 'perimeter_se', 'area_se', 'smoothness_se', 'compactness_se', 'concavity_se', 'concave points_se', 'symmetry_se', 'fractal_dimension_se', 'radius_worst', 'texture_worst', 'perimeter_worst', 'area_worst', 'smoothness_worst', 'compactness_worst', 'concavity_worst', 'concave points_worst', 'symmetry_worst', 'fractal_dimension_worst'] df = df[features] st.subheader('User Input features') st.write(df) load_clf = pickle.load(open('breast_clf.pkl', 'rb')) prediction = load_clf.predict(df) prediction_proba = load_clf.predict_proba(df) breast_labels = np.array(['Benign','Malignant']) st.subheader('Detection') if(prediction == 'B') : st.write(breast_labels[0]) else : st.write(breast_labels[1]) st.subheader('Detection Probability') df_proba = pd.DataFrame(data=prediction_proba, index=['Probability'], columns=breast_labels) st.write(df_proba)