-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.qmd
More file actions
128 lines (95 loc) · 2.82 KB
/
README.qmd
File metadata and controls
128 lines (95 loc) · 2.82 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
format: gfm
execute:
echo: false
warning: false
---
```{r}
#| include: false
library(tidyverse)
library(glue)
extract_modules <- function(fl) {
if (length(fl) == 1) {
txt <- read.delim(fl, header = FALSE)[[1]]
mods <- str_extract_all(
string = txt,
pattern = "(?<=^(import|from)\\s)[a-zA-Z0-9_]{1,}"
)
mods <- unlist(mods)
dir_py_files <- dirname(fl) |>
list.files(pattern = "\\.py$", full.names = TRUE) |>
basename() |>
str_remove(pattern = "\\.py$")
mods <- setdiff(mods, dir_py_files)
} else if (length(fl) > 1) {
mods <- sapply(fl, extract_modules)
}
mods |>
unlist(recursive = TRUE) |>
unique()
}
```
# Machine Learning foR Psychologists
[](https://creativecommons.org/about/program-areas/education-oer/)
[](http://creativecommons.org/licenses/by-nc/4.0/)

<sub>*Last updated `r Sys.Date()`.*</sub>
This folder contains Python translations of the R tutorials in the main repo.
## Setup
You will need:
1. A fresh installation of [**Python**](https://www.python.org/downloads/) (preferably version 3.13 or above).
2. [Positron IDE](https://positron.posit.co/download.html) (optional, but recommended).
3. The following modules, listed by lesson:
```{r}
py_files <- list.files(pattern = ".py$", recursive = TRUE, full.names = TRUE)
py_files <- py_files[str_detect(py_files, "^\\./\\d{2}")]
py_lesson_names <- str_extract(py_files, pattern = "(?<=(/)).{1,}(?=(/))")
py_list <- split(py_files, py_lesson_names)
py_mdls <- lapply(py_list, extract_modules)
py_df <- tibble(
Lesson = names(py_mdls),
Modules = py_mdls
)
py_df |>
mutate(
Lesson = glue("[{Lesson}]({Lesson}//)"),
Modules = sapply(Modules, \(x) glue('`{x}`') |> glue_collapse(sep = ", ")),
) |>
knitr::kable()
```
<details>
<summary><i>Installing Python Modules</i></summary>
You can install all the Python modules used by saving a `requirements.txt` file:
```{r}
reticulate::use_python(
"C:/Users/user/AppData/Local/Programs/Python/Python313/python.exe",
required = TRUE
)
imp <- reticulate::import("importlib.metadata")
py_version <- possibly(imp$version, otherwise = "")
py_mdls <- py_mdls |>
unlist(recursive = TRUE) |>
unique() |>
sort()
py_mdl_info <- tibble(
module = case_match(
py_mdls,
"sklearn" ~ "scikit-learn",
"imblearn" ~ "imbalanced-learn",
.default = py_mdls
),
version = sapply(module, py_version)
) |>
arrange(module)
py_mdl_info |>
glue_data(
"{module}{ifelse(nzchar(py_mdl_info$version), '>=', '')}{version}"
) |>
glue_collapse(sep = "\n") |>
cat()
```
And then running
```
pip install -r requirements.txt
```
</details>