Kaggle competition: Aerial Cactus Identification
train.Ticket = pd.to_numeric(train.Ticket.str.split().str[-1] , errors='coerce')
 test.Ticket = pd.to_numeric(test.Ticket.str.split().str[-1] , errors='coerce' )<count_missing_values>
test= pd.read_csv('.. /input/firstaa/submission.csv' )
train.isna().sum()<count_missing_values>
test['has_cactus']=test['has_cactus'].apply(lambda x:1 if x>=0.3 else 0 )
test.isna().sum()<feature_engineering>
train['Status'] = train['Name'].str.split(',' ).str.get(1 ).str.split('.' ).str.get(0 ).str.strip()
test['Status'] = test['Name'].str.split(',' ).str.get(1 ).str.split('.' ).str.get(0 ).str.strip()
importan_person = ['Dr' , 'Rev' , 'Col' , 'Major' , 'Mlle' , 'Don' , 'Sir' , 'Ms' , 'Capt' , 'Lady' , 'Mme' , 'the Countess' , 'Jonkheer' , 'Dona']
for person in importan_person:
train.Status.replace(person, 'IMP' , inplace =True)
 test.Status.replace(person, 'IMP' , inplace =True )<drop_column>
y_train = np.array(train.has_cactus )
test.drop(['Name' , 'Ticket' ] ,axis = 1, inplace = True)
 train.drop(['Survived','Ticket' ,'Name' ], inplace =True , axis =1 )<categorify>
from keras.applications import resnet50
cat_col = ['Pclass' , 'Sex' , 'Embarked' , 'Status' , 'Deck']
train.Pclass.replace({
1 :'A' , 2:'B' , 3:'C'
} , inplace =True)
 test.Pclass.replace({
1 :'A' , 2:'B' , 3:'C'
} , inplace =True)
 train = pd.get_dummies(train , columns=cat_col)
 test = pd.get_dummies(test , columns=cat_col)
 print(train.shape , test.shape )<normalization>
from keras.layers import GlobalAveragePooling2D,Dense,Dropout
from keras.models import Model
scaler = MinMaxScaler()
train= scaler.fit_transform(train)
 test = scaler.transform(test )<compute_train_metric>
from keras.optimizers import Adam
from keras.callbacks import ReduceLROnPlateau, EarlyStopping
model = RandomForestClassifier(bootstrap= True , min_samples_leaf= 3, n_estimators = 500 ,
min_samples_split = 10, max_features = "sqrt", max_depth= 6)
 cross_val_score(model , train , label , cv=5 )<compute_train_metric>
red =ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=10, verbose=0, mode='auto', epsilon=0.0001, cooldown=0, min_lr=0)
 early_stopping = EarlyStopping(monitor='val_loss', patience=50, verbose=1 )
model = LogisticRegression()
cross_val_score(model , train , label , cv=5 )<compute_train_metric>
model.compile(loss='binary_crossentropy', optimizer=Adam(lr=0.0001), metrics=['accuracy'] )
model = SVC(C=4)
 cross_val_score(model , train , label , cv=5 )<train_model>
pre=model.predict(X_test)[:,0]
model.fit(train , label)
 pre = model.predict(test )<save_to_csv>
from skimage.io import imshow
ans = pd.DataFrame({'PassengerId' : index , 'Survived': pre})
 ans.to_csv('submit.csv', index = False)
 ans.head()<load_from_csv>
test.to_csv('submission.csv', index=False)
 test.head()