<jupyter_start><jupyter_text>3. Pima Indians Diabetes DatasetThe Pima Indians Diabetes Dataset involves predicting the onset of diabetes within 5 years in Pima Indians given medical details.It is a binary (2-class) classification problem. The number of observations for each class is not balanced. There are 768 observations with 8 input variables and 1 output variable. Missing values are believed to be encoded with zero values. The variable names are as follows:Number of times pregnant.Plasma glucose concentration a 2 hours in an oral glucose tolerance test.Diastolic blood pressure (mm Hg).Triceps skinfold thickness (mm).2-Hour serum insulin (mu U/ml).Body mass index (weight in kg/(height in m)^2).Diabetes pedigree function.Age (years).Class variable (0 or 1).The baseline performance of predicting the most prevalent class is a classification accuracy of approximately 65%. Top results achieve a classification accuracy of approximately 77%.<jupyter_code>import csv

rawdata = []
with open("data/pima_indians_diebetes/pima-indians-diabetes.data.csv") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
            rawdata.append(row)
            line_count += 1
    print(f'Processed {line_count} lines.')
import numpy as np
import matplotlib.pyplot as plt

rawdata = np.array(rawdata)
x_raw = rawdata[:,0:8]
y_raw = rawdata[:,8]
# for row in x_raw:
#     print(row)
x_raw = x_raw.astype(float)
y_raw = y_raw.astype(float)
# for row in x_raw:
#     print(row)
print(x_raw.shape)
print(y_raw.shape)
x_isna = False
y_isna = False
for row in x_raw:
    if(np.isnan(np.min(row)) == True):
        x_isna =True
        
for row in y_raw:
    if(np.isnan(np.min(row)) == True):
        y_isna =True
print(x_isna)
print(y_isna)
plt.figure(num=None, figsize=(10, 4), dpi=80, facecolor='w', edgecolor='k')
# plt.scatter(x_raw[:,0],y_raw,1,c = "blue")
# plt.scatter(x_raw[:,1],y_raw,1,c = "red")
# plt.scatter(x_raw[:,2],y_raw,1,c = "green")
# plt.scatter(x_raw[:,3],y_raw,1,c = "black")
plt.scatter(x_raw[:,4],y_raw,1,c = "purple")
# plt.scatter(x_raw[:,5],y_raw,1,c = "pink")
# plt.scatter(x_raw[:,6],y_raw,1,c = "maroon")
# plt.scatter(x_raw[:,7],y_raw,1,c = "green")
plt.yticks([0,1]) 
plt.show
np.mean(x_raw[:,4])
[abs (x_raw[:,4] - np.mean(x_raw[:,4])) < 1 * np.std(x_raw[:,4])].index(False)

x_raw.shape
plt.figure(num=None, figsize=(10, 4), dpi=80, facecolor='w', edgecolor='k')
# plt.scatter(x_raw[:,0],y_raw,1,c = "blue")
# plt.scatter(x_raw[:,1],y_raw,1,c = "red")
# plt.scatter(x_raw[:,2],y_raw,1,c = "green")
# plt.scatter(x_raw[:,3],y_raw,1,c = "black")
plt.scatter(x_raw[:,4],y_raw,1,c = "purple")
# plt.scatter(x_raw[:,5],y_raw,1,c = "pink")
# plt.scatter(x_raw[:,6],y_raw,1,c = "maroon")
# plt.scatter(x_raw[:,7],y_raw,1,c = "green")
plt.yticks([0,1]) 
plt.show
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(x_raw, y_raw, test_size=0.3)
from sklearn.linear_model import LogisticRegression
clf1 = LogisticRegression().fit(x_train, y_train)
print( clf1.score(x_train, y_train) )
print( clf1.score(x_test, y_test) )
plt.figure(num=None, figsize=(10, 4), dpi=80, facecolor='w', edgecolor='k')
plt.scatter(x_train[:,1],y_train,30,c = "green")
plt.scatter(x_train[:,1],clf1.predict(x_train),1,c = "red")
plt.show
from sklearn.svm import SVC
clf20 = SVC(gamma = 'scale',kernel='linear').fit(x_train, y_train)
clf21 = SVC(gamma = 'scale',kernel='linear').fit(x_train, y_train)
print( clf20.score(x_train, y_train) )
print( clf20.score(x_test, y_test) )
print( clf21.score(x_train, y_train) )
print( clf21.score(x_test, y_test) )
plt.figure(num=None, figsize=(10, 4), dpi=80, facecolor='w', edgecolor='k')
plt.scatter(x_train[:,1],y_train,30,c = "green")
plt.scatter(x_train[:,1],clf2.predict(x_train),1,c = "red")
plt.show
from sklearn.neural_network import MLPClassifier
besthp ={}
bestsc = []
for x in range(1,30,2):
    for y in range(1,30,2):
        print(x,y)
        clf3 = MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(x,y), random_state=1).fit(x_train, y_train)
#         besthp.update(clf3.score(x_test, y_test)=(x,y))
        bestsc.append(clf3.score(x_test, y_test))

(max(bestsc))
clf3 = MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(23,15), random_state=1).fit(x_train, y_train)

print( clf3.score(x_train, y_train) )
print( clf3.score(x_test, y_test) )<jupyter_output>0.750465549348231
0.7142857142857143
{'fraction_non_alphanumeric': 0.1667782987273945, 'fraction_numerical': 0.03773163652601027, 'mean_word_length': 5.686567164179104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '612073', 'license': 'MIT', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1838, 'n_words': 367, 'path': 'Mini Projects/pima_indians_diebetes.ipynb', 'repo_name': 'xo28122000/ML_in_Python', 'size': '4479'}