<jupyter_start><jupyter_text>Pre processing of Abalone dataset to make imbalance ratio of training and testing same<jupyter_code>import numpy as np
from numpy import linalg
import pandas as pd
train = pd.read_csv("haberman.csv",header=None)
train.head()
train[3] = train[3].map({2:1,1:-1})
print(train[3])
train=np.asarray(train)
min_train=np.zeros((81,4))
max_train=np.zeros((225,4))
min_train=np.asarray(min_train)
max_train=np.asarray(max_train)
k=0
l=0
for i in range(0,306):
    if(train[i][3]==1):
        for j in range(0,4):
            min_train[k][j]=train[i][j]   
        k=k+1
    else :
        for j in range(0,4):
            max_train[l][j]=train[i][j]
        l=l+1
print(min_train)
data1=np.zeros((61,4))
data2=np.zeros((61,4))
data3=np.zeros((61,4))
data4=np.zeros((61,4))
data5=np.zeros((62,4))
for i in range(0,81):
    for j in range(0,4):
        if(i<16):
            data1[i][j]=min_train[i][j]
        elif(15<i and i<32):
            data2[i-16][j]=min_train[i][j]
        elif(31<i and i<48):
            data3[i-32][j]=min_train[i][j]
        elif(47<i and i<64):
            data4[i-48][j]=min_train[i][j]
        elif(63<i and i<81):
            data5[i-64][j]=min_train[i][j]
    
        
print(data5[17])
for i in range(0,225):
    for j in range(0,4):
        if(i<45):
            data1[i+16][j]=max_train[i][j]
        elif(44<i and i<90):
            data2[i-29][j]=max_train[i][j]
        elif(89<i and i<135):
            data3[i-74][j]=max_train[i][j]
        elif(134<i and i<180):
            data4[i-119][j]=max_train[i][j]
        elif(179<i and i<225):
            data5[i-163][j]=max_train[i][j]   
print(data5[61])
print(data5.shape)
data5
import csv
with open('newab.csv', 'w') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(data1)

csvFile.close()
import csv
with open('newab.csv', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(data2)

csvFile.close()
import csv
with open('newab.csv', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(data3)

csvFile.close()
import csv
with open('newab.csv', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(data4)

csvFile.close()
import csv
with open('newab.csv', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(data5)

csvFile.close()
df = pd.read_csv("newab.csv")
#checking the number of empty rows in th csv file
print (df.isnull().sum())
#Droping the empty rows
modifiedDF = df.dropna()
#Saving it to the csv file 
modifiedDF.to_csv('modifiedhaberman.csv',index=False)<jupyter_output>34.0    0
59.0    0
0.0     0
1.0     0
dtype: int64
{'fraction_non_alphanumeric': 0.1709628506444276, 'fraction_numerical': 0.060272934040940106, 'mean_word_length': 3.2156549520766773, 'pattern_counts': {'":': 0, '<': 22, '<?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': '445261', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1071, 'n_words': 209, 'path': 'Fuzzy-SVM/Codici originari/Preprocessing Haberman.ipynb', 'repo_name': 'ritafolisi/Tirocinio', 'size': '2638'}