mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-09-06 23:17:22 +00:00
Compare commits
6 Commits
typehintin
...
improve-de
Author | SHA1 | Date | |
---|---|---|---|
|
8ae1593861 | ||
|
1372aa03f9 | ||
|
7284851091 | ||
|
9232cc31be | ||
|
6fb0eefbc0 | ||
|
4f71c21471 |
@@ -1,7 +1,6 @@
|
||||
FROM ubuntu:20.04
|
||||
FROM python:slim
|
||||
WORKDIR /
|
||||
RUN apt-get -y update
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
|
||||
RUN apt-get install -y python3 python3-dev git python3-pip python3-kivy python-is-python3 libgl1-mesa-dev build-essential
|
||||
RUN ln -s $(which pip3) /usr/bin/pip
|
||||
RUN pip install pymongo pandas numpy scipy scikit-learn matplotlib pylint kivy
|
||||
RUN apt-get -y update; apt-get -y upgrade
|
||||
RUN apt-get -y install git
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
@@ -1,2 +0,0 @@
|
||||
FROM titanscout2022/tra-analysis-base:latest
|
||||
WORKDIR /
|
@@ -1,28 +1,22 @@
|
||||
{
|
||||
"name": "TRA Analysis Development Environment",
|
||||
"build": {
|
||||
"dockerfile": "dev-dockerfile",
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/bash",
|
||||
"python.pythonPath": "/usr/local/bin/python",
|
||||
"python.pythonPath": "",
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
|
||||
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
|
||||
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
|
||||
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
|
||||
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
|
||||
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
|
||||
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
|
||||
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
|
||||
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
|
||||
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
|
||||
"python.linting.pylintPath": "",
|
||||
"python.testing.pytestPath": "",
|
||||
"editor.tabSize": 4,
|
||||
"editor.insertSpaces": false
|
||||
},
|
||||
"extensions": [
|
||||
"mhutchie.git-graph",
|
||||
"ms-python.python",
|
||||
"waderyan.gitblame"
|
||||
],
|
||||
"postCreateCommand": "/usr/bin/pip3 install -r ${containerWorkspaceFolder}/analysis-master/requirements.txt && /usr/bin/pip3 install --no-cache-dir pylint && /usr/bin/pip3 install pytest"
|
||||
"postCreateCommand": ""
|
||||
}
|
@@ -2,4 +2,7 @@ numpy
|
||||
scipy
|
||||
scikit-learn
|
||||
six
|
||||
pyparsing
|
||||
pyparsing
|
||||
|
||||
pylint
|
||||
pytest
|
@@ -9,6 +9,7 @@ from tra_analysis import Clustering
|
||||
from tra_analysis import CorrelationTest
|
||||
from tra_analysis import Fit
|
||||
from tra_analysis import KNN
|
||||
from tra_analysis import metrics as m
|
||||
from tra_analysis import NaiveBayes
|
||||
from tra_analysis import RandomForest
|
||||
from tra_analysis import RegressionMetric
|
||||
@@ -27,7 +28,7 @@ x_data_circular = []
|
||||
y_data_circular = []
|
||||
|
||||
y_data_ccu = [1, 3, 7, 14, 21]
|
||||
y_data_ccd = [1, 5, 7, 8.5, 8.66]
|
||||
y_data_ccd = [8.66, 8.5, 7, 5, 1]
|
||||
|
||||
test_data_scrambled = [-32, 34, 19, 72, -65, -11, -43, 6, 85, -17, -98, -26, 12, 20, 9, -92, -40, 98, -78, 17, -20, 49, 93, -27, -24, -66, 40, 84, 1, -64, -68, -25, -42, -46, -76, 43, -3, 30, -14, -34, -55, -13, 41, -30, 0, -61, 48, 23, 60, 87, 80, 77, 53, 73, 79, 24, -52, 82, 8, -44, 65, 47, -77, 94, 7, 37, -79, 36, -94, 91, 59, 10, 97, -38, -67, 83, 54, 31, -95, -63, 16, -45, 21, -12, 66, -48, -18, -96, -90, -21, -83, -74, 39, 64, 69, -97, 13, 55, 27, -39]
|
||||
test_data_sorted = [-98, -97, -96, -95, -94, -92, -90, -83, -79, -78, -77, -76, -74, -68, -67, -66, -65, -64, -63, -61, -55, -52, -48, -46, -45, -44, -43, -42, -40, -39, -38, -34, -32, -30, -27, -26, -25, -24, -21, -20, -18, -17, -14, -13, -12, -11, -3, 0, 1, 6, 7, 8, 9, 10, 12, 13, 16, 17, 19, 20, 21, 23, 24, 27, 30, 31, 34, 36, 37, 39, 40, 41, 43, 47, 48, 49, 53, 54, 55, 59, 60, 64, 65, 66, 69, 72, 73, 77, 79, 80, 82, 83, 84, 85, 87, 91, 93, 94, 97, 98]
|
||||
@@ -48,16 +49,25 @@ def test_basicstats():
|
||||
def test_regression():
|
||||
|
||||
assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccu, ["lin"])) == True
|
||||
#assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccd, ["log"])) == True
|
||||
#assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccu, ["exp"])) == True
|
||||
#assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccu, ["ply"])) == True
|
||||
#assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccd, ["sig"])) == True
|
||||
assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccd, ["log"])) == True
|
||||
assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccu, ["exp"])) == True
|
||||
assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccu, ["ply"])) == True
|
||||
assert all(isinstance(item, str) for item in an.regression(test_data_linear, y_data_ccd, ["sig"])) == True
|
||||
|
||||
def test_metrics():
|
||||
|
||||
assert an.Metric().elo(1500, 1500, [1, 0], 400, 24) == 1512.0
|
||||
assert an.Metric().glicko2(1500, 250, 0.06, [1500, 1400], [250, 240], [1, 0]) == (1478.864307445517, 195.99122679202452, 0.05999602937563585)
|
||||
#assert an.Metric().trueskill([[(25, 8.33), (24, 8.25), (32, 7.5)], [(25, 8.33), (25, 8.33), (21, 6.5)]], [1, 0]) == [(metrics.trueskill.Rating(mu=21.346, sigma=7.875), metrics.trueskill.Rating(mu=20.415, sigma=7.808), metrics.trueskill.Rating(mu=29.037, sigma=7.170)), (metrics.trueskill.Rating(mu=28.654, sigma=7.875), metrics.trueskill.Rating(mu=28.654, sigma=7.875), metrics.trueskill.Rating(mu=23.225, sigma=6.287))]
|
||||
e = [[(21.346, 7.875), (20.415, 7.808), (29.037, 7.170)], [(28.654, 7.875), (28.654, 7.875), (23.225, 6.287)]]
|
||||
r = an.Metric().trueskill([[(25, 8.33), (24, 8.25), (32, 7.5)], [(25, 8.33), (25, 8.33), (21, 6.5)]], [1, 0])
|
||||
i = 0
|
||||
for group in r:
|
||||
j = 0
|
||||
for team in group:
|
||||
assert abs(team.mu - e[i][j][0]) < 0.001
|
||||
assert abs(team.sigma - e[i][j][1]) < 0.001
|
||||
j+=1
|
||||
i+=1
|
||||
|
||||
def test_array():
|
||||
|
||||
|
@@ -380,7 +380,7 @@ from tra_analysis.metrics import elo as Elo
|
||||
from tra_analysis.metrics import glicko2 as Glicko2
|
||||
import numpy as np
|
||||
import scipy
|
||||
import sklearn, sklearn.cluster
|
||||
import sklearn, sklearn.cluster, sklearn.pipeline
|
||||
from tra_analysis.metrics import trueskill as Trueskill
|
||||
|
||||
# import submodules
|
||||
|
@@ -4,9 +4,12 @@
|
||||
# this should be imported as a python module using 'from tra_analysis import RandomForest'
|
||||
# setup:
|
||||
|
||||
__version__ = "1.0.2"
|
||||
__version__ = "1.0.3"
|
||||
|
||||
__changelog__ = """changelog:
|
||||
1.0.3:
|
||||
- updated RandomForestClassifier and RandomForestRegressor parameters to match sklearn v 1.0.2
|
||||
- changed default values for kwargs to rely on sklearn
|
||||
1.0.2:
|
||||
- optimized imports
|
||||
1.0.1:
|
||||
@@ -28,19 +31,19 @@ __all__ = [
|
||||
import sklearn, sklearn.ensemble, sklearn.naive_bayes
|
||||
from . import ClassificationMetric, RegressionMetric
|
||||
|
||||
def random_forest_classifier(data, labels, test_size, n_estimators, criterion="gini", max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features="auto", max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, class_weight=None):
|
||||
def random_forest_classifier(data, labels, test_size, n_estimators, **kwargs):
|
||||
|
||||
data_train, data_test, labels_train, labels_test = sklearn.model_selection.train_test_split(data, labels, test_size=test_size, random_state=1)
|
||||
kernel = sklearn.ensemble.RandomForestClassifier(n_estimators = n_estimators, criterion = criterion, max_depth = max_depth, min_samples_split = min_samples_split, min_samples_leaf = min_samples_leaf, min_weight_fraction_leaf = min_weight_fraction_leaf, max_leaf_nodes = max_leaf_nodes, min_impurity_decrease = min_impurity_decrease, bootstrap = bootstrap, oob_score = oob_score, n_jobs = n_jobs, random_state = random_state, verbose = verbose, warm_start = warm_start, class_weight = class_weight)
|
||||
kernel = sklearn.ensemble.RandomForestClassifier(n_estimators = n_estimators, **kwargs)
|
||||
kernel.fit(data_train, labels_train)
|
||||
predictions = kernel.predict(data_test)
|
||||
|
||||
return kernel, ClassificationMetric(predictions, labels_test)
|
||||
|
||||
def random_forest_regressor(data, outputs, test_size, n_estimators, criterion="mse", max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features="auto", max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False):
|
||||
def random_forest_regressor(data, outputs, test_size, n_estimators, **kwargs):
|
||||
|
||||
data_train, data_test, outputs_train, outputs_test = sklearn.model_selection.train_test_split(data, outputs, test_size=test_size, random_state=1)
|
||||
kernel = sklearn.ensemble.RandomForestRegressor(n_estimators = n_estimators, criterion = criterion, max_depth = max_depth, min_samples_split = min_samples_split, min_weight_fraction_leaf = min_weight_fraction_leaf, max_features = max_features, max_leaf_nodes = max_leaf_nodes, min_impurity_decrease = min_impurity_decrease, min_impurity_split = min_impurity_split, bootstrap = bootstrap, oob_score = oob_score, n_jobs = n_jobs, random_state = random_state, verbose = verbose, warm_start = warm_start)
|
||||
kernel = sklearn.ensemble.RandomForestRegressor(n_estimators = n_estimators, **kwargs)
|
||||
kernel.fit(data_train, outputs_train)
|
||||
predictions = kernel.predict(data_test)
|
||||
|
||||
|
@@ -0,0 +1,24 @@
|
||||
# Titan Robotics Team 2022: Metrics submodule
|
||||
# Written by Arthur Lu
|
||||
# Notes:
|
||||
# this should be imported as a python module using 'from tra_analysis import metrics'
|
||||
# setup:
|
||||
|
||||
__version__ = "1.0.0"
|
||||
|
||||
__changelog__ = """changelog:
|
||||
1.0.0:
|
||||
- implemented elo, glicko2, trueskill
|
||||
"""
|
||||
|
||||
__author__ = (
|
||||
"Arthur Lu <learthurgo@gmail.com>",
|
||||
)
|
||||
|
||||
__all__ = {
|
||||
"Expression"
|
||||
}
|
||||
|
||||
from . import elo
|
||||
from . import glicko2
|
||||
from . import trueskill
|
Reference in New Issue
Block a user