Kaggle competition: Don't Get Kicked!
print(model.evaluate(x_test,y_test))
print(modelBest.evaluate(x_test,y_test))<save_to_csv>
train_data=pd.read_csv('/kaggle/input/DontGetKicked/training.csv')
 train_data.head()
with open('result.csv','w')as f:
f.write('ImageId,Label
' )<save_to_csv>
test_data=pd.read_csv('/kaggle/input/DontGetKicked/test.csv')
 test_data.head()
i=0
for x in data:
with open('result.csv','a')as f:
pred = modelBest.predict(x.reshape(1,28,28,1))
val = int(np.argmax(pred,axis=1))
i += 1
res = str(i)+ ',' + str(val)+ '
'
f.write(res )<import_modules>
train_data.isnull().sum()
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split<load_from_csv>
test_data.isnull().sum()
df_train = pd.read_csv('.. /input/train.csv' )<train_model>
train_data['IsBadBuy'].value_counts()
X_train = df_train.drop('label', axis = 1)
 y_train = df_train['label']
X_train = X_train / 255
X_train = X_train.values.reshape(-1,28,28,1)
 y_train = to_categorical(y_train)
 train_datagen = ImageDataGenerator(
 rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1, 
)
 train_datagen.fit(X_train)
 model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(16,(3,3), activation='relu', padding='same', input_shape=(28, 28, 1)) ,
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Conv2D(16,(3,3), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(32,(3,3), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Conv2D(32,(3,3), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Conv2D(64,(3,3), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Conv2D(64,(3,3), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Flatten() ,
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(10, activation='softmax')
 ])
 model.compile(loss='categorical_crossentropy',
optimizer=Adam(0.0001),
metrics=['acc'] )<train_model>
train_data['Model'].value_counts()
batch_size = 32
history = model.fit_generator(
 train_datagen.flow(X_train, y_train, batch_size=batch_size),
epochs=20,
)<save_to_csv>
train_data.drop('Model',axis=1,inplace=True)
 test_data.drop("Model",axis=1,inplace=True )
test = pd.read_csv('.. /input/test.csv')
 test = test / 255
test = test.values.reshape(-1,28,28,1)
 pred = model.predict(test)
 pred = np.argmax(pred, axis = 1)
 pred_csv = pd.DataFrame(pred, columns= ['Label'])
 pred_csv.index += 1
print(pred_csv)
 pred_csv.to_csv('submission.csv', index_label='ImageId' )<set_options>
train_data['Trim'].value_counts()
%matplotlib inline
print(pd.__version__, np.__version__, keras.__version__ )<load_from_csv>
train_data.drop('Trim',inplace=True,axis=1)
 test_data.drop('Trim',inplace=True,axis=1 )
data = pd.read_csv("/kaggle/input/digit-recognizer/train.csv")
 data.describe()<categorify>
train_data['SubModel'].value_counts()
X, y = data.iloc[:, 1:] / 255, data.iloc[:, 0]
X, y = X.values, y.values
print(X.dtype, y.dtype)
 X.resize(X.shape[0], 28, 28, 1)
 y = to_categorical(y, num_classes=10)
 print(type(X), X.shape)
 print(type(y), y.shape )<split>
train_data.drop('SubModel',inplace=True,axis=1)
 test_data.drop('SubModel',inplace=True,axis=1 )
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.1, random_state=3)
 print(X_train.shape, y_train.shape)
 print(X_val.shape, y_val.shape )<train_model>
train_data['Color'].value_counts()
datagen = ImageDataGenerator(
 rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1 
)
 datagen.fit(X_train )<define_search_model>
test_data['Color'].value_counts()
regularizer=10E-4
def res_block(x, i, regularizer=regularizer):
x1 = keras.layers.Conv2D(pow(2, i),(3, 3), activation='relu',
padding='same', kernel_initializer="he_normal",
kernel_regularizer=keras.regularizers.l2(regularizer))(x)
 x2 = keras.layers.Conv2D(pow(2, i),(3, 3), activation='relu',
padding='same', kernel_initializer="he_normal",
kernel_regularizer=keras.regularizers.l2(regularizer))(x1)
 x2 = keras.layers.Conv2D(pow(2, i),(3, 3), activation='relu',
padding='same', kernel_initializer="he_normal",
kernel_regularizer=keras.regularizers.l2(regularizer))(x2)
 x = keras.layers.concatenate([x1, x2])
 return x
input_X = keras.layers.Input(shape=(28, 28, 1))
x = input_X
for i in range(3, 7):
x = res_block(x, i)
 x = keras.layers.MaxPooling2D(2, 2 )(x)
 x = keras.layers.BatchNormalization()(x)
 x = keras.layers.Flatten()(x)
 y = keras.layers.Dense(units=10, activation='softmax' )(x)
 model = keras.models.Model(inputs=input_X, outputs=y)
 model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
 model.summary()
plot_model(model, show_shapes=True)
<train_model>
train_data['Color'].fillna(value='Color_Unknown',inplace=True)
 test_data['Color'].fillna(value='Color_Unknown',inplace=True )
es = keras.callbacks.EarlyStopping(monitor='val_loss', patience=7, restore_best_weights=True)
 history = model.fit_generator(
 datagen.flow(X_train, y_train, batch_size=64),
epochs=32,
verbose=1,
validation_data=(X_val, y_val),
shuffle=True,
callbacks=[es]
)<load_from_csv>
print("Number of null values in Color column "+str(train_data['Color'].isnull().sum()))
print("Number of null values in Color column "+str(test_data['Color'].isnull().sum()))
test_data = pd.read_csv("/kaggle/input/digit-recognizer/test.csv")
 test_imgs = test_data / 255
test_imgs = test_imgs.values
test_imgs.resize(test_imgs.shape[0], 28, 28, 1)
 print(test_imgs.shape )<predict_on_test>
train_data['Transmission'].value_counts()
predictions = model.predict(test_imgs ).argmax(axis=1)
 print(predictions.shape)
 print(predictions )<save_to_csv>
test_data['Transmission'].value_counts()
results = pd.DataFrame({"ImageID": range(1, len(test_imgs)+ 1),
"Label": predictions})
 print(results)
 results.to_csv("sample_submission.csv", header=True, index=False )<define_variables>
train_data[train_data['Transmission']=='Manual']
train_dir = ".. /input/train.csv"
test_dir = ".. /input/test.csv"<load_from_csv>
train_data['Transmission'].replace("Manual","MANUAL",inplace=True )
df = pd.read_csv(train_dir)
 test_df = pd.read_csv(test_dir)
 print("Total number of instance : ",len(df))
df.isna().sum()<drop_column>
train_data['Transmission'].value_counts()
df.drop(["Cabin"], axis = 1, inplace = True)
 test_df.drop(["Cabin"], axis = 1, inplace = True)
 df.drop(["Ticket"], axis = 1, inplace = True)
 test_df.drop(["Ticket"], axis = 1, inplace = True)
 df.info()
df.head(10 )<drop_column>
train_data['Transmission'].fillna(value="Transmission_unk",inplace=True)
 test_data['Transmission'].fillna(value="Transmission_unk",inplace=True )
df.drop("PassengerId", axis = 1, inplace = True)
 test_df.drop("PassengerId", axis = 1, inplace = True )<categorify>
train_data['WheelTypeID'].value_counts()
df["Sex"].replace("male", 0, inplace = True)
 test_df["Sex"].replace("male", 0, inplace = True)
 df["Sex"].replace("female", 1, inplace = True)
 test_df["Sex"].replace("female", 1, inplace = True)
 df["Embarked"].replace(["S","C","Q"],[0,1,2], inplace = True)
 test_df["Embarked"].replace(["S","C","Q"],[0,1,2], inplace = True )<feature_engineering>
train_data.drop('WheelTypeID',inplace=True,axis=1)
 test_data.drop('WheelTypeID',inplace=True,axis=1 )
def create_family_ranges(df):
familysize = []
for members in df["n_fam_mem"]:
if members == 0:
familysize.append(0)
 elif members > 0 and members <=4:
familysize.append(1)
 elif members > 4:
familysize.append(2)
 return familysize
famsize = create_family_ranges(df)
 df["familysize"] = famsize
test_famsize = create_family_ranges(test_df)
 test_df["familysize"] = test_famsize<categorify>
train_data['WheelType'].value_counts()
def age_to_int(df):
agelist = df["Age"].values.tolist()
for i in range(len(agelist)) :
if agelist[i] < 18 and agelist[i] >= 0:
agelist[i] = 0
elif agelist[i] >= 18 and agelist[i] < 60:
agelist[i] = 1
elif agelist[i]>=60 and agelist[i]<200:
agelist[i] = 2
else:
agelist[i] = -1
ageint = pd.DataFrame(agelist)
 return ageint<data_type_conversions>
test_data['WheelType'].value_counts()
ageint = age_to_int(df)
 df["Ageint"] = ageint
df.drop("Age", axis = 1, inplace = True)
 test_ageint = age_to_int(test_df)
 test_df["Ageint"] = test_ageint
test_df.drop("Age", axis = 1, inplace = True)
<categorify>
train_data['WheelType'].fillna(value='WheelType_unk',inplace=True)
 test_data['WheelType'].fillna(value='WheelType_unk',inplace=True )
def conv_fare_ranges(df):
fare_ranges = []
for fare in df.actual_fare:
if fare < 7:
fare_ranges.append(0)
 elif fare >=7 and fare < 14:
fare_ranges.append(1)
 elif fare >=14 and fare < 30:
fare_ranges.append(2)
 elif fare >=30 and fare < 50:
fare_ranges.append(3)
 elif fare >=50:
fare_ranges.append(4)
 return fare_ranges
fare_ranges = conv_fare_ranges(df)
 df["fare_ranges"] = fare_ranges
test_fare_ranges = conv_fare_ranges(test_df)
 test_df["fare_ranges"] = test_fare_ranges<categorify>
train_data['WheelType'].value_counts()
def name_to_int(df):
name = df["Name"].values.tolist()
namelist = []
for i in name:
index = 1
inew = i.split()
if inew[0].endswith(","):
index = 1
elif inew[1].endswith(","):
index = 2
elif inew[2].endswith(","):
index = 3
namelist.append(inew[index])
 print(set(namelist))
titlelist = []
for i in range(len(namelist)) :
if namelist[i] == "Lady.":
titlelist.append("Lady.")
 elif namelist[i] == "Ms.":
titlelist.append("Ms.")
 elif namelist[i] == "Miss.":
titlelist.append("Miss.")
 elif namelist[i] == "Dr.":
titlelist.append("Dr.")
 elif namelist[i] == "Mr.":
titlelist.append("Mr.")
 elif namelist[i] == "Jonkheer.":
titlelist.append("Jonkheer.")
 elif namelist[i] == "Col.":
titlelist.append("Col.")
 elif namelist[i] == "Mrs.":
titlelist.append("Mrs")
 elif namelist[i] == "Sir.":
titlelist.append("Sir.")
 elif namelist[i] == "Mlle.":
titlelist.append("Mlle.")
 elif namelist[i] == "Capt.":
titlelist.append("Capt.")
 elif namelist[i] == "the":
titlelist.append("the")
 elif namelist[i] == "Don.":
titlelist.append("Don.")
 elif namelist[i] == "Master.":
titlelist.append("Master.")
 elif namelist[i] == "Rev.":
titlelist.append("Rev.")
 elif namelist[i] == "Mme.":
titlelist.append("Mme.")
 elif namelist[i] == "Major.":
titlelist.append("Major.")
 else:
titlelist.append("sometitle")
 print(set(namelist))
return titlelist<count_values>
train_data['Nationality'].value_counts()
titlelist = name_to_int(df)
 df["titles"] = titlelist
df["titles"].value_counts()
testtitlelist = name_to_int(test_df)
 test_df["titles"] = testtitlelist<count_values>
test_data['Nationality'].value_counts()
df["titles"].replace(["Ms.","Jonkheer.","the","Don.","Capt.","Sir.","Lady.","Mme.","Col.","Major."],"sometitle", inplace = True)
 test_df["titles"].replace(["Ms.","Jonkheer.","the","Don.","Capt.","Sir.","Lady.","Mme.","Col.","Major."],"sometitle", inplace = True)
 df["titles"].replace("Mlle.","Miss.", inplace = True)
 test_df["titles"].replace("Mlle.","Miss.", inplace = True)
 test_df["titles"].value_counts()<categorify>
train_data['Nationality'].fillna(value='Nationality_unk',inplace=True)
 test_data['Nationality'].fillna(value='Nationality_unk',inplace=True )
df["titles"].replace(["Mr.", "Miss.", "Mrs", "Master.", "Dr.", "Rev.", "sometitle"],[0,1,2,3,4,5,6], inplace = True)
 df["titles"].astype("int64")
 test_df["titles"].replace(["Mr.", "Miss.", "Mrs", "Master.", "Dr.", "Rev.", "sometitle"],[0,1,2,3,4,5,6], inplace = True)
 test_df["titles"].astype("int64")
 df.drop(["Name"], axis = 1, inplace = True)
 test_df.drop(["Name"], axis = 1, inplace = True )<drop_column>
train_data['Size'].value_counts()
df.drop(["SibSp","Parch","Fare","n_fam_mem","actual_fare"], axis = 1, inplace = True)
 test_df.drop(["SibSp","Parch","Fare","n_fam_mem","actual_fare"], axis = 1, inplace = True )<split>
test_data['Size'].value_counts()
labels = df["Survived"]
data = df.drop("Survived", axis = 1)
 X_train, X_test, Y_train, Y_test = train_test_split(data, labels, test_size = 0.1 )<define_variables>
train_data['Size'].fillna(value='Size_unk',inplace=True)
 test_data['Size'].fillna(value="Size_unk",inplace=True )
final_clf = None
clf_names = ["Logistic Regression", "KNN(3)", "KNN(5)", "Random forest classifier", "Decision Tree Classifier",
"Gradient Boosting Classifier", "Support Vector Machine"]
classifiers = []
scores = []<train_on_grid>
train_data['TopThreeAmericanName'].value_counts()
bestknn5 = None
bestknn3 = None
bestrf = None
bestgb = None
bestcvm = None
bestlr = None
bestdt = None
for i in range(10):
X_train, X_test, Y_train, Y_test = train_test_split(data, labels, test_size = 0.1)
 tempscores = []
lr_clf = LogisticRegression()
lr_clf.fit(X_train, Y_train)
 tempscores.append(( lr_clf.score(X_test, Y_test)) *100)
 if lr_clf.score(X_test, Y_test)*100 > 85:
bestlr = lr_clf
knn3_clf = KNeighborsClassifier()
knn3_clf.fit(X_train, Y_train)
 tempscores.append(( knn3_clf.score(X_test, Y_test)) *100)
 if knn3_clf.score(X_test, Y_test)*100 > 85:
bestknn3 = knn3_clf
knn5_clf = KNeighborsClassifier()
knn5_clf.fit(X_train, Y_train)
 tempscores.append(( knn5_clf.score(X_test, Y_test)) *100)
 if knn5_clf.score(X_test, Y_test)*100 > 85:
bestknn5 = knn5_clf
rf_clf = RandomForestClassifier(n_estimators = 100)
 rf_clf.fit(X_train, Y_train)
 tempscores.append(( rf_clf.score(X_test, Y_test)) *100)
 if rf_clf.score(X_test, Y_test)*100 > 85:
bestrf = rf_clf
dt_clf = DecisionTreeClassifier()
dt_clf.fit(X_train, Y_train)
 tempscores.append(( dt_clf.score(X_test, Y_test)) *100)
 if dt_clf.score(X_test, Y_test)*100 > 85:
bestdt = dt_clf
gb_clf = GradientBoostingClassifier()
gb_clf.fit(X_train, Y_train)
 tempscores.append(( gb_clf.score(X_test, Y_test)) *100)
 if gb_clf.score(X_test, Y_test)*100 > 85:
bestgb = lr_clf
svm_clf = SVC(gamma = "scale")
 svm_clf.fit(X_train, Y_train)
 tempscores.append(( svm_clf.score(X_test, Y_test)) *100)
 if svm_clf.score(X_test, Y_test)*100 > 85:
bestsvm = svm_clf
scores.append(tempscores )<feature_engineering>
test_data['TopThreeAmericanName'].value_counts()
scores = np.array(scores)
 clfs = pd.DataFrame({"Classifier":clf_names})
 clfs["iteration0"] = scores[0].T
clfs["iteration1"] = scores[1].T
clfs["iteration2"] = scores[2].T
clfs["iteration3"] = scores[3].T
clfs["iteration4"] = scores[4].T
clfs["iteration5"] = scores[5].T
clfs["iteration6"] = scores[6].T
clfs["iteration7"] = scores[7].T
clfs["iteration8"] = scores[8].T
clfs["iteration9"] = scores[9].T
means = clfs.mean(axis = 1)
 means = means.values.tolist()
clfs["Average"] = means<find_best_params>
train_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True)
 test_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True )
final_clf = bestsvm<predict_on_test>
train_data['PRIMEUNIT'].value_counts()
test_data = test_df
predictions = final_clf.predict(test_data)
 print(len(predictions))<save_to_csv>
test_data['PRIMEUNIT'].value_counts()
final_csv = []
csv_title = ['PassengerId', 'Survived']
final_csv.append(csv_title)
 for i in range(len(predictions)) :
passengerid = i + 892
survived = predictions[i]
temp = [passengerid, survived]
final_csv.append(temp)
 print(len(final_csv))
with open('submission_csv.csv', 'w')as file:
writer = csv.writer(file)
 writer.writerows(final_csv)
 file.close()<set_options>
train_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True)
 test_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True )
%reload_ext autoreload
%autoreload 2
%matplotlib inline<import_modules>
train_data['AUCGUART'].replace("AGREEN","GREEN",inplace=True)
 test_data['AUCGUART'].replace("ARED","RED",inplace=True )
from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import *
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split<load_from_csv>
train_data['AUCGUART'].fillna(value="AUC_unk",inplace=True)
 test_data['AUCGUART'].fillna(value="AUC_unk",inplace=True )
train=pd.read_csv(f'{PATH}/train.csv')
 test=pd.read_csv(f'{PATH}/test.csv' )<split>
train_data.drop(['MMRAcquisitionAuctionAveragePrice','MMRAcquisitionAuctionCleanPrice',
'MMRAcquisitionRetailAveragePrice','MMRAcquisitonRetailCleanPrice',
'MMRCurrentAuctionAveragePrice','MMRCurrentAuctionCleanPrice',
'MMRCurrentRetailAveragePrice','MMRCurrentRetailCleanPrice'],
inplace=True,axis=1)
 test_data.drop(['MMRAcquisitionAuctionAveragePrice','MMRAcquisitionAuctionCleanPrice',
'MMRAcquisitionRetailAveragePrice','MMRAcquisitonRetailCleanPrice',
'MMRCurrentAuctionAveragePrice','MMRCurrentAuctionCleanPrice',
'MMRCurrentRetailAveragePrice','MMRCurrentRetailCleanPrice'],
inplace=True,axis=1 )
image=train.iloc[:,1:]
lbl=train.iloc[:,0:1] 
<data_type_conversions>
train_data.drop('PurchDate',axis=1,inplace=True)
 test_data.drop("PurchDate",axis=1,inplace=True )
img=image.as_matrix()
img=img.reshape(-1,28,28)
 test_img=test.as_matrix()
test_img=test_img.reshape(-1,28,28)
 img=np.stack(( img,)*3, axis=-1 ).astype('float32')
 test_img=np.stack(( test_img,)*3, axis=-1 ).astype('float32')
<categorify>
train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object'
<split>
not_categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object']
train_img, val_img, train_lbl, val_lbl=train_test_split(img, lbl, train_size=0.8,random_state=1 )<concatenate>
for i in not_categorical:
maximum=np.max(train_data[i])
 train_data[i]=train_data[i]/maximum
maximum_test=np.max(test_data[i])
 test_data[i]=test_data[i]/maximum_test
train_lbl=train_lbl.values.flatten()
val_lbl=val_lbl.values.flatten()<load_pretrained>
categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes=='object']
learn=ConvLearner.pretrained(arch, data, precompute=True )<find_best_params>
train_data[categorical[0]]
learn.lr_find()<load_pretrained>
pd.get_dummies(train_data[categorical[0]] )
learn=ConvLearner.pretrained(arch, data, precompute=True )<train_model>
for i in categorical:
dummies=pd.get_dummies(train_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
train_data=pd.concat([train_data,dummies],axis=1)
 train_data.drop(i,inplace=True,axis=1)
 dummies=pd.get_dummies(test_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
test_data=pd.concat([test_data,dummies],axis=1)
 test_data.drop(i,inplace=True,axis=1 )
learn.fit(0.01,9 )<load_pretrained>
for i in train_data.drop('IsBadBuy',axis=1 ).columns:
if i not in test_data.columns:
test_data[i]=np.zeros(len(test_data))
learn=ConvLearner.pretrained(arch, data, precompute=False )<train_model>
for i in test_data.columns:
if i not in train_data.columns:
train_data[i]=np.zeros(len(train_data))
learn.fit(0.01,9, cycle_len=1 )<define_search_space>
test_data=test_data[train_data.drop("IsBadBuy",axis=1 ).columns]
lr=np.array([1e-4,1e-3,1e-2] )<train_model>
X=train_data.drop(['RefId','IsBadBuy'],axis=1)
 y=train_data['IsBadBuy']
learn.fit(lr, 4, cycle_len=1, cycle_mult=2 )<save_model>
X_train,X_test,y_train,y_test=train_test_split(X,y,random_state=42 )
learn.save('4_epochs' )<predict_on_test>
from sklearn.neighbors import KNeighborsClassifier
%time log_preds_test, y_test=learn.TTA(is_test=True)
 probs_test=np.mean(np.exp(log_preds_test),0)
 probs_test.shape 
<create_dataframe>
from sklearn.neighbors import KNeighborsClassifier
df=pd.DataFrame(probs_test )<drop_column>
from sklearn.neighbors import KNeighborsClassifier
df1=df[['ImageId', 'Label']]<save_to_csv>
KNN=KNeighborsClassifier(n_neighbors=11)
 KNN.fit(X_train,y_train )
df1.to_csv("submission.csv", index=False )<import_modules>
KNN.score(X_test,y_test )
from tensorflow import keras<load_from_csv>
predict=KNN.predict(test_data.drop('RefId',axis=1))
train_data = pd.read_csv('.. /input/train.csv')
 test_data = pd.read_csv('.. /input/test.csv')
<data_type_conversions>
Submission=pd.DataFrame(data=predict,columns=['IsBadBuy'])
 Submission.head()
x_train =(train_data.iloc[:,1:].values ).astype('float32')
 y_train = train_data.iloc[:,0].values.astype('int32')
 x_test = test_data.values.astype('float32' )<define_variables>
Submission['RefId']=test_data['RefId']
Submission.set_index('RefId',inplace=True )
batch_size = 64
num_classes = 10
epochs = 25
input_shape =(28, 28, 1 )<split>
Submission.head()
Submission.to_csv('Submission.csv' )