Skip to content

Commit

Permalink
Merge pull request #1214 from tilburgsciencehub/fix/links-code
Browse files Browse the repository at this point in the history
Fix broken links and add codeblock tags
  • Loading branch information
lachlandeer authored Jun 22, 2024
2 parents 283e88c + e2930d5 commit 3eed1fb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ In this section, we load the MNIST dataset and preprocess it for training and te

We begin by importing necessary libraries for data manipulation and preprocessing. Then, we load the MNIST dataset using Keras' built-in function `mnist.load_data()`. The dataset consists of 60,000 training images and 10,000 test images, each with their corresponding labels. Next, we preprocess the data by reshaping the input images and normalizing pixel values to a range between 0 and 1. Additionally, we convert the class labels to categorical format using one-hot encoding.

{{% codeblock %}}
```python
import numpy as np
from keras.datasets import mnist
Expand All @@ -169,14 +170,17 @@ X_train = X_train.reshape((X_train.shape[0], -1)).astype('float32') / 255
X_test = X_test.reshape((X_test.shape[0], -1)).astype('float32') / 255
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

```
{{% /codeblock %}}


### Building the model
In this section, we construct the neural network model using Keras' Sequential API.

We create a Sequential model, which allows us to build a linear stack of layers. The model consists of dense (fully connected) layers, which are interconnected neurons. Each dense layer performs a linear operation on the input data followed by a non-linear activation function. In our model, we use ReLU (Rectified Linear Activation) as the activation function for hidden layers and softmax for the output layer. The `units` parameter specifies the number of neurons in each layer, and `input_shape` defines the shape of the input data for the first layer.

```
{{% codeblock %}}
```python
from keras.models import Sequential
from keras.layers import Dense

Expand All @@ -188,13 +192,16 @@ model.add(Dense(units=64, activation='relu', input_shape=(X_train.shape[1],)))
model.add(Dense(units=64, activation='relu'))
model.add(Dense(units=10, activation='softmax'))
```
{{% /codeblock %}}


### Compiling, fitting and evaluating the model
In this section, we compile the model with an optimizer, loss function, and evaluation metric, train the model on the training data, and evaluate its performance on the test data.

After building the model, we compile it using the `compile()` method. Here, we specify the optimizer (Adam), loss function (categorical cross-entropy), and evaluation metric (accuracy). Then, we train the model on the training data using the `fit()` method, specifying the number of epochs (iterations over the entire dataset) and batch size (number of samples per gradient update). Finally, we evaluate the trained model on the test data to measure its performance in terms of loss and accuracy.

```
{{% codeblock %}}
```python
# Compiling the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

Expand All @@ -207,6 +214,7 @@ print("Test Loss:", loss)
print("Test Accuracy:", accuracy)

```
{{% /codeblock %}}

{{% summary %}}
### What is Deep Learning?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ aliases:
**`Packrat` is now soft-deprecated**

It is still maintained, but there will be no new development for it. An updated alternative would be `renv`.
Do you want to learn about it? Visit [this building block](https://tilburgsciencehub.com/topics/automate-and-execute-your-work/reproducible-work/renv/)!
Do you want to learn about it? Visit [this topic](/use/renv)!
{{% /warning %}}

## Overview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ The R community offers multiple tools to manage dependencies and reproducibility

### Packrat

[Packrat](https://tilburgsciencehub.com/topics/automate-and-execute-your-work/reproducible-work/packrat/) is an earlier solution for managing project-specific R libraries. It helps isolate projects and make them more reproducible by ensuring that each project's library is separate.
[Packrat](/reproduce/packrat) is an earlier solution for managing project-specific R libraries. It helps isolate projects and make them more reproducible by ensuring that each project's library is separate.

Nonetheless, while `packrat` was widely used, it has some limitations which `renv` has aimed to address. Furthermore, while it is still maintained, there will be no new development for it. This presents `renv` as a better alternative.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ In general, we follow [Google's R Style Guide](https://google.github.io/stylegui
* Do not use dots
* Underscores or camel-case are fine.

* See [our conventions for line length](https://tilburgsciencehub.com/topics/develop-your-research-skills/tips/principles-good-coding/)
* See [our conventions for line length](/write/good-code)

* We do not require that all functions have a comment block describing their uses. We encourage to do so when the purpose of a function would not be clear or whenever the function will be used outside of the file in which it is defined.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ Whether you’re looking to start coding for a new career or just as a hobby, pi

## Learn to code

As a first step, [learn how to set up R and RStudio on your local machine](https://tilburgsciencehub.com/topics/configure-your-computer/statistics-and-computation/r/). Next, we have compiled a [comprehensive guide](https://tilburgsciencehub.com/topics/configure-your-computer/statistics-and-computation/r/) with links to useful sources to help you structure your coding learning journey for, it can be daunting to figure out the right resources among tons out there!
As a first step, [learn how to set up R and RStudio on your local machine](/install/r). Next, we have compiled a [comprehensive guide](/learn/r) with links to useful sources to help you structure your coding learning journey for, it can be daunting to figure out the right resources among tons out there!

Furthermore, to polish your coding skills we have put together a succinct coding style [guideline](https://tilburgsciencehub.com/topics/configure-your-computer/statistics-and-computation/r/) to follow.
Furthermore, to polish your coding skills we have put together a succinct coding style [guideline](/write/good-code/r) to follow.


## More on R Packages

Packages are a set of R functions, data and compiled code bundled together and these are stored in a ‘library’. While R comes with a standard set of packages, one may install additional ones whenever required. As your project grows, the variety of packages used also broadens and it's easy to lose track of them. Here’s a brief [code snippet](https://tilburgsciencehub.com/topics/automate-and-execute-your-work/automate-your-workflow/auto-install-r-packages/) to automatically install packages that may not yet be installed on your machine.
Packages are a set of R functions, data and compiled code bundled together and these are stored in a ‘library’. While R comes with a standard set of packages, one may install additional ones whenever required. As your project grows, the variety of packages used also broadens and it's easy to lose track of them. Here’s a brief [code snippet](/install/r-packages) to automatically install packages that may not yet be installed on your machine.

In a similar vein, Packrat is an excellent tool to manage your R package library. It is the go-to solution to potential dependency issues between packages when working on multiple projects or when working on the same project using different machines which may have different versions of the packages installed. This helps make R packages isolated, portable and reproducible.

Check out our comprehensive guide to get you started with [Packrat](https://tilburgsciencehub.com/topics/automate-and-execute-your-work/reproducible-work/packrat/)
Check out our comprehensive guide to get you started with [Packrat](/reproduce/packrat)


## Analysis with R: Examples

Got a hang of the R syntax and are looking to put your R coding skills to practice with some empirical project? Here are some starter guides and codes of commonly used techniques for descriptive and causal analysis.

- [Run a regression analysis](https://tilburgsciencehub.com/topics/analyze-data/regressions/regression-analysis/)
- [Impact evaluation with DID and RD](https://tilburgsciencehub.com/topics/analyze-data/regressions/impact-evaluation/)
- [Synthetic control analysis](https://tilburgsciencehub.com/topics/analyze-data/regressions/synth-control/)
- [Run a regression analysis](/analyze/regression/)
- [Impact evaluation with DID and RD](/impact/evaluation)
- [Synthetic control analysis](/impact/syntCont)


## Communicate your insights with R
Expand All @@ -62,5 +62,5 @@ One of the most important and challenging job of a researcher is communicating o

Wanna try them out for yourself? Here are some useful resources to help you get started.

- [Build Interactive dashboards with R shiny](https://tilburgsciencehub.com/topics/collaborate-and-share-your-work/publish-on-the-web/shiny-apps/)
- [Publish e-books and interactive articles directly from R](https://tilburgsciencehub.com/topics/collaborate-and-share-your-work/publish-on-the-web/using-r/)
- [Build Interactive dashboards with R shiny](/Shiny/App)
- [Publish e-books and interactive articles directly from R](/make/ebooks)

0 comments on commit 3eed1fb

Please sign in to comment.