Spaces:
Sleeping
Sleeping
File size: 4,812 Bytes
ab31d46 337c210 ab31d46 e1ec722 ab31d46 89df161 ab31d46 8155166 ab31d46 a0c9c31 a5e5fe5 ab31d46 932bd4e ab31d46 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# -*- coding: utf-8 -*-
"""Diabetes.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/15IbzL0ARqBYPhh4fx4KN2rJ62USEmIO2
Importing the Dependencies
"""
#pip install -U scikit-learn
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score
"""Data Collection and Analysis
PIMA Diabetes Dataset
"""
# loading the diabetes dataset to a pandas DataFrame
diabetes_dataset = pd.read_csv('diabetes.csv')
# printing the first 5 rows of the dataset
diabetes_dataset.head()
# number of rows and Columns in this dataset
diabetes_dataset.shape
# getting the statistical measures of the data
diabetes_dataset.describe()
diabetes_dataset['Outcome'].value_counts()
"""0 --> Non-Diabetic
1 --> Diabetic
"""
diabetes_dataset.groupby('Outcome').mean()
# separating the data and labels
X = diabetes_dataset.drop(columns = 'Outcome', axis=1)
Y = diabetes_dataset['Outcome']
print(X)
print(Y)
"""Data Standardization"""
scaler = StandardScaler()
scaler.fit(X)
standardized_data = scaler.transform(X)
print(standardized_data)
X = standardized_data
Y = diabetes_dataset['Outcome']
print(X)
print(Y)
"""Train Test Split"""
X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size = 0.2, stratify=Y, random_state=2)
print(X.shape, X_train.shape, X_test.shape)
"""Training the Model"""
classifier = svm.SVC(kernel='linear')
#training the support vector Machine Classifier
classifier.fit(X_train, Y_train)
"""Model Evaluation
Accuracy Score
"""
# accuracy score on the training data
X_train_prediction = classifier.predict(X_train)
training_data_accuracy = accuracy_score(X_train_prediction, Y_train)
print('Accuracy score of the training data : ', training_data_accuracy)
# accuracy score on the test data
X_test_prediction = classifier.predict(X_test)
test_data_accuracy = accuracy_score(X_test_prediction, Y_test)
print('Accuracy score of the test data : ', test_data_accuracy)
"""Making a Predictive System"""
def predict(Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age):
#input_data = (5,166,72,19,175,25.8,0.587,51)
input_data = (Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age)
# changing the input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
# reshape the array as we are predicting for one instance
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
# standardize the input data
std_data = scaler.transform(input_data_reshaped)
print(std_data)
prediction = classifier.predict(std_data)
#print(prediction)
if (prediction[0] == 0):
print('The person is not diabetic')
else:
print('The person is diabetic')
return prediction
predict(4,136,64,20,175,25.6,0.597,50)
import gradio as gr
def dibetis_predict(Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age):
#input_data = (5,166,72,19,175,25.8,0.587,51)
input_data = (Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age)
# changing the input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
# reshape the array as we are predicting for one instance
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
# standardize the input data
std_data = scaler.transform(input_data_reshaped)
print(std_data)
prediction = classifier.predict(std_data)
if (prediction[0] == 0):
print('The person is not diabetic')
return 'The person is not diabetic'
else:
print('The person is diabetic')
return 'The person is diabetic'
demo = gr.Interface(
fn=dibetis_predict,
inputs = [
gr.Slider(0, 20, value=4, label="Pregnancies", info="Choose between 0 and 20"),
gr.Slider(1, 200, value=136, label="Glucose", info="Choose between 1 and 200"),
gr.Slider(1, 100, value=64, label="BloodPressure", info="Choose between 1 and 100"),
gr.Slider(1, 50, value=20, label="SkinThickness", info="Choose between 1 and 50"),
gr.Slider(1, 200, value=175, label="Insulin", info="Choose between 1 and 200"),
gr.Slider(1, 100, value=25.5, label="BMI", info="Choose between 1 and 100"),
gr.Slider(0, 1.0, value=0.549, label="DiabetesPedigreeFunction", info="Choose between 0.0 and 1.0"),
gr.Slider(1, 100, value=50, label="Age", info="Choose between 1 and 100"),
],
#description="Diabetes Prediction Model By Yash Rawal"
#Markdown("""Dibetese prediction system by Yash Rawal""")
outputs = "text",
)
if __name__ == "__main__":
demo.launch()
|