<jupyter_start><jupyter_text>SVC<jupyter_code>clf1 = SVC(C=10,gamma=10, kernel="rbf")
ypred1 = clf1.predict(X)
s1 = f1_score(y1, ypred1, average="weighted")
clf2 = SVC(C=10,gamma=10, kernel="rbf").fit(X, y2)
ypred2 = clf2.predict(X)
s2 = f1_score(y2, ypred2, average="weighted")
scores = cross_val_score(clf1, X, y2, cv=5, scoring="f1_weighted")
print(scores)

score = 100 * (s1+s2) / 2
print(s1,s2)
print("Training f1 score: ", score)
# ypred1 = clf1.predict(X_train)
# s1 = f1_score(y_train1, ypred1, average="weighted")
# ypred2 = clf2.predict(X_train)
# s2 = f1_score(y_train2, ypred2, average="weighted")
0.9138437651219301 0.8973397476796859
Training f1 score:  90.55917564008081
X2 = df2.drop(columns=["pet_id"])
ypred11 = clf1.predict(X2)
ypred22 = clf2.predict(X2)
submission = pd.DataFrame({"pet_id": df2["pet_id"], "breed_category": ypred11, "pet_category": ypred22})
print(submission.shape)
submission.to_csv("submission.csv", index=False)<jupyter_output><empty_output><jupyter_text>XGBoost<jupyter_code># D_train1 = xgb.DMatrix(X, label=y1)
# D_train2 = xgb.DMatrix(X, label=y2)
# D_test1 = xgb.DMatrix(X_test, label=y_test1)
# D_test2 = xgb.DMatrix(X_test, label=y_test2)

# param1 = {
#     'eta': 0.3, 
#     'max_depth': 6,
#     "gamma": 0.1,
#     'objective': 'multi:softmax',
#     "nthread": 5,
#     # "lambda": 20,
#     # "alpha": 0.1,
#     "eval_metric": "mlogloss",
#     'num_class': 5} 

# param2 = {
#     'eta': 0.3, 
#     'max_depth': 6,
#     "gamma": 0.01,  
#     # "lambda": 10,
#     # "alpha": 0.1,
#     'objective': 'multi:softmax',
#     "eval_metric": "mlogloss",  
#     'num_class': 5} 

# steps = 20 

# model1 = xgb.train(param1, D_train1, steps)
# model2 = xgb.train(param2, D_train2, steps)

model1 = xgb.XGBClassifier(learning_rate=0.1,  
                      objective='multi:softmax', 
                      n_estimators=1000,
                      gamma=10,
                      max_depth=6).fit(X,y1) 

model2 = xgb.XGBClassifier(learning_rate=0.1,  
                      objective='multi:softmax', 
                      n_estimators=1000,
                      gamma=10, 
                      max_depth=6).fit(X,y2)
train_preds1 = model1.predict(X)
train_preds2 = model2.predict(X)

s1 = f1_score(y1, train_preds1, average="weighted")
s2 = f1_score(y2, train_preds2, average="weighted")
score = 100 * (s1+s2) / 2
print(s1,s2)
print("Training f1 score: ", score)
pd.DataFrame(preds1, columns=['Value'])['Value'].value_counts().plot(kind='barh')
test_preds1 = model1.predict(X2)
test_preds2 = model2.predict(X2)

# s1 = f1_score(y_test1, preds1, average="weighted")
# s2 = f1_score(y_test2, preds2, average="weighted")
# score = 100 * (s1+s2) / 2
# print(s1,s2)
# print("Test f1 score: ", score)

# pd.DataFrame(test_preds1, columns=['Value'])['Value'].value_counts().plot(kind='barh')
# D_train3 = xgb.DMatrix(X2)

ypred11 = model1.predict(X2)
ypred22 = model2.predict(X2)
submission = pd.DataFrame({"pet_id": df2["pet_id"], "breed_category": ypred11, "pet_category": ypred22})
print(submission.shape)
submission.to_csv("submission.csv", index=False)<jupyter_output><empty_output><jupyter_text>LGBM<jupyter_code>from lightgbm import LGBMClassifier
from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import uniform as sp_uniform
from scipy.stats import randint as sp_randint

lgb1 = LGBMClassifier(
    reg_lambda=57,
    refit=True,
    # reg_alpha=10,
    # learning_rate=0.1,
    max_depth=-1,
    n_estimators=200).fit(X,y1)

lgb2 = LGBMClassifier(
    # reg_lambda=0.1,
    # reg_alpha=0.01,
    learning_rate=0.1,
    refit=True,
    n_estimators=200).fit(X,y2)

# param_test ={'num_leaves': sp_randint(6, 50), 
#              'min_child_samples': sp_randint(100, 500), 
#              'min_child_weight': [1e-5, 1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3, 1e4],
#              'subsample': sp_uniform(loc=0.2, scale=0.8), 
#              'colsample_bytree': sp_uniform(loc=0.4, scale=0.6),
#              'reg_alpha': [40,42,44,56,57, 50, 60, 55],
#              'reg_lambda': [10,12,13, 15, 20,25],
#               'max_depth': [1,2,3,4,5,10,-1]}

# clf1 = RandomizedSearchCV(lgb1, param_test, random_state=0)
# clf2 = RandomizedSearchCV(lgb2, param_test, random_state=0)

# search1 = clf1.fit(X,y1)
# search2 = clf2.fit(X,y2)

# print(search1.best_params_)
# print(search2.best_params_)
train_preds1 = lgb1.predict(X)
train_preds2 = lgb2.predict(X)

s1 = f1_score(y1, train_preds1, average="weighted")
s2 = f1_score(y2, train_preds2, average="weighted")
score = 100 * (s1+s2) / 2
print(s1,s2)
print("Training f1 score: ", score)
ypred11 = lgb1.predict(X2)
ypred22 = lgb2.predict(X2)
submission = pd.DataFrame({"pet_id": df2["pet_id"], "breed_category": ypred11, "pet_category": ypred22})
print(submission.shape)
submission.to_csv("submission3.csv", index=False)<jupyter_output>(8072, 3)<jupyter_text>Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier

model1 = RandomForestClassifier(n_estimators=1000, max_depth=10, random_state=0).fit(X, y1)

model2 = RandomForestClassifier(n_estimators=1000, max_depth=10, random_state=0).fit(X, y2)
train_preds1 = model1.predict(X)
train_preds2 = model2.predict(X)

s1 = f1_score(y1, train_preds1, average="weighted")
s2 = f1_score(y2, train_preds2, average="weighted")
score = 100 * (s1+s2) / 2
print(s1,s2)
print("Training f1 score: ", score)
ypred11 = model1.predict(X2)
ypred22 = model2.predict(X2)
submission = pd.DataFrame({"pet_id": df2["pet_id"], "breed_category": ypred11, "pet_category": ypred22})
print(submission.shape)
submission.to_csv("submission10.csv", index=False)<jupyter_output><empty_output>