<jupyter_start><jupyter_text><jupyter_code>#Connect to Anvil
!pip install anvil-uplink
import anvil.server
anvil.server.connect("2ZZFEIO7RSWJ2NSXVOIJU7NK-PUMVCYIB7OL5ZPSL")
#Import scikit-learn dataset library
from sklearn import datasets
import pandas as pd
import numpy as np


from sqlalchemy import create_engine
engine = create_engine('sqlite://', echo=False)

#Load dataset
cleveland = pd.read_csv('heart.csv')
# Import train_test_split function
from sklearn.model_selection import train_test_split

# Split dataset into training set and test set
x = np.array(cleveland.drop(['target'], 1))
y = np.array(cleveland['target'])

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)
#Import svm model
from sklearn import svm

#Create a svm Classifier
clf = svm.SVC(C = 60, kernel='linear') # Linear Kernel

#Train the model using the training sets
clf.fit(X_train, y_train)

#Predict the response for test dataset
y_pred = clf.predict(X_test)
#Import scikit-learn metrics module for accuracy calculation
from sklearn import metrics

# Model Accuracy: how often is the classifier correct?
Accuracy = metrics.accuracy_score(y_test, y_pred)
print("Accuracy:",Accuracy)
#Create Callable Function
@anvil.server.callable
def svmpredict(Age, Sex, CP, BP, Cholesterol, BS, RestECG_Results, MaxHR, exind_Angina, ST_Depression, ST_Slope, MajorVessels, Thal_Test):
  #Converts to CSV file
  patientData = pd.DataFrame([[Age, Sex, CP, BP, Cholesterol, BS, RestECG_Results, MaxHR, exind_Angina, ST_Depression, ST_Slope, MajorVessels, Thal_Test]], columns=['Age','Sex','CP','BP','Cholesterol','BS', 'RestECG_Results','MaxHR', 'exind_Angina', 'ST_Depression','ST_Slope','MajorVessels','Thal_Test'])
  patientData.to_csv('patientData.csv')
  
  #Calculates results
  PatientTest = clf.predict(patientData)
  PercentAccuracy = round(Accuracy * 100, 2)
  return PatientTest, PercentAccuracy

anvil.server.wait_forever()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10747894997523527, 'fraction_numerical': 0.0079247152055473, 'mean_word_length': 5.824324324324325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '365757', 'license': 'Unlicense', 'n_tokens_mistral': 768, 'n_tokens_neox': 705, 'n_words': 176, 'path': 'Final_SVM_JJ.ipynb', 'repo_name': 'beny2000/HeartDiseaseClassifier', 'size': '2019'}