代码拉取完成,页面将自动刷新
"""
1. 安装kaggle的api: pip install kaggle
2. 在myAcount里找到create new API token,然后下载这个token,名字叫kaggle.json。
3. 把他放到/home/your account/.kaggle/文件夹内,如果没有这个文件夹则创建一个,注意这是一个默认隐藏的文件夹。
4. 要在比赛Rule page click "I understand and Accept"
5. 在终端输入对应的下载代码,这个在相应的kaggle数据集页面上有,比如我下的这个是kaggle competitions download -c challenges-in-representation-learning-facial-expression-recognition-challenge
"""
## 10 lines code to do Kaggle using autogluon
# env preparation
conda create -y --force -n ag python=3.8 pip
conda activate ag
pip install "mxnet<2.0.0"
pip install autogluon
## use case 1 with Kaggle titanic
# download data from kaggle
pip install kaggle
kaggle c download titanic
unzip -o titanic.zip
# starting model training
from autogluon.tabular import TabularDataset, TabularPredictor
train_data = TabularDataset('train.csv')
id, label = 'PassengerId', 'Survived'
predictor = TabularPredictor(label=label).fit(
train_data.drop(columns=[id]))
# prediction and test
import pandas as pd
test_data = TabularDataset('test.csv')
preds = predictor.predict(test_data.drop(columns=[id]))
submission = pd.DataFrame({id:test_data[id], label:preds})
submission.to_csv('submission.csv', index=False)
## use case 2 with California house pricing
from autogluon.tabular import TabularDataset, TabularPredictor
import numpy as np
train_data = TabularDataset('train.csv')
id, label = 'PassengerId', 'Survived'
# data preprocessing
large_val_cols = ['Lot', 'Total interior livable area', 'Tax assessed value', 'Annual tax amount', 'Listed Price', 'Last Sold Price']
for c in large_val_cols + [label]:
train_data[c] = np.log(train_data[c]+1)
# model 1
predictor = TabularPredictor(label=label).fit(train_data.drop(columns=[id]))
# model 2
predictor = TabularPredictor(label=label).fit(
train_data.drop(columns=[id]),
hyperparameters='multimodal',
num_stack_levels=1,
num_bag_folds=5)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。