1 Star 0 Fork 0

minyuan/autogluon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
kaggle-install.py 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
minyuan 提交于 2021-06-30 23:23 . 10 lines code to do ML with autogluon
"""
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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/minyuan-fr/autogluon.git
git@gitee.com:minyuan-fr/autogluon.git
minyuan-fr
autogluon
autogluon
master

搜索帮助