Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff to the repo linters #113

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ repos:
hooks:
- id: markdownlint
args: [--ignore-path=.markdownlintignore]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.231"
hooks:
- id: ruff
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.ruff]
line-length = 120
select = ["E", "F", "I", "UP", "B"]
fix = true
3 changes: 1 addition & 2 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import datetime
import os
import sys

sys.path.insert(0, os.path.abspath("../extensions"))
import datetime


# -- Project information -----------------------------------------------------

Expand Down
82 changes: 39 additions & 43 deletions source/examples/rapids-sagemaker-higgs/rapids-higgs.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,62 @@
#!/usr/bin/env python
# coding: utf-8

import argparse

import cudf
from cuml import RandomForestClassifier as cuRF
from cuml.preprocessing.model_selection import train_test_split
import cudf
import numpy as np
import pandas as pd
from sklearn.metrics import accuracy_score
import os
from urllib.request import urlretrieve
import gzip
import argparse


def main(args):

# SageMaker options
model_dir = args.model_dir
data_dir = args.data_dir

col_names = ['label'] + ["col-{}".format(i) for i in range(2, 30)] # Assign column names
dtypes_ls = ['int32'] + ['float32' for _ in range(2, 30)] # Assign dtypes to each column

data = cudf.read_csv(data_dir+'HIGGS.csv', names=col_names, dtype=dtypes_ls)
X_train, X_test, y_train, y_test = train_test_split(data, 'label', train_size=0.70)
data_dir = args.data_dir

col_names = ["label"] + [
f"col-{i}" for i in range(2, 30)
] # Assign column names
dtypes_ls = ["int32"] + [
"float32" for _ in range(2, 30)
] # Assign dtypes to each column

data = cudf.read_csv(data_dir + "HIGGS.csv", names=col_names, dtype=dtypes_ls)
X_train, X_test, y_train, y_test = train_test_split(data, "label", train_size=0.70)

# Hyper-parameters
hyperparams={
'n_estimators' : args.n_estimators,
'max_depth' : args.max_depth,
'n_bins' : args.n_bins,
'split_criterion' : args.split_criterion,
'bootstrap' : args.bootstrap,
'max_leaves' : args.max_leaves,
'max_features' : args.max_features
hyperparams = {
"n_estimators": args.n_estimators,
"max_depth": args.max_depth,
"n_bins": args.n_bins,
"split_criterion": args.split_criterion,
"bootstrap": args.bootstrap,
"max_leaves": args.max_leaves,
"max_features": args.max_features,
}

cu_rf = cuRF(**hyperparams)
cu_rf.fit(X_train, y_train)

print("test_acc:", accuracy_score(cu_rf.predict(X_test), y_test)
print("test_acc:", accuracy_score(cu_rf.predict(X_test), y_test))



if __name__ == "__main__":

parser = argparse.ArgumentParser()

# Hyper-parameters
parser.add_argument('--n_estimators', type=int, default=20)
parser.add_argument('--max_depth', type=int, default=16)
parser.add_argument('--n_bins', type=int, default=8)
parser.add_argument('--split_criterion', type=int, default=0)
parser.add_argument('--bootstrap', type=bool, default=True)
parser.add_argument('--max_leaves', type=int, default=-1)
parser.add_argument('--max_features', type=float, default=0.2)
parser.add_argument("--n_estimators", type=int, default=20)
parser.add_argument("--max_depth", type=int, default=16)
parser.add_argument("--n_bins", type=int, default=8)
parser.add_argument("--split_criterion", type=int, default=0)
parser.add_argument("--bootstrap", type=bool, default=True)
parser.add_argument("--max_leaves", type=int, default=-1)
parser.add_argument("--max_features", type=float, default=0.2)

# SageMaker parameters
parser.add_argument('--model_dir', type=str)
parser.add_argument('--model_output_dir', type=str, default='/opt/ml/output/')
parser.add_argument('--data_dir', type=str, default='/opt/ml/input/data/dataset/')
parser.add_argument("--model_dir", type=str)
parser.add_argument("--model_output_dir", type=str, default="/opt/ml/output/")
parser.add_argument("--data_dir", type=str, default="/opt/ml/input/data/dataset/")

args = parser.parse_args()
main(args)