<jupyter_start><jupyter_text>Data Analysis<jupyter_code>stroke.info()
stroke['work_type'].value_counts()
import seaborn as sns
sns.countplot(x = 'stroke',data = stroke)
print("Target variable with value 0 : "+ format(len(stroke.loc[stroke['stroke']==0])))
print("Target variable with value 1 : "+ format(len(stroke.loc[stroke['stroke']==1])))
stroke1=stroke.copy(deep=True)
stroke1
stroke1['code_gender'] = stroke1.gender.astype('category').cat.codes
stroke1['code_ever_married']=stroke['ever_married'].astype('category').cat.codes
stroke1['code_work_type'] = stroke['work_type'].astype('category').cat.codes
stroke1['code_Residence_type'] = stroke['Residence_type'].astype('category').cat.codes
stroke1['code_smoking_status'] = stroke['smoking_status'].astype('category').cat.codes
stroke1.head(10)
stroke['gender'] = stroke.gender.astype('category').cat.codes
stroke['ever_married'] = stroke['ever_married'].astype('category').cat.codes
stroke['work_type'] = stroke['work_type'].astype('category').cat.codes
stroke['Residence_type'] = stroke['Residence_type'].astype('category').cat.codes
stroke['smoking_status'] = stroke['smoking_status'].astype('category').cat.codes
stroke1['work_type'].value_counts()
gender_dict={"Male":1,"Female":0}
married_dict={"Yes":1,"No":0}
work_dict={"Govt_job":0,"Never_worked ":1,"Private":2,"Self-employed":3,"children":4}
residence_code={"Urban":1,"Rural":0}
smoking_code={"Unknown":0,"formerly smoked":1,"never smoked":2,"smokes":3}<jupyter_output><empty_output><jupyter_text>Model Creation<jupyter_code>stroke
X = stroke[:,stroke.columns!='stroke']
Y = stroke['stroke'].values
X
#from imblearn.over_sampling import RandomOverSampler
#oversample=RandomOverSampler(sampling_strategy='minority')
#X, Y = oversample.fit_resample(X, Y)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X = pd.DataFrame(scaler.fit_transform(X), columns=X.columns)
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.35,random_state=0)
from sklearn import metrics
from sklearn.metrics import confusion_matrix 
from sklearn.metrics import classification_report 
from sklearn.metrics import accuracy_score 
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train,Y_train)
model.score(X_test,Y_test)<jupyter_output><empty_output><jupyter_text>Model File<jupyter_code>import joblib 
joblib.dump(model, 'model.pkl',compress=1)
#Sample prediction for Random Input
import numpy as np
load_model = joblib.load('model.pkl')
values = np.transpose(np.array([[0], [0.743652], [0], [1], [1], [0], [0], [0.301634], [0.303551],[1]]))
values.reshape(1, -1)
predictions = load_model.predict(values)
predictions<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1671480144404332, 'fraction_numerical': 0.023826714801444042, 'mean_word_length': 10.892703862660944, 'pattern_counts': {'":': 15, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '403583', 'license': 'MIT', 'n_tokens_mistral': 988, 'n_tokens_neox': 953, 'n_words': 136, 'path': 'Notebooks/Stroke.ipynb', 'repo_name': 'srisatya1197/HealthCheck', 'size': '2770'}