Kaggle competition: Kannada MNIST
train_data['WheelType'].value_counts()<count_values>
import matplotlib.pyplot as plt
train_data['Nationality'].value_counts()<count_values>
dataset = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv' )
test_data['Nationality'].value_counts()<data_type_conversions>
X = dataset.iloc[:,1:].values
y = dataset.iloc[:,0].values
train_data['Nationality'].fillna(value='Nationality_unk',inplace=True)
 test_data['Nationality'].fillna(value='Nationality_unk',inplace=True )<count_values>
from sklearn.model_selection import train_test_split
train_data['Size'].value_counts()<count_values>
from sklearn.model_selection import train_test_split
test_data['Size'].value_counts()<data_type_conversions>
X_train, X_val, y_train, y_val = train_test_split(X, y,test_size=0.20,random_state=42 )
train_data['Size'].fillna(value='Size_unk',inplace=True)
 test_data['Size'].fillna(value="Size_unk",inplace=True )<count_values>
print("train samples:",X_train.shape[0])
 print("validation samples:",X_val.shape[0] )
train_data['TopThreeAmericanName'].value_counts()<count_values>
X_train = X_train.astype('float32')
 X_val = X_val.astype('float32')
 X_train /= 255
X_val /= 255
test_data['TopThreeAmericanName'].value_counts()<data_type_conversions>
img_shape = 28
X_train = np.reshape(X_train,(X_train.shape[0], img_shape, img_shape, 1))
X_val = np.reshape(X_val,(X_val.shape[0], img_shape, img_shape, 1))
input_shape =(img_shape, img_shape, 1 )
train_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True)
 test_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True )<count_values>
from tensorflow import keras
import tensorflow
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten,BatchNormalization
from keras.layers import Conv2D, MaxPooling2D,GlobalAveragePooling2D
train_data['PRIMEUNIT'].value_counts()<count_values>
batch_size = 256
num_classes = 10
epochs = 50
test_data['PRIMEUNIT'].value_counts()<data_type_conversions>
y_train = keras.utils.to_categorical(y_train,num_classes)
 y_val = keras.utils.to_categorical(y_val,num_classes)
train_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True)
 test_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True )<categorify>
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3),
activation='relu',
input_shape=input_shape))
model.add(Dropout(0.25))
model.add(Conv2D(64,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(64,(3, 3), activation='relu'))
model.add(MaxPooling2D(( 2,2)))
 model.add(Dropout(0.25))
model.add(Conv2D(128,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(128,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(128,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(128,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(128,(3, 3), activation='relu'))
model.add(Dropout(0.25))
model.add(GlobalAveragePooling2D())
 model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
train_data['AUCGUART'].replace("AGREEN","GREEN",inplace=True)
 test_data['AUCGUART'].replace("ARED","RED",inplace=True )<data_type_conversions>
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer="rmsprop",
metrics=['accuracy'] )
train_data['AUCGUART'].fillna(value="AUC_unk",inplace=True)
 test_data['AUCGUART'].fillna(value="AUC_unk",inplace=True )<drop_column>
callback = keras.callbacks.EarlyStopping(monitor='val_loss', patience=7 )
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 )<drop_column>
history = model.fit(X_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
callbacks=[callback],
validation_data=(X_val, y_val))
train_data.drop('PurchDate',axis=1,inplace=True)
 test_data.drop("PurchDate",axis=1,inplace=True )<drop_column>
loss,accuracy = model.evaluate(X_val, y_val,batch_size=256, verbose=1)
 print("accuracy:",accuracy)
 print("loss:",loss)
train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object'<drop_column>
val_loss = history.history['val_loss']
val_acc = history.history['val_accuracy']
train_loss = history.history['loss']
train_acc = history.history['accuracy']
not_categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object'] 
<feature_engineering>
sample_sub = pd.read_csv("/kaggle/input/Kannada-MNIST/sample_submission.csv" )
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<drop_column>
test = pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv")
 X_test = test.iloc[:,1:].values
test_ID = test.iloc[:,0].values
X_test = X_test.astype('float32')
 X_test /=255
X_test = np.reshape(X_test,(X_test.shape[0], img_shape, img_shape, 1))
categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes=='object']<filter>
predicts = model.predict(X_test,batch_size=256 )
train_data[categorical[0]]<categorify>
predicts_d = pd.DataFrame(predicts )
pd.get_dummies(train_data[categorical[0]] )<categorify>
number_pred =[]
for i in range(predicts_d.shape[0]):
probs = predicts_d.values[i]
for index,number in enumerate(probs):
max_ = probs.max()
if probs[index] == max_:
number_pred.append(index)
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 )<feature_engineering>
sub_dict = {"id":test_ID,"label":number_pred}
sub_dt = pd.DataFrame(sub_dict )
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))<feature_engineering>
sub_csv = sub_dt.to_csv('my-submission23.csv',index=False )