Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<prepare_output>
!pip install tensorflow-gpu==2.0.0-beta0
!pip install pandas
final_pred=(test_pred_stack*0.1665)+(test_pred_lgb*0.678)+(test_pred_ridge*0.1665)
 final_pred.head()<prepare_output>
import tensorflow as tf
from tensorflow import keras
sample_sub['SalePrice']=final_pred<save_to_csv>
def focal_loss_fn(gamma=2.,alpha=0.25):
EPSILON = 1e-6
def ce(y_true,y_pred,weights=None):
mask = y_pred < EPSILON
true_vals = tf.fill(tf.shape(y_pred),EPSILON)
 y_pred = tf.where(mask,true_vals,y_pred)
 ce = y_true*(-tf.math.log(y_pred)) +(1-y_true)*(-tf.math.log(1-y_pred))
if weights is not None:
ce = ce*weights
ce_loss = tf.reduce_mean(ce+EPSILON)
 return ce_loss
def focal_loss_fixed(y_true,y_pred):
t = y_true
p = y_pred
pt = p*t +(1-p)*(1-t)
 w = alpha*t +(1-alpha)*(1-t)
 w = tf.pow(( 1-pt),gamma)
 fl = ce(y_true,y_pred,w)
 return fl
return focal_loss_fixed
sample_sub.to_csv('SampleSubmissionForHousePrice.csv',index=False )<import_modules>
!pip install imutils
print("pandas version: {}".format(pd.__version__))
print("NumPy version: {}".format(np.__version__))
print("matplotlib version: {}".format(matplotlib.__version__))
print("seaborn version: {}".format(sns.__version__))
print("scikit-learn version: {}".format(sklearn.__version__))
print("statsmodels version: {}".format(statsmodels.__version__))
print("SciPy version: {}".format(sp.__version__)) 
<import_modules>
test_imgs_dir = ".. /input/aerial-cactus-identification/test/test"
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
from sklearn import feature_selection
from sklearn import model_selection
from sklearn import metrics
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import seaborn as sns<load_from_csv>
img_paths = list(paths.list_images(test_imgs_dir))
data = pd.read_csv(".. /input/titanic/train.csv")
 data_val = pd.read_csv(".. /input/titanic/test.csv")
 data1 = data.copy(deep = True)
 data_cleaner = [data1, data_val]<count_missing_values>
import cv2
print(data1.isnull().sum())
 print("-"*10)
 print(data_val.isnull().sum() )<data_type_conversions>
img_size = 96
images = []
img_names = []
for img_path in img_paths:
img_name = img_path.split(os.path.sep)[-1]
img = cv2.imread(img_path)
 img = cv2.resize(img,(img_size,img_size))
img = keras.preprocessing.image.img_to_array(img)
 images.append(img)
 img_names.append(img_name)
 images = np.array(images,dtype='float')/ 255.
 print(len(img_names),len(images))
print(np.max(images),np.min(images))
for dataset in data_cleaner:
dataset['Age'].fillna(dataset['Age'].median() , inplace = True)
 dataset['Embarked'].fillna(dataset['Embarked'].mode() [0], inplace = True)
 dataset['Fare'].fillna(dataset['Fare'].median() , inplace = True)
 dataset.drop('Cabin', axis=1, inplace=True )<count_missing_values>
predictions = model.predict(images )
print(data1.isnull().sum())
 print("-"*10)
 print(data_val.isnull().sum() )<categorify>
solution = np.concatenate(( img_names,predictions),axis=1)
 solution.shape
varlist = ['Sex']
def binary_map(x):
return x.map({'male': 1, "female": 0})
 for dataset in data_cleaner:
dataset[varlist] = dataset[varlist].apply(binary_map )<categorify>
submit_csv = pd.DataFrame(solution,columns=["id","has_cactus"])
 submit_csv.to_csv("submission_resnet50.csv",index=False )