Compare commits

..

No commits in common. "a4dd8835537e36d9d865cf487fdfd40c8650d04e" and "cec08a0061b2992f2dd6acb4a26cad5e6cda140f" have entirely different histories.

9 changed files with 10 additions and 288 deletions

View file

@ -147,9 +147,6 @@ matches:
- trigger: ;frac
force_clipboard: true
replace: \frac{}{}
- trigger: ;perp
force_clipboard: true
replace: \perp\!\!\!\perp
- trigger: ;int
force_clipboard: true
replace: \int{f(x)\, dx}
@ -332,10 +329,6 @@ matches:
- trigger: ;zwiki
force_clipboard: true
replace: https://pzwiki.net/wiki/Project_Zomboid_Wiki
# Routes to Vintage Story Wiki
- trigger: ;vswiki
force_clipboard: true
replace: https://wiki.vintagestory.at/
# Prepares about pages for firefox
- trigger: ;conf
force_clipboard: true

View file

@ -51,6 +51,10 @@ return {
update_cwd = false,
ignore_list = {},
},
system_open = {
cmd = nil,
args = {},
},
diagnostics = {
enable = false,
show_on_dirs = false,

View file

@ -37,7 +37,6 @@ alias Code="cd ~/Documents/Code && ls"
alias graphics="cd ~/Documents/Graphic_Design && ls"
alias Math="cd ~/Documents/Math && ls"
alias sophia="cd ~/Documents/sophia && ls"
alias study="cd ~/Documents/study && ls"
alias cplus="cd ~/Documents/Code/cpp && ls"
alias js="cd ~/Documents/Code/javascript && ls"
alias py="cd ~/Documents/Code/python && ls"
@ -274,10 +273,8 @@ alias sudoku="sku"
# alias rbd="checkrebuild -v"
# pip list and pip freeze command list pip packages
# poetry virtual env
alias svenv="python -m venv .venv"
alias venv='source ".venv/bin/activate"'
alias {uvenv,dvenv}="deactivate"
alias pip="python -m pip"
#Particularly useful commands more to remember than to use as aliases:
# alias optimalbufsize= 'stat -c "%o"' # followed by filename will give you the optimal read/write BUFSIZE for a file
@ -344,7 +341,6 @@ alias vgrind="valgrind --leak-check=full --show-leak-kinds=all --track-origins=y
# alias {twd,thewalkingdead}="steam steam://rungameid/1449690 &"
# alias {cbmods,cybermods}="cd ~/.local/share/Steam/steamapps/common/Cyberpunk\ 2077/archive/pc/mod && ls"
alias vintagestory="flatpak run at.vintagestory.VintageStory"
alias vsmods="cd ~/.var/app/at.vintagestory.VintageStory/config/VintagestoryData/Mods/ && ls"
# docker specific Aliases
alias docker-ls="docker container ls -a && docker images"

View file

@ -1,8 +1,6 @@
.env*
.gitignore
.prettierrc
.prettierignore
.editorconfig
node_modules
*.vim
.venv/
.ipynb_checkpoints/
node_modules

View file

@ -1,81 +0,0 @@
# Linear Regression
In linear regression, given features and labels (X, Y), where Y is real-valued,
we try to learn a function f(x) to predict Y given x. Figure 2 outlines this
function:
$$ \hat{y} = w_0 + w_1x_1 + w_2x_2 + \dots + w_mx_m = \mathbf{w}^T\mathbf{X} $$
_Figure 2: Learning Function_
where $\mathbf{X} = x_1\text{, } \dots \text{, } x_m$ are the feature values and
$\mathbf{w} = w_0 \text{, } \dots \text{, } w_n$ can be seen as weights.
The weights determine how the corresponding feature affects the predicted value.
Thus, our task is to find the appropriate values of **w**.
**Cost function:** The cost function helps us to figure out the best possible
values for **w**. For the cost function, we use the Mean Squared Error (MSE),
Figure 3.
$$ MSE(\mathbf{w}) = \frac{1}{m}\sum_{i=1}^{m}{\left(\hat{y_i} - y_i\right)^2} $$
_Figure 3: MSE_
Using this MSE function we are going to update the values of w, such that the
MSE value settles at the minimum. The method of updating w to minimize the cost
function (MSE) is called gradient descent. We initialize the values of w and
then update these values iteratively to minimize the cost. Sometimes the cost
function can be a non-convex function where you can settle at a local minimum,
but for linear regression, it is always a convex function. To update w, we take
gradients from the cost function. To find these gradients, we take partial
derivatives with respect to w. Figure 4 outlines this 'update rule'.
- Initialize $w_i$
- Repeat until convergence
$\{w_i := w_i - \alpha \times \frac{\partial MSE(\mathbf{w})}{\partial w_i}\}$
Parameter $\alpha$ is called learning rate.
_Figure 4: Update Rule_
Code: In order to perform linear regression, we are going to use a Python module
called scikit learn. In the following example, we will use the California
Housing Data Set. The data set contains information about the housing values in
the suburbs of Boston.
There are 14 attributes for each **X**. Examples of these attributes include:
- MedInc per capita crime rate by town
- HouseAge Average age of a house in years
- AveRooms Average Rooms in a home
- Population City population
The target value **Y** is:
- MedHouseVal - Median value of owner-occupied homes in $1000's
Next, we split the data into training and testing sets. We train the model with
80% of the samples and test with the remaining 20%. Finally, we will evaluate
our model using MSE.
```py
import sklearn
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
X = housing ['data']
Y = housing ['target']
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=5)
lr = LinearRegression()
lr.fit(X_train, Y_train)
Y_pred = lr.predict(X_test)
mse = sklearn.metrics.mean_squared_error(Y_test, Y_pred)
print('Mean squared error for test set:', mse)
```

View file

@ -1,103 +0,0 @@
# Classification
Logistic regression is used in classification problems. For example, an email
can be classified as belonging to one of two classes: 'spam' and 'not spam'.
Given features and labels (**x**, **Y**), where **Y** can take only discrete
values (we can also say that the target variable is categorical), we try to
learn a function f(x) to predict Y given x. Figure 5 outlines this function.
$$ \hat{y} = w_0 + w_1x_1 + w_2x_2 + \dots + w_mx_m = \mathbf{w}^T\mathbf{X} $$
where $\mathbf{X} = x_1 \text{, } \dots \text{, } x_m$ are the feature values
and $\mathbf{w} = w_0 \text{, } \dots \text{, } w_n$ can be seen as weights.
_Figure 5: Learning Function_
As in linear regression, the weights determine how the corresponding feature
affects the predicted value, thus our task is to find the appropriate values of
**w**.
In this binary classification problem, the predicted function must return binary
values (either 0 or 1). To achieve this, we apply to our function the sigmoid or
logistic function (Figure 6). The sigmoid function has the domain of all real
numbers, with a return value from 0 to 1. Unlike linear regression, using the
sigmoid function we transform the output into a probability.
$$ \text{Sigmoid function: } \sigma(x) = \frac{1}{1 + \mathbf{e}^{-x}} $$
$$ \text{Sigmoid applied to learning function: } \sigma(\hat{y}) = \sigma\left(\mathbf{w}^T\mathbf{X}\right) = \frac{1}{1 + \mathbf{e}^{-\mathbf{w}^T\mathbf{X}}} $$
$$ \text{Probability for } \mathbf{X} \text{ to belong in the positive class: } Pr\left(c_{+}\mid X\right) = \frac{1}{1 + \mathbf{e}^{-\mathbf{w}^T\mathbf{X}}} $$
$$ \text{Probability for } \mathbf{X} \text{ to belong in the negative class: } Pr\left(c_{-}\mid X\right) = 1 - Pr\left(c_{+}\mid X\right) $$
_Figure 6: Sigmoid Function_
**Cost function**: Figure 7 outlines the cost function that is used in logistic
regression (Maximum Likelihood).
$$ J(\mathbf{w}) = \frac{1}{m}\sum_{i=1}^{m}{-\left[y_i\log \hat{y} + \left(1 - y_i\right)\left(1 - \hat{y}\right)\right]} $$
_Figure 7: Cost Function in Logistic Regression_
Using this cost function, we are going to update the values of **w**, such that
the J(w) value settles at the minimum. To obtain the values of **w**, we perform
the gradient descent algorithm. Figure 8 outlines the update rule of **w** in
logistic regression.
- Initialize $w_i$
- Repeat until convergence
$\{w_i := w_i - \alpha \cdot \frac{\partial MSE(\mathbf{w})}{\partial w_i}\}$
Parameter $\alpha$ is called learning rate.
_Figure 8: Update Rule_
**Code:i** To perform logistic regression we again use the scikit learn module.
In the following example, we will use the Breast Cancer Wisconsin (Diagnostic)
Data Set. There are 10 attributes for every **X** including:
- radius (mean of distances from the center to points on the perimeter)
- texture (standard deviation of gray-scale values)
- perimeter
- area
- smoothness (local variation in radius lengths)
The **Y** classes are:
- WDBC-Malignant
- WDBC-Benign
Next, we split the data into training and testing sets. We train the model with
80% of the samples and test with the remaining 20%. Finally, we will evaluate
our model using precision and recall metrics. The precision is the intuitive
ability of the classifier not to label as positive a sample that is negative,
and recall is the ability of the classifier to find all the positive samples.
```py
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import recall_score
from sklearn.metrics import precision_score
data = load_breast_cancer()
X = data['data']
Y = data['target']
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=5)
clf = LogisticRegression()
clf.fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
print('Recall:', recall_score(Y_test, Y_pred))
print('Precision:', precision_score(Y_test, Y_pred))
```
The disadvantage of this algorithm is that for each iteration m gradients have
to be computed leading to m training examples. If the training set is very
large, the above algorithm is going to be memory inefficient and might crash if
the training set doesn't fit in the memory. The Stochastic Gradient Descent
algorithm may be helpful in this case as it takes a sample of the training set
to calculate the weights-parameters instead of the entire sample space for each
iteration. This makes training much faster.

View file

@ -1,84 +0,0 @@
### Setup
Considering that it's been a while since I've set up MySQL and Pip, I thought
I'd document some of the basics here again for my own sake:
**Setting Up Mysql**
I opted to setup mysql via docker instead of installing it on bare metal. Simply
use the contained `docker-compose.yml` file with
[docker-compose](https://github.com/docker/compose) to get a very basic mysql
instance up and running:
```sh
docker-compose up -d
```
Confirm it's running using `ps`:
```sh
docker ps
```
As long as it's up and running you can test it to be sure:
```sh
docker exec -it myjsql-basic mysql -u root -p
```
And put in the default root password from the `docker-compose.yml` file.
**Virtual Environments**
You'll want to install `pip` and also get a virtual environment running:
```sh
python -m venv .venv
```
```sh
source .venv/bin/activate
```
Once inside the virtual environment, upgrade the local `pip`:
```sh
python -m pip install --upgrade pip
```
And use that `pip` to install all the packages from `requirements.txt`:
```sh
python -m pip install -r requirements.txt
```
If you need to create a new `requirements.txt`, then just:
```sh
pip freeze > requirements.txt
```
**Confirming MySQL Statements Were Executed:**
From within the `docker exec`'ed mysql repl, for now just use `SHOW DATABASES`
to ensure it went through:
```
mysql> SHOW DATABASES;
```
You should see output like this:
```
+--------------------+
| Database |
+--------------------+
| employee_db |
| information_schema |
| myapp |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.001 sec)
```

View file

@ -26,8 +26,7 @@ cat <<EOM
anim id est laborum.</p>
</article>
</main>
<script src="./index.js" defer></script>
</body>
<script src="./index.js" default defer></script>
</html>
EOM
EOM

View file

@ -75,11 +75,11 @@
## Study.com Courses with OR
- [Network and System Security: SDCM-0200](https://study.com/academy/course/computer-science-202-network-and-system-security.html)
TAKE THIS ONE OR
OR
- [Introduction to Cybersecurity: SDCM-0215](https://study.com/academy/course/computer-science-110-introduction-to-cybersecurity.html)
- [Database Programming: SDCM-0218](https://study.com/academy/course/computer-science-204-database-programming.html)
TAKE THIS ONE OR
OR
- [Database Management: SDCM-0164](https://study.com/academy/course/computer-science-303-database-management.html)
## Sophia.org Documents