POP77032 Quantitative Text Analysis for Social Scientists
Having considered the Boolean AND function in the lecture, let’s now look at the Boolean OR function.
The OR function is defined as follows: \[ \text{OR}(x_1, x_2) = \begin{cases} 1 & \text{if } x_1 = 1 \text{ or } x_2 = 1 \\ 0 & \text{if } x_1 = 0 \text{ and } x_2 = 0 \end{cases} \]
We will start by defining the complete dataset and applying a simple linear regression to it.
First, try implementing the OR function using a single-layer perceptron (SLP) using stochastic gradient descent (SGD) with the MSE loss function, as we did for the AND function in the lecture.
As we discussed in the lecture, the MSE loss function isn’t ideal for binary classification problems, so, as an alternative, we can try implementing it using the negative log-likelihood.
array([0.25, 0.75, 0.75, 1.25])
sklearn or statsmodels, we would get the following estimates for the weights and bias:Optimization terminated successfully.
Current function value: 0.317947
Iterations 8
| Dep. Variable: | y | No. Observations: | 1000 |
|---|---|---|---|
| Model: | Logit | Df Residuals: | 997 |
| Method: | MLE | Df Model: | 2 |
| Date: | Thu, 09 Apr 2026 | Pseudo R-squ.: | 0.5089 |
| Time: | 00:13:24 | Log-Likelihood: | -317.95 |
| converged: | True | LL-Null: | -647.45 |
| Covariance Type: | nonrobust | LLR p-value: | 7.942e-144 |
| coef | std err | z | P>|z| | [0.025 | 0.975] | |
|---|---|---|---|---|---|---|
| const | -1.4090 | 0.123 | -11.424 | 0.000 | -1.651 | -1.167 |
| x1 | 0.7463 | 0.108 | 6.890 | 0.000 | 0.534 | 0.959 |
| x2 | 3.1038 | 0.204 | 15.199 | 0.000 | 2.704 | 3.504 |