Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
62 lines (47 loc) · 1.92 KB
/
Copy pathutils.py
File metadata and controls
62 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from typing import Tuple
import numpy as np
import pandas as pd
def split_train_test(X: pd.DataFrame, y: pd.Series, train_proportion: float = .25) \
-> Tuple[pd.DataFrame, pd.Series, pd.DataFrame, pd.Series]:
"""
Split given sample to a training- and testing sample
Parameters
----------
X : DataFrame of shape (n_samples, n_features)
Data frame of samples and feature values.
y : Series of shape (n_samples, )
Responses corresponding samples in data frame.
train_proportion: Fraction of samples to be split as training set
Returns
-------
train_X : DataFrame of shape (ceil(train_proportion * n_samples), n_features)
Design matrix of train set
train_y : Series of shape (ceil(train_proportion * n_samples), )
Responses of training samples
test_X : DataFrame of shape (floor((1-train_proportion) * n_samples), n_features)
Design matrix of test set
test_y : Series of shape (floor((1-train_proportion) * n_samples), )
Responses of test samples
"""
split_ind = int(train_proportion * X.shape[0])
train_X = X[:split_ind]
test_X = X[split_ind + 1:]
train_y = y[:split_ind]
test_y = y[split_ind + 1:]
return train_X, train_y, test_X, test_y
def confusion_matrix(a: np.ndarray, b: np.ndarray) -> np.ndarray:
"""
Compute a confusion matrix between two sets of integer vectors
Parameters
----------
a: ndarray of shape (n_samples,)
First vector of integers
b: ndarray of shape (n_samples,)
Second vector of integers
Returns
-------
confusion_matrix: ndarray of shape (a_unique_values, b_unique_values)
A confusion matrix where the value of the i,j index shows the number of times value `i` was found in vector `a`
while value `j` vas found in vector `b`
"""
raise NotImplementedError()