Kaggle competition: SIIM-ISIC Melanoma Classification
<SOS> metric: MCAUC Kaggle data source: siim-isic-melanoma-classification<categorify>
import numpy as np
import pandas as pd
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, attrs):
self.attrs = attrs
def fit(self, X, y=None):
return self
def transform(self, X, y=None):
return X.loc[:, self.attrs]
class LabelBinarizerPipelineFriendly(OneHotEncoder):
def fit(self, X, y=None):

 super(LabelBinarizerPipelineFriendly,self ).fit(X)
 def transform(self, X, y=None):
return super(LabelBinarizerPipelineFriendly, self ).transform(X ).toarray()
def fit_transform(self, X, y=None):
return super(LabelBinarizerPipelineFriendly, self ).fit(X ).transform(X)
<create_dataframe>
print(h2o.__version__)
 h2o.init(max_mem_size='16G' )
num_pipeline = Pipeline([ 
('selection', DataFrameSelector(num_attrs)) , 
('merge_bath', MergeBath()), 
('merge_bsmnt', MergeBsmntFs()), 
('merge_porch', MergePorches()), 
('filter', FilterLotAreaAndRooms()), 
('drop', DataFrameDropper(num_drop_attrs)) , 
('impute', SimpleImputer()), 
('std_scale', StandardScaler()),
])
 label_pipeline = Pipeline([ 
('selection', DataFrameSelector(label_attrs)) , 
('drop', DataFrameDropper(label_new_drop_attrs)) , 
('impute', SimpleImputer(strategy="most_frequent")) , 
('encode', OneHotEncoder(sparse=False, handle_unknown='ignore')) , 
('std_scale', StandardScaler()),
])
 full_pipeline = FeatureUnion([ 
('num_pipline', num_pipeline), 
('label_pipeline', label_pipeline),
])
 X_train_cleaned = pd.DataFrame(full_pipeline.fit_transform(X_train_without_outlier))<prepare_x_and_y>
train = h2o.import_file(".. /input/melanoma-train-test-creator/train_meta_size_3.csv")
 test = h2o.import_file(".. /input/melanoma-train-test-creator/test_meta_size_3.csv" )
y_train = y_train_without_outlier<train_model>
x = test.columns
y = 'target'
linear_model = LinearRegression()
linear_model.fit(X_train_cleaned, y_train )<find_best_model_class>
train[y] = train[y].asfactor()
def analys_model(model):
some_data = X_train.iloc[:5]
some_label = y_train.iloc[:5]
some_data_prepared = full_pipeline.transform(some_data)
 print(f"\x1b[31mPredictions are \033[92m{model.predict(some_data_prepared)}")
 print(f"\x1b[31mLables are \033[92m{list(some_label)}")
 housing_prediction = model.predict(X_train_cleaned)
 scores = cross_validate(model, X_train_cleaned, y_train, scoring="neg_mean_squared_error", cv=3)
 rmse_scores = np.sqrt(-scores['test_score'])
 print(f"\x1b[31mScores : \033[92m{rmse_scores}")
 print(f"\x1b[31mMean : \033[92m{rmse_scores.mean() }")
 print(f"\x1b[31mStandard Deviation : \033[92m{rmse_scores.std() }" )<train_on_grid>
aml = H2OAutoML(max_models=10000, seed=47, max_runtime_secs=3600)
 aml.train(x=x, y=y, training_frame=train, fold_column="fold" )
sgd_grid = {
'n_iter_no_change': [10, 20, 30, 40, 50, 60, 80, 100, 130, 140],
'eta0': [0.4, 0.2, 0.1, 0.05, 0.03, 0.01, 0.009, 0.004],
}
sgd_model = SGDRegressor()
sgd_best = RandomizedSearchCV(sgd_model, sgd_grid, verbose=2, cv=3,n_jobs=-1,
scoring="neg_mean_squared_error" ).fit(X_train_cleaned, y_train ).best_estimator_
sgd_best
sgd_best.fit(X_train_cleaned, y_train)
 analys_model(sgd_best )<train_on_grid>
aml.leader
ridge_grid = {
'alpha': np.linspace(0, 1, num=500),
'solver' : ['cholesky'],
}
ridge_model = Ridge()
ridge_best = RandomizedSearchCV(ridge_model, ridge_grid, verbose=2, cv=3,n_jobs=-1,
scoring="neg_mean_squared_error" ).fit(X_train_cleaned, y_train ).best_estimator_
ridge_best.fit(X_train_cleaned, y_train)
 analys_model(ridge_best )<train_on_grid>
preds = aml.predict(test )
lasso_grid = {
'alpha': np.linspace(0, 1e-3, num=1000),
}
lasso_model = Lasso()
lasso_best = RandomizedSearchCV(lasso_model, lasso_grid, verbose=2, cv=3,n_jobs=-1,
scoring="neg_mean_squared_error" ).fit(X_train_cleaned, y_train ).best_estimator_
lasso_best.fit(X_train_cleaned, y_train)
 analys_model(lasso_best )<train_on_grid>
sample_submission = pd.read_csv('.. /input/siim-isic-melanoma-classification/sample_submission.csv')
 sample_submission.head()
<train_model><EOS> 
sample_submission['target'] = preds['p1'].as_data_frame().values
sample_submission.to_csv('submission.csv', index=False )