Working on RL project

This commit is contained in:
2026-03-07 08:28:10 +01:00
parent acd403a14e
commit b331cdd716
12 changed files with 567 additions and 2466 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

154
M2/Time Series/TD4.qmd Normal file
View File

@@ -0,0 +1,154 @@
# Exercise 1 :
```{r}
set.seed(123)
n <- 100
t <- 1:n
eps <- rnorm(n, mean = 0, sd = 1)
X <- eps
Y <- 3 * t + 2 + 15 * eps
Z <- 3 * t + 2 + 15 * eps + 55 * sin(t * pi / 6)
par(mfrow = c(3, 1))
plot(ts(X), main = "Série X_t : Bruit blanc", ylab = "X_t", col = "blue")
plot(ts(Y), main = "Série Y_t : Tendance + bruit", ylab = "Y_t", col = "red")
plot(
ts(Z),
main = "Série Z_t : Tendance + saisonnalité + bruit",
ylab = "Z_t",
col = "darkgreen"
)
```
```{r}
library(forecast)
alpha_vals <- c(0.1, 0.3, 0.5, 0.7, 0.9)
mse_simple <- function(series) {
mse <- c()
for (a in alpha_vals) {
fit <- ses(series, alpha = a, initial = "simple", h = 1)
fitted_vals <- fitted(fit)
mse <- c(mse, mean((series - fitted_vals)^2, na.rm = TRUE))
}
data.frame(alpha = alpha_vals, MSE = mse)
}
mse_simple(X)
mse_simple(Y)
mse_simple(Z)
```
```{r}
holt_mse <- function(series) {
beta_vals <- seq(0.1, 0.9, 0.2)
alpha_vals <- seq(0.1, 0.9, 0.2)
res <- expand.grid(alpha = alpha_vals, beta = beta_vals)
res$MSE <- NA_real_
for (i in seq_len(nrow(res))) {
fit <- tryCatch(
suppressWarnings(forecast::holt(
series,
alpha = res$alpha[i],
beta = res$beta[i],
h = 1
)),
error = function(e) NULL
)
if (!is.null(fit)) {
fitted_vals <- stats::fitted(fit)
res$MSE[i] <- mean((series - fitted_vals)^2, na.rm = TRUE)
} else {
res$MSE[i] <- NA_real_
}
}
res[order(res$MSE, na.last = TRUE), , drop = FALSE][1:5, ]
}
holt_mse(X)
holt_mse(Y)
holt_mse(Z)
```
```{r}
fit_X <- ses(X)
fit_Y <- ses(Y)
fit_Z <- ses(Z)
accuracy(fit_X)
accuracy(fit_Y)
accuracy(fit_Z)
```
```{r}
fit_X_holt <- holt(X)
fit_Y_holt <- holt(Y)
fit_Z_holt <- holt(Z)
accuracy(fit_X_holt)
accuracy(fit_Y_holt)
accuracy(fit_Z_holt)
```
# Exercise 2
```{r}
library(tseries)
library(forecast)
data("AirPassengers")
log_air <- log(AirPassengers)
n <- length(log_air)
n_test <- 12
train <- window(log_air, end = c(1959, 12))
test <- window(log_air, start = c(1960, 1))
plot(log_air, main = "Série AirPassengers (Log)")
lines(train, col = "blue")
lines(test, col = "red")
legend("topleft", legend = c("Train", "Test"), col = c("blue", "red"), lty = 1)
```
```{r}
library(forecast)
fit_simple <- ses(train, h = n_test)
fit_holt <- holt(train, h = n_test)
plot(log_air)
lines(fit_simple$mean, col = "green", lwd = 2)
lines(fit_holt$mean, col = "orange", lwd = 2)
legend(
"topleft",
legend = c("Série", "Simple", "Holt"),
col = c("black", "green", "orange"),
lty = 1
)
accuracy(fit_simple, test)
accuracy(fit_holt, test)
```
```{r}
fit_hw_add <- hw(train, h = n_test, seasonal = "additive")
fit_hw_mult <- hw(train, h = n_test, seasonal = "multiplicative")
plot(log_air)
lines(fit_hw_add$mean, col = "purple", lwd = 2)
lines(fit_hw_mult$mean, col = "darkgreen", lwd = 2)
legend("topleft", legend = c("Série", "HW Additif", "HW Multiplicatif"), col = c("black", "purple", "darkgreen"), lty = 1)
accuracy(fit_hw_add, test)
accuracy(fit_hw_mult, test)
```

View File

@@ -5,51 +5,27 @@ description = "A curated collection of mathematics and data science projects dev
readme = "README.md"
requires-python = ">= 3.12,<3.14"
dependencies = [
"accelerate>=1.12.0",
"ale-py>=0.11.2",
"catboost>=1.2.10",
"datasets>=4.6.1",
"faiss-cpu>=1.13.2",
"folium>=0.20.0",
"geopandas>=1.1.2",
"google-api-python-client>=2.191.0",
"google-auth-oauthlib>=1.3.0",
"google-generativeai>=0.8.6",
"gymnasium[toy-text]>=1.2.3",
"imblearn>=0.0",
"ipykernel>=7.2.0",
"ipywidgets>=8.1.8",
"langchain>=1.2.10",
"langchain-community>=0.4.1",
"langchain-core>=1.2.17",
"langchain-huggingface>=1.2.1",
"langchain-mistralai>=1.1.1",
"langchain-ollama>=1.0.1",
"langchain-openai>=1.1.10",
"langchain-text-splitters>=1.1.1",
"mapclassify>=2.10.0",
"matplotlib>=3.10.8",
"nbformat>=5.10.4",
"numpy>=2.4.2",
"opencv-python>=4.13.0.92",
"openpyxl>=3.1.5",
"pandas>=3.0.1",
"pandas-stubs>=3.0.0.260204",
"pettingzoo[atari]>=1.24.3",
"plotly>=6.6.0",
"polars>=1.38.1",
"pypdf>=6.7.5",
"rasterio>=1.5.0",
"requests>=2.32.5",
"scikit-learn>=1.8.0",
"scipy>=1.17.1",
"seaborn>=0.13.2",
"sentence-transformers>=5.2.3",
# "sequenzo>=0.1.20",
"shap>=0.50.0",
"spacy>=3.8.11",
"statsmodels>=0.14.6",
"supersuit>=3.10.0",
"tensorflow>=2.20.0",
"tf-keras>=2.20.1",
"tiktoken>=0.12.0",
@@ -57,9 +33,7 @@ dependencies = [
"torch>=2.10.0",
"umap-learn>=0.5.11",
"uv>=0.10.7",
"wbdata>=1.1.0",
"xgboost>=3.2.0",
"yfinance>=1.2.0",
]
[dependency-groups]

1864
uv.lock generated

File diff suppressed because it is too large Load Diff