This commit is contained in:
louiscklaw
2025-01-31 20:57:47 +08:00
parent ed177c5ad6
commit fc6f79b133
341 changed files with 201064 additions and 0 deletions

7
Man1130/gitUpdate.bat Normal file
View File

@@ -0,0 +1,7 @@
git status .
@pause
git add .
git commit -m"update Man1130,"
start git push

View File

@@ -0,0 +1,22 @@
**~*
**.cache
**.Trash*
# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks
# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks
### JupyterNotebooks ###
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/
.ipynb_checkpoints
*/.ipynb_checkpoints/*
# IPython
profile_default/
ipython_config.py
# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/
# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,555 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Supervised Learning\n",
"## KNN\n",
"> - KNN is a non-parametric learning algorithm (No assumption is made on the data) \n",
"> - KNN can be used for classification (discrte) and regression (continuous label) \n",
"> - All training data has to be present to determine the label of new data \n",
"> - Sensitive to irrelavant features \n",
"> - Sensitive to scale of data \n",
"### Issues:\n",
"> - Choose number of neighors *k* \n",
"> - Choose distance metric "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data\n",
"### Breast Cancer\n",
"> **Label**: Malignant or Benign \n",
"> **30 Features**: Radius, Texture, Perimeter, Area, Smoothness, etc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>mean radius</th>\n",
" <th>mean texture</th>\n",
" <th>mean perimeter</th>\n",
" <th>mean area</th>\n",
" <th>mean smoothness</th>\n",
" <th>mean compactness</th>\n",
" <th>mean concavity</th>\n",
" <th>mean concave points</th>\n",
" <th>mean symmetry</th>\n",
" <th>mean fractal dimension</th>\n",
" <th>...</th>\n",
" <th>worst radius</th>\n",
" <th>worst texture</th>\n",
" <th>worst perimeter</th>\n",
" <th>worst area</th>\n",
" <th>worst smoothness</th>\n",
" <th>worst compactness</th>\n",
" <th>worst concavity</th>\n",
" <th>worst concave points</th>\n",
" <th>worst symmetry</th>\n",
" <th>worst fractal dimension</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>17.99</td>\n",
" <td>10.38</td>\n",
" <td>122.80</td>\n",
" <td>1001.0</td>\n",
" <td>0.11840</td>\n",
" <td>0.27760</td>\n",
" <td>0.3001</td>\n",
" <td>0.14710</td>\n",
" <td>0.2419</td>\n",
" <td>0.07871</td>\n",
" <td>...</td>\n",
" <td>25.38</td>\n",
" <td>17.33</td>\n",
" <td>184.60</td>\n",
" <td>2019.0</td>\n",
" <td>0.1622</td>\n",
" <td>0.6656</td>\n",
" <td>0.7119</td>\n",
" <td>0.2654</td>\n",
" <td>0.4601</td>\n",
" <td>0.11890</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>20.57</td>\n",
" <td>17.77</td>\n",
" <td>132.90</td>\n",
" <td>1326.0</td>\n",
" <td>0.08474</td>\n",
" <td>0.07864</td>\n",
" <td>0.0869</td>\n",
" <td>0.07017</td>\n",
" <td>0.1812</td>\n",
" <td>0.05667</td>\n",
" <td>...</td>\n",
" <td>24.99</td>\n",
" <td>23.41</td>\n",
" <td>158.80</td>\n",
" <td>1956.0</td>\n",
" <td>0.1238</td>\n",
" <td>0.1866</td>\n",
" <td>0.2416</td>\n",
" <td>0.1860</td>\n",
" <td>0.2750</td>\n",
" <td>0.08902</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>19.69</td>\n",
" <td>21.25</td>\n",
" <td>130.00</td>\n",
" <td>1203.0</td>\n",
" <td>0.10960</td>\n",
" <td>0.15990</td>\n",
" <td>0.1974</td>\n",
" <td>0.12790</td>\n",
" <td>0.2069</td>\n",
" <td>0.05999</td>\n",
" <td>...</td>\n",
" <td>23.57</td>\n",
" <td>25.53</td>\n",
" <td>152.50</td>\n",
" <td>1709.0</td>\n",
" <td>0.1444</td>\n",
" <td>0.4245</td>\n",
" <td>0.4504</td>\n",
" <td>0.2430</td>\n",
" <td>0.3613</td>\n",
" <td>0.08758</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>11.42</td>\n",
" <td>20.38</td>\n",
" <td>77.58</td>\n",
" <td>386.1</td>\n",
" <td>0.14250</td>\n",
" <td>0.28390</td>\n",
" <td>0.2414</td>\n",
" <td>0.10520</td>\n",
" <td>0.2597</td>\n",
" <td>0.09744</td>\n",
" <td>...</td>\n",
" <td>14.91</td>\n",
" <td>26.50</td>\n",
" <td>98.87</td>\n",
" <td>567.7</td>\n",
" <td>0.2098</td>\n",
" <td>0.8663</td>\n",
" <td>0.6869</td>\n",
" <td>0.2575</td>\n",
" <td>0.6638</td>\n",
" <td>0.17300</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>20.29</td>\n",
" <td>14.34</td>\n",
" <td>135.10</td>\n",
" <td>1297.0</td>\n",
" <td>0.10030</td>\n",
" <td>0.13280</td>\n",
" <td>0.1980</td>\n",
" <td>0.10430</td>\n",
" <td>0.1809</td>\n",
" <td>0.05883</td>\n",
" <td>...</td>\n",
" <td>22.54</td>\n",
" <td>16.67</td>\n",
" <td>152.20</td>\n",
" <td>1575.0</td>\n",
" <td>0.1374</td>\n",
" <td>0.2050</td>\n",
" <td>0.4000</td>\n",
" <td>0.1625</td>\n",
" <td>0.2364</td>\n",
" <td>0.07678</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 30 columns</p>\n",
"</div>"
],
"text/plain": [
" mean radius mean texture mean perimeter mean area mean smoothness \\\n",
"0 17.99 10.38 122.80 1001.0 0.11840 \n",
"1 20.57 17.77 132.90 1326.0 0.08474 \n",
"2 19.69 21.25 130.00 1203.0 0.10960 \n",
"3 11.42 20.38 77.58 386.1 0.14250 \n",
"4 20.29 14.34 135.10 1297.0 0.10030 \n",
"\n",
" mean compactness mean concavity mean concave points mean symmetry \\\n",
"0 0.27760 0.3001 0.14710 0.2419 \n",
"1 0.07864 0.0869 0.07017 0.1812 \n",
"2 0.15990 0.1974 0.12790 0.2069 \n",
"3 0.28390 0.2414 0.10520 0.2597 \n",
"4 0.13280 0.1980 0.10430 0.1809 \n",
"\n",
" mean fractal dimension ... worst radius worst texture worst perimeter \\\n",
"0 0.07871 ... 25.38 17.33 184.60 \n",
"1 0.05667 ... 24.99 23.41 158.80 \n",
"2 0.05999 ... 23.57 25.53 152.50 \n",
"3 0.09744 ... 14.91 26.50 98.87 \n",
"4 0.05883 ... 22.54 16.67 152.20 \n",
"\n",
" worst area worst smoothness worst compactness worst concavity \\\n",
"0 2019.0 0.1622 0.6656 0.7119 \n",
"1 1956.0 0.1238 0.1866 0.2416 \n",
"2 1709.0 0.1444 0.4245 0.4504 \n",
"3 567.7 0.2098 0.8663 0.6869 \n",
"4 1575.0 0.1374 0.2050 0.4000 \n",
"\n",
" worst concave points worst symmetry worst fractal dimension \n",
"0 0.2654 0.4601 0.11890 \n",
"1 0.1860 0.2750 0.08902 \n",
"2 0.2430 0.3613 0.08758 \n",
"3 0.2575 0.6638 0.17300 \n",
"4 0.1625 0.2364 0.07678 \n",
"\n",
"[5 rows x 30 columns]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"from sklearn.datasets import load_breast_cancer\n",
"\n",
"breast_cancer = load_breast_cancer()\n",
"X = pd.DataFrame(breast_cancer.data, columns=breast_cancer.feature_names)\n",
"X.head()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Create an X with 2 features only\n",
"\n",
"X = X[['mean area', 'mean compactness']]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['malignant', 'benign'], dtype='<U9')"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"breast_cancer.target_names"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['malignant', 'malignant', 'malignant', 'malignant', 'malignant', ..., 'malignant', 'malignant', 'malignant', 'malignant', 'benign']\n",
"Length: 569\n",
"Categories (2, object): ['malignant', 'benign']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = pd.Categorical.from_codes(codes=breast_cancer.target, categories=breast_cancer.target_names)\n",
"y"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>benign</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" benign\n",
"0 0\n",
"1 0\n",
"2 0\n",
"3 0\n",
"4 0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = pd.get_dummies(y, drop_first=True) \n",
"y.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(426, 1)\n",
"(143, 1)\n",
"<class 'pandas.core.frame.DataFrame'>\n"
]
}
],
"source": [
"from sklearn.model_selection import train_test_split\n",
"\n",
"Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, random_state=1)\n",
"print(ytrain.shape)\n",
"print(ytest.shape)\n",
"print(type(ytest))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier\n",
"import numpy as np\n",
"\n",
"knn = KNeighborsClassifier(n_neighbors=5, metric='euclidean')\n",
"knn.fit(Xtrain, ytrain.to_numpy().ravel())\n",
"ypred = knn.predict(Xtest).reshape([143,1])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Prediction</th>\n",
" <th>Actual</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Prediction Actual\n",
"0 1 1\n",
"1 1 0\n",
"2 1 1\n",
"3 0 0\n",
"4 0 0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame(np.hstack([ypred,ytest]),columns=['Prediction','Actual']).head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[42 13]\n",
" [ 9 79]]\n"
]
}
],
"source": [
"from sklearn.metrics import confusion_matrix\n",
"print(confusion_matrix(ytest, ypred))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,151 @@
Id,SepalLengthCm,SepalWidthCm,PetalLengthCm,PetalWidthCm,Species
1,5.1,3.5,1.4,0.2,Iris-setosa
2,4.9,3.0,1.4,0.2,Iris-setosa
3,4.7,3.2,1.3,0.2,Iris-setosa
4,4.6,3.1,1.5,0.2,Iris-setosa
5,5.0,3.6,1.4,0.2,Iris-setosa
6,5.4,3.9,1.7,0.4,Iris-setosa
7,4.6,3.4,1.4,0.3,Iris-setosa
8,5.0,3.4,1.5,0.2,Iris-setosa
9,4.4,2.9,1.4,0.2,Iris-setosa
10,4.9,3.1,1.5,0.1,Iris-setosa
11,5.4,3.7,1.5,0.2,Iris-setosa
12,4.8,3.4,1.6,0.2,Iris-setosa
13,4.8,3.0,1.4,0.1,Iris-setosa
14,4.3,3.0,1.1,0.1,Iris-setosa
15,5.8,4.0,1.2,0.2,Iris-setosa
16,5.7,4.4,1.5,0.4,Iris-setosa
17,5.4,3.9,1.3,0.4,Iris-setosa
18,5.1,3.5,1.4,0.3,Iris-setosa
19,5.7,3.8,1.7,0.3,Iris-setosa
20,5.1,3.8,1.5,0.3,Iris-setosa
21,5.4,3.4,1.7,0.2,Iris-setosa
22,5.1,3.7,1.5,0.4,Iris-setosa
23,4.6,3.6,1.0,0.2,Iris-setosa
24,5.1,3.3,1.7,0.5,Iris-setosa
25,4.8,3.4,1.9,0.2,Iris-setosa
26,5.0,3.0,1.6,0.2,Iris-setosa
27,5.0,3.4,1.6,0.4,Iris-setosa
28,5.2,3.5,1.5,0.2,Iris-setosa
29,5.2,3.4,1.4,0.2,Iris-setosa
30,4.7,3.2,1.6,0.2,Iris-setosa
31,4.8,3.1,1.6,0.2,Iris-setosa
32,5.4,3.4,1.5,0.4,Iris-setosa
33,5.2,4.1,1.5,0.1,Iris-setosa
34,5.5,4.2,1.4,0.2,Iris-setosa
35,4.9,3.1,1.5,0.1,Iris-setosa
36,5.0,3.2,1.2,0.2,Iris-setosa
37,5.5,3.5,1.3,0.2,Iris-setosa
38,4.9,3.1,1.5,0.1,Iris-setosa
39,4.4,3.0,1.3,0.2,Iris-setosa
40,5.1,3.4,1.5,0.2,Iris-setosa
41,5.0,3.5,1.3,0.3,Iris-setosa
42,4.5,2.3,1.3,0.3,Iris-setosa
43,4.4,3.2,1.3,0.2,Iris-setosa
44,5.0,3.5,1.6,0.6,Iris-setosa
45,5.1,3.8,1.9,0.4,Iris-setosa
46,4.8,3.0,1.4,0.3,Iris-setosa
47,5.1,3.8,1.6,0.2,Iris-setosa
48,4.6,3.2,1.4,0.2,Iris-setosa
49,5.3,3.7,1.5,0.2,Iris-setosa
50,5.0,3.3,1.4,0.2,Iris-setosa
51,7.0,3.2,4.7,1.4,Iris-versicolor
52,6.4,3.2,4.5,1.5,Iris-versicolor
53,6.9,3.1,4.9,1.5,Iris-versicolor
54,5.5,2.3,4.0,1.3,Iris-versicolor
55,6.5,2.8,4.6,1.5,Iris-versicolor
56,5.7,2.8,4.5,1.3,Iris-versicolor
57,6.3,3.3,4.7,1.6,Iris-versicolor
58,4.9,2.4,3.3,1.0,Iris-versicolor
59,6.6,2.9,4.6,1.3,Iris-versicolor
60,5.2,2.7,3.9,1.4,Iris-versicolor
61,5.0,2.0,3.5,1.0,Iris-versicolor
62,5.9,3.0,4.2,1.5,Iris-versicolor
63,6.0,2.2,4.0,1.0,Iris-versicolor
64,6.1,2.9,4.7,1.4,Iris-versicolor
65,5.6,2.9,3.6,1.3,Iris-versicolor
66,6.7,3.1,4.4,1.4,Iris-versicolor
67,5.6,3.0,4.5,1.5,Iris-versicolor
68,5.8,2.7,4.1,1.0,Iris-versicolor
69,6.2,2.2,4.5,1.5,Iris-versicolor
70,5.6,2.5,3.9,1.1,Iris-versicolor
71,5.9,3.2,4.8,1.8,Iris-versicolor
72,6.1,2.8,4.0,1.3,Iris-versicolor
73,6.3,2.5,4.9,1.5,Iris-versicolor
74,6.1,2.8,4.7,1.2,Iris-versicolor
75,6.4,2.9,4.3,1.3,Iris-versicolor
76,6.6,3.0,4.4,1.4,Iris-versicolor
77,6.8,2.8,4.8,1.4,Iris-versicolor
78,6.7,3.0,5.0,1.7,Iris-versicolor
79,6.0,2.9,4.5,1.5,Iris-versicolor
80,5.7,2.6,3.5,1.0,Iris-versicolor
81,5.5,2.4,3.8,1.1,Iris-versicolor
82,5.5,2.4,3.7,1.0,Iris-versicolor
83,5.8,2.7,3.9,1.2,Iris-versicolor
84,6.0,2.7,5.1,1.6,Iris-versicolor
85,5.4,3.0,4.5,1.5,Iris-versicolor
86,6.0,3.4,4.5,1.6,Iris-versicolor
87,6.7,3.1,4.7,1.5,Iris-versicolor
88,6.3,2.3,4.4,1.3,Iris-versicolor
89,5.6,3.0,4.1,1.3,Iris-versicolor
90,5.5,2.5,4.0,1.3,Iris-versicolor
91,5.5,2.6,4.4,1.2,Iris-versicolor
92,6.1,3.0,4.6,1.4,Iris-versicolor
93,5.8,2.6,4.0,1.2,Iris-versicolor
94,5.0,2.3,3.3,1.0,Iris-versicolor
95,5.6,2.7,4.2,1.3,Iris-versicolor
96,5.7,3.0,4.2,1.2,Iris-versicolor
97,5.7,2.9,4.2,1.3,Iris-versicolor
98,6.2,2.9,4.3,1.3,Iris-versicolor
99,5.1,2.5,3.0,1.1,Iris-versicolor
100,5.7,2.8,4.1,1.3,Iris-versicolor
101,6.3,3.3,6.0,2.5,Iris-virginica
102,5.8,2.7,5.1,1.9,Iris-virginica
103,7.1,3.0,5.9,2.1,Iris-virginica
104,6.3,2.9,5.6,1.8,Iris-virginica
105,6.5,3.0,5.8,2.2,Iris-virginica
106,7.6,3.0,6.6,2.1,Iris-virginica
107,4.9,2.5,4.5,1.7,Iris-virginica
108,7.3,2.9,6.3,1.8,Iris-virginica
109,6.7,2.5,5.8,1.8,Iris-virginica
110,7.2,3.6,6.1,2.5,Iris-virginica
111,6.5,3.2,5.1,2.0,Iris-virginica
112,6.4,2.7,5.3,1.9,Iris-virginica
113,6.8,3.0,5.5,2.1,Iris-virginica
114,5.7,2.5,5.0,2.0,Iris-virginica
115,5.8,2.8,5.1,2.4,Iris-virginica
116,6.4,3.2,5.3,2.3,Iris-virginica
117,6.5,3.0,5.5,1.8,Iris-virginica
118,7.7,3.8,6.7,2.2,Iris-virginica
119,7.7,2.6,6.9,2.3,Iris-virginica
120,6.0,2.2,5.0,1.5,Iris-virginica
121,6.9,3.2,5.7,2.3,Iris-virginica
122,5.6,2.8,4.9,2.0,Iris-virginica
123,7.7,2.8,6.7,2.0,Iris-virginica
124,6.3,2.7,4.9,1.8,Iris-virginica
125,6.7,3.3,5.7,2.1,Iris-virginica
126,7.2,3.2,6.0,1.8,Iris-virginica
127,6.2,2.8,4.8,1.8,Iris-virginica
128,6.1,3.0,4.9,1.8,Iris-virginica
129,6.4,2.8,5.6,2.1,Iris-virginica
130,7.2,3.0,5.8,1.6,Iris-virginica
131,7.4,2.8,6.1,1.9,Iris-virginica
132,7.9,3.8,6.4,2.0,Iris-virginica
133,6.4,2.8,5.6,2.2,Iris-virginica
134,6.3,2.8,5.1,1.5,Iris-virginica
135,6.1,2.6,5.6,1.4,Iris-virginica
136,7.7,3.0,6.1,2.3,Iris-virginica
137,6.3,3.4,5.6,2.4,Iris-virginica
138,6.4,3.1,5.5,1.8,Iris-virginica
139,6.0,3.0,4.8,1.8,Iris-virginica
140,6.9,3.1,5.4,2.1,Iris-virginica
141,6.7,3.1,5.6,2.4,Iris-virginica
142,6.9,3.1,5.1,2.3,Iris-virginica
143,5.8,2.7,5.1,1.9,Iris-virginica
144,6.8,3.2,5.9,2.3,Iris-virginica
145,6.7,3.3,5.7,2.5,Iris-virginica
146,6.7,3.0,5.2,2.3,Iris-virginica
147,6.3,2.5,5.0,1.9,Iris-virginica
148,6.5,3.0,5.2,2.0,Iris-virginica
149,6.2,3.4,5.4,2.3,Iris-virginica
150,5.9,3.0,5.1,1.8,Iris-virginica
1 Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
2 1 5.1 3.5 1.4 0.2 Iris-setosa
3 2 4.9 3.0 1.4 0.2 Iris-setosa
4 3 4.7 3.2 1.3 0.2 Iris-setosa
5 4 4.6 3.1 1.5 0.2 Iris-setosa
6 5 5.0 3.6 1.4 0.2 Iris-setosa
7 6 5.4 3.9 1.7 0.4 Iris-setosa
8 7 4.6 3.4 1.4 0.3 Iris-setosa
9 8 5.0 3.4 1.5 0.2 Iris-setosa
10 9 4.4 2.9 1.4 0.2 Iris-setosa
11 10 4.9 3.1 1.5 0.1 Iris-setosa
12 11 5.4 3.7 1.5 0.2 Iris-setosa
13 12 4.8 3.4 1.6 0.2 Iris-setosa
14 13 4.8 3.0 1.4 0.1 Iris-setosa
15 14 4.3 3.0 1.1 0.1 Iris-setosa
16 15 5.8 4.0 1.2 0.2 Iris-setosa
17 16 5.7 4.4 1.5 0.4 Iris-setosa
18 17 5.4 3.9 1.3 0.4 Iris-setosa
19 18 5.1 3.5 1.4 0.3 Iris-setosa
20 19 5.7 3.8 1.7 0.3 Iris-setosa
21 20 5.1 3.8 1.5 0.3 Iris-setosa
22 21 5.4 3.4 1.7 0.2 Iris-setosa
23 22 5.1 3.7 1.5 0.4 Iris-setosa
24 23 4.6 3.6 1.0 0.2 Iris-setosa
25 24 5.1 3.3 1.7 0.5 Iris-setosa
26 25 4.8 3.4 1.9 0.2 Iris-setosa
27 26 5.0 3.0 1.6 0.2 Iris-setosa
28 27 5.0 3.4 1.6 0.4 Iris-setosa
29 28 5.2 3.5 1.5 0.2 Iris-setosa
30 29 5.2 3.4 1.4 0.2 Iris-setosa
31 30 4.7 3.2 1.6 0.2 Iris-setosa
32 31 4.8 3.1 1.6 0.2 Iris-setosa
33 32 5.4 3.4 1.5 0.4 Iris-setosa
34 33 5.2 4.1 1.5 0.1 Iris-setosa
35 34 5.5 4.2 1.4 0.2 Iris-setosa
36 35 4.9 3.1 1.5 0.1 Iris-setosa
37 36 5.0 3.2 1.2 0.2 Iris-setosa
38 37 5.5 3.5 1.3 0.2 Iris-setosa
39 38 4.9 3.1 1.5 0.1 Iris-setosa
40 39 4.4 3.0 1.3 0.2 Iris-setosa
41 40 5.1 3.4 1.5 0.2 Iris-setosa
42 41 5.0 3.5 1.3 0.3 Iris-setosa
43 42 4.5 2.3 1.3 0.3 Iris-setosa
44 43 4.4 3.2 1.3 0.2 Iris-setosa
45 44 5.0 3.5 1.6 0.6 Iris-setosa
46 45 5.1 3.8 1.9 0.4 Iris-setosa
47 46 4.8 3.0 1.4 0.3 Iris-setosa
48 47 5.1 3.8 1.6 0.2 Iris-setosa
49 48 4.6 3.2 1.4 0.2 Iris-setosa
50 49 5.3 3.7 1.5 0.2 Iris-setosa
51 50 5.0 3.3 1.4 0.2 Iris-setosa
52 51 7.0 3.2 4.7 1.4 Iris-versicolor
53 52 6.4 3.2 4.5 1.5 Iris-versicolor
54 53 6.9 3.1 4.9 1.5 Iris-versicolor
55 54 5.5 2.3 4.0 1.3 Iris-versicolor
56 55 6.5 2.8 4.6 1.5 Iris-versicolor
57 56 5.7 2.8 4.5 1.3 Iris-versicolor
58 57 6.3 3.3 4.7 1.6 Iris-versicolor
59 58 4.9 2.4 3.3 1.0 Iris-versicolor
60 59 6.6 2.9 4.6 1.3 Iris-versicolor
61 60 5.2 2.7 3.9 1.4 Iris-versicolor
62 61 5.0 2.0 3.5 1.0 Iris-versicolor
63 62 5.9 3.0 4.2 1.5 Iris-versicolor
64 63 6.0 2.2 4.0 1.0 Iris-versicolor
65 64 6.1 2.9 4.7 1.4 Iris-versicolor
66 65 5.6 2.9 3.6 1.3 Iris-versicolor
67 66 6.7 3.1 4.4 1.4 Iris-versicolor
68 67 5.6 3.0 4.5 1.5 Iris-versicolor
69 68 5.8 2.7 4.1 1.0 Iris-versicolor
70 69 6.2 2.2 4.5 1.5 Iris-versicolor
71 70 5.6 2.5 3.9 1.1 Iris-versicolor
72 71 5.9 3.2 4.8 1.8 Iris-versicolor
73 72 6.1 2.8 4.0 1.3 Iris-versicolor
74 73 6.3 2.5 4.9 1.5 Iris-versicolor
75 74 6.1 2.8 4.7 1.2 Iris-versicolor
76 75 6.4 2.9 4.3 1.3 Iris-versicolor
77 76 6.6 3.0 4.4 1.4 Iris-versicolor
78 77 6.8 2.8 4.8 1.4 Iris-versicolor
79 78 6.7 3.0 5.0 1.7 Iris-versicolor
80 79 6.0 2.9 4.5 1.5 Iris-versicolor
81 80 5.7 2.6 3.5 1.0 Iris-versicolor
82 81 5.5 2.4 3.8 1.1 Iris-versicolor
83 82 5.5 2.4 3.7 1.0 Iris-versicolor
84 83 5.8 2.7 3.9 1.2 Iris-versicolor
85 84 6.0 2.7 5.1 1.6 Iris-versicolor
86 85 5.4 3.0 4.5 1.5 Iris-versicolor
87 86 6.0 3.4 4.5 1.6 Iris-versicolor
88 87 6.7 3.1 4.7 1.5 Iris-versicolor
89 88 6.3 2.3 4.4 1.3 Iris-versicolor
90 89 5.6 3.0 4.1 1.3 Iris-versicolor
91 90 5.5 2.5 4.0 1.3 Iris-versicolor
92 91 5.5 2.6 4.4 1.2 Iris-versicolor
93 92 6.1 3.0 4.6 1.4 Iris-versicolor
94 93 5.8 2.6 4.0 1.2 Iris-versicolor
95 94 5.0 2.3 3.3 1.0 Iris-versicolor
96 95 5.6 2.7 4.2 1.3 Iris-versicolor
97 96 5.7 3.0 4.2 1.2 Iris-versicolor
98 97 5.7 2.9 4.2 1.3 Iris-versicolor
99 98 6.2 2.9 4.3 1.3 Iris-versicolor
100 99 5.1 2.5 3.0 1.1 Iris-versicolor
101 100 5.7 2.8 4.1 1.3 Iris-versicolor
102 101 6.3 3.3 6.0 2.5 Iris-virginica
103 102 5.8 2.7 5.1 1.9 Iris-virginica
104 103 7.1 3.0 5.9 2.1 Iris-virginica
105 104 6.3 2.9 5.6 1.8 Iris-virginica
106 105 6.5 3.0 5.8 2.2 Iris-virginica
107 106 7.6 3.0 6.6 2.1 Iris-virginica
108 107 4.9 2.5 4.5 1.7 Iris-virginica
109 108 7.3 2.9 6.3 1.8 Iris-virginica
110 109 6.7 2.5 5.8 1.8 Iris-virginica
111 110 7.2 3.6 6.1 2.5 Iris-virginica
112 111 6.5 3.2 5.1 2.0 Iris-virginica
113 112 6.4 2.7 5.3 1.9 Iris-virginica
114 113 6.8 3.0 5.5 2.1 Iris-virginica
115 114 5.7 2.5 5.0 2.0 Iris-virginica
116 115 5.8 2.8 5.1 2.4 Iris-virginica
117 116 6.4 3.2 5.3 2.3 Iris-virginica
118 117 6.5 3.0 5.5 1.8 Iris-virginica
119 118 7.7 3.8 6.7 2.2 Iris-virginica
120 119 7.7 2.6 6.9 2.3 Iris-virginica
121 120 6.0 2.2 5.0 1.5 Iris-virginica
122 121 6.9 3.2 5.7 2.3 Iris-virginica
123 122 5.6 2.8 4.9 2.0 Iris-virginica
124 123 7.7 2.8 6.7 2.0 Iris-virginica
125 124 6.3 2.7 4.9 1.8 Iris-virginica
126 125 6.7 3.3 5.7 2.1 Iris-virginica
127 126 7.2 3.2 6.0 1.8 Iris-virginica
128 127 6.2 2.8 4.8 1.8 Iris-virginica
129 128 6.1 3.0 4.9 1.8 Iris-virginica
130 129 6.4 2.8 5.6 2.1 Iris-virginica
131 130 7.2 3.0 5.8 1.6 Iris-virginica
132 131 7.4 2.8 6.1 1.9 Iris-virginica
133 132 7.9 3.8 6.4 2.0 Iris-virginica
134 133 6.4 2.8 5.6 2.2 Iris-virginica
135 134 6.3 2.8 5.1 1.5 Iris-virginica
136 135 6.1 2.6 5.6 1.4 Iris-virginica
137 136 7.7 3.0 6.1 2.3 Iris-virginica
138 137 6.3 3.4 5.6 2.4 Iris-virginica
139 138 6.4 3.1 5.5 1.8 Iris-virginica
140 139 6.0 3.0 4.8 1.8 Iris-virginica
141 140 6.9 3.1 5.4 2.1 Iris-virginica
142 141 6.7 3.1 5.6 2.4 Iris-virginica
143 142 6.9 3.1 5.1 2.3 Iris-virginica
144 143 5.8 2.7 5.1 1.9 Iris-virginica
145 144 6.8 3.2 5.9 2.3 Iris-virginica
146 145 6.7 3.3 5.7 2.5 Iris-virginica
147 146 6.7 3.0 5.2 2.3 Iris-virginica
148 147 6.3 2.5 5.0 1.9 Iris-virginica
149 148 6.5 3.0 5.2 2.0 Iris-virginica
150 149 6.2 3.4 5.4 2.3 Iris-virginica
151 150 5.9 3.0 5.1 1.8 Iris-virginica

View File

@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
jupyter = "*"
notebook = "*"
pandas = "*"
quandl = "*"
seaborn = "*"
sklearn = "*"
scikit-learn = "*"
pydot = "*"
[dev-packages]
[requires]
python_version = "3.11"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
10 + 10
'10 + 10'
'10 + 10'
10 + 10
10 + '10'
'Hello world'
type(10)
type('abc')

View File

@@ -0,0 +1,6 @@
# x = 5
# x
# x = 10
# y = 20
# x + y
# x = y

View File

@@ -0,0 +1,29 @@
# print()
# print('hello world!')
# year = 2017
# print('This year is '+year)
# print('This year is '+str(year))
# yearStr = '2017'
# print('This year is '+yearStr)
# print('This year is '+(yearStr+1))
# print('This year is '+str(int(yearStr)+1))
#
# format()
# year = 2017
# print('This year is '+year)
# print('This year is '+str(year))
# print('This year is {}'.format(year)
# print('This year is {}, and next year is {}'.format(year,year+1))
# print('This year is {}, and I will go abroad at the end of {}'.format(2017,2017))
# print('This year is {y}, and I will go abroad at the end of {y}'.format(y=2017))
#
# input()
# input('How tall are you? ')
# height = input('How tall are you?')
# print('You are {} meter tall'.format(int(height)/100))
#
#
#
height = input('What\'s your height? ')
height = int(input('What\'s your height? '))

View File

@@ -0,0 +1,30 @@
def say_hello():
print('Hello World!')
def area_of_square(length):
return length**2
def area_of_circle(radius):
pi = 3.1415926
return pi*radius**2
# pi can also be defined outside of the function
# good and bad?
# what if someone change the value outside?
def area_of_rectangle(length,width):
return length*width
def app():
age = int(input('What\'s your age?'))
print('Your age is {}'.format(age))
print('-------')
app()
app()

View File

@@ -0,0 +1,16 @@
def bmi_test(bmi):
if bmi < 18.5:
print('You\'d better eat more!')
elif bmi < 24:
print('Good job!')
else:
print('You\'d better to some exercises')
bmi_test(20)
# multiple statement
# multiple

View File

@@ -0,0 +1,52 @@
# BMI = Weight / Height^2 kg and m
def convert_to_m(height):
return height/100
def calculate_bmi(height, weight):
#print(weight)
#print(height)
return weight/height**2
def bmi_test(bmi):
print('Your bmi is {}'.format(round(bmi, 2)))
if bmi < 18.5:
print('You\'d better eat more!')
elif bmi < 25:
print('Good job!')
elif bmi < 30:
print('You\'d better do some exercises')
else:
print('You\'d better consult doctor')
def bmi_app():
try:
age = int(input('What\'s your age?'))
except ValueError:
print("You need to enter 0 - 100 as your age")
try:
age = int(input('What\'s your age?'))
except:
print("Your input is still wrong. Quitting the app")
return
if age < 18:
print("Sorry I can't help you.")
else:
height = float(input('What\'s your height (in cm)? '))
height = convert_to_m(height)
weight = float(input('what\'s your weight (in kg) '))
bmi = calculate_bmi(height, weight)
bmi_test(bmi)
print('-------------------------------------------')
bmi_app()
bmi_app()
# how to improve?
# Q1 what if the weight is not integer? e.g. 62.5

View File

@@ -0,0 +1,29 @@
# you can download at
# https://goo.gl/WKdcqo
colors = ['red', 'blue', 'green']
colors
colors[0] # zero base indexing
colors[1]
colors[2]
colors.append('purple')
colors
colors.remove('green')
colors
colors.extend(['green', 'yellow'])
'green' in colors
colors[3]
type(colors)
help(colors)

View File

@@ -0,0 +1,13 @@
# you can download at
# https://goo.gl/WKdcqo
import random
random.randint(0,3)
colors = [random.randint(0,2)]
colors = [random.randint(0,len(colors))]
random.choice(colors)

View File

@@ -0,0 +1,28 @@
# you can download at
# https://goo.gl/WKdcqo
colors = ['red','blue','green']
for color in colors:
print('I love {}'.format(color))
range(3)
for i in range(3):
print(i)
for i in range(5):
print(i)
# break, pass, continue
for i in range(3):
cmd = input('Enter command: ')
if cmd == 'break':
break
elif cmd == 'pass':
pass
print('command is pass')
elif cmd == 'continue':
continue
print('command is continue')

View File

@@ -0,0 +1,26 @@
# you can download at
# https://goo.gl/WKdcqo
import random
def guess_lucky_number():
colors = ['red', 'blue', 'green', 'purple', 'yellow']
lucky_color = random.choice(colors)
for i in range(3):
print('There are {} colors'.format(colors))
guess = input('Guess your lucky color: ')
if guess != lucky_color:
colors.remove(guess)
print('Seems like {} is not your lucky color :( \n'.format(guess))
else:
break
if guess == lucky_color:
print('Great! {} is your lucky color!! '.format(lucky_color))
else:
print('Actually, {} is your lucky color '.format(lucky_color))
guess_lucky_number()

View File

@@ -0,0 +1,19 @@
vocabs = {}
type(vocabs)
vocabs['programming'] = 'the activity of job of writing computer programs'
vocabs
vocabs['python'] = 'a very large snake that kills animals for food'
del(vocabs['programming'])
vocabs.clear()
vocabs['programming'] = ['the activity of job of writing computer programs','_______ming']
vocabs = {'programming': 'the activity of job of writing computer programs',
'python': 'a very large snake'}

View File

@@ -0,0 +1,19 @@
vocabs = {'programming': ['the activity or job of writing computer programs','_______ming'],
'python': ['a very large snake that kills animals for food by wrapping itself around them and crushing them', '___hon'],
'fun': ['pleasure, enjoyment, or entertainment', '__n']}
vocabs.keys()
vocabs.values()
vocabs.items()
for key in vocabs.keys():
print(key)
for value in vocabs.values():
print(value)
for key,value in vocabs.items():
print('{} ({})\n {}'.format(key,value[1],value[0]))

View File

@@ -0,0 +1,36 @@
vocabs = {'programming': ['the activity or job of writing computer programs','_______ming'],
'python': ['a very large snake that kills animals for food by wrapping itself around them and crushing them', '___hon'],
'fun': ['pleasure, enjoyment, or entertainment', '__n']}
def new_word():
try:
word, definition, hint = input('Enter a new word (word|definition|hint): ').split('|')
print('{} ({})\n {}'.format(word,hint,definition))
except ValueError:
print('Please make sure your format is correct!')
except:
print('Something is wrong')
new_word()
def new_word():
try:
word, definition, hint = input("Enter a new words (word|definition|hint)").split("|")
print("{}".format(word))
print(" - {} ({})".format(definition, hint))
print('----------------------')
except ValueError:
print("Value Error")
new_word()
except:
print("Something is wrong")
new_word()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -ex
python -m pip install pipenv
pipenv sync
pipenv run \
jupyter-notebook \
--allow-root \
--ip=0.0.0.0

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
pipenv install jupyter
pipenv install jupyter notebook
pipenv install pandas
pipenv install quandl
pipenv install seaborn
pipenv install scikit-learn
# jupyter-notebook

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
docker run -it \
-v $PWD:/app \
-w /app \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.ssh/id_rsa:/home/node/.ssh/id_rsa:ro \
-v ~/.ssh/known_host:/home/node/.ssh/known_hosts:ro \
-p 8889:8888 \
--rm \
python:latest \
bash

View File

@@ -0,0 +1,52 @@
"state","abbreviation"
"Alabama","AL"
"Alaska","AK"
"Arizona","AZ"
"Arkansas","AR"
"California","CA"
"Colorado","CO"
"Connecticut","CT"
"Delaware","DE"
"District of Columbia","DC"
"Florida","FL"
"Georgia","GA"
"Hawaii","HI"
"Idaho","ID"
"Illinois","IL"
"Indiana","IN"
"Iowa","IA"
"Kansas","KS"
"Kentucky","KY"
"Louisiana","LA"
"Maine","ME"
"Montana","MT"
"Nebraska","NE"
"Nevada","NV"
"New Hampshire","NH"
"New Jersey","NJ"
"New Mexico","NM"
"New York","NY"
"North Carolina","NC"
"North Dakota","ND"
"Ohio","OH"
"Oklahoma","OK"
"Oregon","OR"
"Maryland","MD"
"Massachusetts","MA"
"Michigan","MI"
"Minnesota","MN"
"Mississippi","MS"
"Missouri","MO"
"Pennsylvania","PA"
"Rhode Island","RI"
"South Carolina","SC"
"South Dakota","SD"
"Tennessee","TN"
"Texas","TX"
"Utah","UT"
"Vermont","VT"
"Virginia","VA"
"Washington","WA"
"West Virginia","WV"
"Wisconsin","WI"
"Wyoming","WY"
1 state abbreviation
2 Alabama AL
3 Alaska AK
4 Arizona AZ
5 Arkansas AR
6 California CA
7 Colorado CO
8 Connecticut CT
9 Delaware DE
10 District of Columbia DC
11 Florida FL
12 Georgia GA
13 Hawaii HI
14 Idaho ID
15 Illinois IL
16 Indiana IN
17 Iowa IA
18 Kansas KS
19 Kentucky KY
20 Louisiana LA
21 Maine ME
22 Montana MT
23 Nebraska NE
24 Nevada NV
25 New Hampshire NH
26 New Jersey NJ
27 New Mexico NM
28 New York NY
29 North Carolina NC
30 North Dakota ND
31 Ohio OH
32 Oklahoma OK
33 Oregon OR
34 Maryland MD
35 Massachusetts MA
36 Michigan MI
37 Minnesota MN
38 Mississippi MS
39 Missouri MO
40 Pennsylvania PA
41 Rhode Island RI
42 South Carolina SC
43 South Dakota SD
44 Tennessee TN
45 Texas TX
46 Utah UT
47 Vermont VT
48 Virginia VA
49 Washington WA
50 West Virginia WV
51 Wisconsin WI
52 Wyoming WY

View File

@@ -0,0 +1,53 @@
state,area (sq. mi)
Alabama,52423
Alaska,656425
Arizona,114006
Arkansas,53182
California,163707
Colorado,104100
Connecticut,5544
Delaware,1954
Florida,65758
Georgia,59441
Hawaii,10932
Idaho,83574
Illinois,57918
Indiana,36420
Iowa,56276
Kansas,82282
Kentucky,40411
Louisiana,51843
Maine,35387
Maryland,12407
Massachusetts,10555
Michigan,96810
Minnesota,86943
Mississippi,48434
Missouri,69709
Montana,147046
Nebraska,77358
Nevada,110567
New Hampshire,9351
New Jersey,8722
New Mexico,121593
New York,54475
North Carolina,53821
North Dakota,70704
Ohio,44828
Oklahoma,69903
Oregon,98386
Pennsylvania,46058
Rhode Island,1545
South Carolina,32007
South Dakota,77121
Tennessee,42146
Texas,268601
Utah,84904
Vermont,9615
Virginia,42769
Washington,71303
West Virginia,24231
Wisconsin,65503
Wyoming,97818
District of Columbia,68
Puerto Rico,3515
1 state area (sq. mi)
2 Alabama 52423
3 Alaska 656425
4 Arizona 114006
5 Arkansas 53182
6 California 163707
7 Colorado 104100
8 Connecticut 5544
9 Delaware 1954
10 Florida 65758
11 Georgia 59441
12 Hawaii 10932
13 Idaho 83574
14 Illinois 57918
15 Indiana 36420
16 Iowa 56276
17 Kansas 82282
18 Kentucky 40411
19 Louisiana 51843
20 Maine 35387
21 Maryland 12407
22 Massachusetts 10555
23 Michigan 96810
24 Minnesota 86943
25 Mississippi 48434
26 Missouri 69709
27 Montana 147046
28 Nebraska 77358
29 Nevada 110567
30 New Hampshire 9351
31 New Jersey 8722
32 New Mexico 121593
33 New York 54475
34 North Carolina 53821
35 North Dakota 70704
36 Ohio 44828
37 Oklahoma 69903
38 Oregon 98386
39 Pennsylvania 46058
40 Rhode Island 1545
41 South Carolina 32007
42 South Dakota 77121
43 Tennessee 42146
44 Texas 268601
45 Utah 84904
46 Vermont 9615
47 Virginia 42769
48 Washington 71303
49 West Virginia 24231
50 Wisconsin 65503
51 Wyoming 97818
52 District of Columbia 68
53 Puerto Rico 3515

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
---
tags: [docker, jupyter, python, kaggle, data-science]
---
# man1130
### task 1
- HKD 200
### task 2
- HKD 250

View File

@@ -0,0 +1 @@
# helloworld

View File

@@ -0,0 +1,13 @@
{
"name": "jupyter-bokeh",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gitUpdate": "git add . && git commit -m\"update Man1130-python-comission,\" && git push"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

@@ -0,0 +1,98 @@
/* @theme academic */
@import 'gaia';
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');
:root {
--color-background: #fff;
--color-foreground: #333;
--color-highlight: #800000;
}
section {
background-image: none;
font-family: 'Noto Sans JP', sans-serif;
padding-top: 90px;
padding-left: 40px;
padding-right: 40px;
}
/* https://github.com/marp-team/marpit/issues/271 */
section::after {
font-weight: 700;
content: attr(data-marpit-pagination) '/' attr(data-marpit-pagination-total);
}
ul ul {
font-size: 0.9em;
}
section.lead h1 {
color: #800000;
text-align: left;
}
section.lead h1 strong {
-webkit-text-stroke: 1px #800000;
}
section.lead h2 {
color: #800000;
text-align: left;
}
section.lead h2 strong {
-webkit-text-stroke: 1px #800000;
}
section.lead h3 {
color: #800000;
text-align: left;
}
section.lead h3 strong {
-webkit-text-stroke: 1px #800000;
}
section.lead h4 {
color: #800000;
text-align: left;
}
section.lead h4 strong {
-webkit-text-stroke: 1px #800000;
}
section.lead h5 {
color: #800000;
text-align: left;
}
section.lead h5 strong {
-webkit-text-stroke: 1px #800000;
}
section.lead p {
text-align: right;
}
header {
background-color: #800000;
color: #fff;
font-size: 1em;
font-weight: 700;
}
blockquote {
max-width: 90%;
border-top: 0.1em dashed #555;
font-size: 60%;
position: absolute;
bottom: 20px;
}
blockquote::before {
content: "";
}
blockquote::after {
content: "";
}
img[alt~="center"] {
display: block;
margin: 0 auto;
}
code {
font-family: 'Source Code Pro', monospace;
}

BIN
Man1130/jupyter/Man1130-python-comission/slides/bg.jpg (Stored with Git LFS) Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,330 @@
@charset "UTF-8";
/*!
* Marp Dracula theme.
* @theme dracula
* @author Daniel Nicolas Gisolfi
*
* @auto-scaling true
* @size 4:3 960px 720px
* @size 16:9 1280px 720px
*/
@import url("https://fonts.googleapis.com/css?family=Lato:400,900|IBM+Plex+Sans:400,700");
:root {
--dracula-background: #282a36;
--dracula-current-line: #44475a;
--dracula-foreground: #f8f8f2;
--dracula-comment: #6272a4;
--dracula-cyan: #8be9fd;
--dracula-green: #50fa7b;
--dracula-orange: #ffb86c;
--dracula-pink: #ff79c6;
--dracula-purple:#bd93f9;
--dracula-red: #ff5555;
--dracula-yellow: #f1fa8c;
}
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: var(--dracula-background);
}
/* Dracula Foreground */
.hljs,
.hljs-subst,
.hljs-typing,
.hljs-variable,
.hljs-template-variable {
color: var(--dracula-foreground);
}
/* Dracula Comment */
.hljs-comment,
.hljs-quote,
.hljs-deletion {
color: var(--dracula-comment);
}
/* Dracula Cyan */
.hljs-meta .hljs-doctag,
.hljs-built_in,
.hljs-selector-tag,
.hljs-section,
.hljs-link,
.hljs-class {
color: var(--dracula-cyan);
}
/* Dracula Green */
.hljs-title {
color: var(--dracula-green);
}
/* Dracula Orange */
.hljs-params {
color: var(--dracula-orange);
}
/* Dracula Pink */
.hljs-keyword {
color: var(--dracula-pink);
}
/* Dracula Purple */
.hljs-literal,
.hljs-number {
color: var(--dracula-purple);
}
/* Dracula Red */
.hljs-regexp {
color: var(--dracula-red);
}
/* Dracula Yellow */
.hljs-string,
.hljs-name,
.hljs-type,
.hljs-attr,
.hljs-symbol,
.hljs-bullet,
.hljs-addition,
.hljs-template-tag {
color: var(--dracula-yellow);
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-title,
.hljs-section,
.hljs-doctag,
.hljs-type,
.hljs-name,
.hljs-strong {
font-weight: bold;
}
.hljs-params,
.hljs-emphasis {
font-style: italic;
}
svg[data-marp-fitting=svg] {
max-height: 580px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0.5em 0 0 0;
color: var(--dracula-pink);
}
h1 strong,
h2 strong,
h3 strong,
h4 strong,
h5 strong,
h6 strong {
font-weight: inherit;
}
h1 {
font-size: 1.8em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.3em;
}
h4 {
font-size: 1.1em;
}
h5 {
font-size: 1em;
}
h6 {
font-size: 0.9em;
}
p,
blockquote {
margin: 1em 0 0 0;
}
ul > li,
ol > li {
margin: 0.3em 0 0 0;
color: var(--dracula-cyan);
}
ul > li > p,
ol > li > p {
margin: 0.6em 0 0 0;
}
code {
display: inline-block;
font-family: "IBM Plex Mono", monospace;
font-size: 0.8em;
letter-spacing: 0;
margin: -0.1em 0.15em;
padding: 0.1em 0.2em;
vertical-align: baseline;
color: var(--dracula-green);
}
pre {
display: block;
margin: 1em 0 0 0;
min-height: 1em;
overflow: visible;
}
pre code {
box-sizing: border-box;
margin: 0;
min-width: 100%;
padding: 0.5em;
font-size: 0.7em;
}
pre code svg[data-marp-fitting=svg] {
max-height: calc(580px - 1em);
}
blockquote {
margin: 1em 0 0 0;
padding: 0 1em;
position: relative;
color: var(--dracula-orange);
}
blockquote::after, blockquote::before {
content: "“";
display: block;
font-family: "Times New Roman", serif;
font-weight: bold;
position: absolute;
color: var(--dracula-green);
}
blockquote::before {
top: 0;
left: 0;
}
blockquote::after {
right: 0;
bottom: 0;
transform: rotate(180deg);
}
blockquote > *:first-child {
margin-top: 0;
}
mark {
background: transparent;
}
table {
border-spacing: 0;
border-collapse: collapse;
margin: 1em 0 0 0;
}
table th,
table td {
padding: 0.2em 0.4em;
border-width: 1px;
border-style: solid;
}
section {
font-size: 35px;
font-family: "IBM Plex Sans";
line-height: 1.35;
letter-spacing: 1.25px;
padding: 70px;
color: var(--dracula-foreground);
background-color: var(--dracula-background);
}
section > *:first-child,
section > header:first-child + * {
margin-top: 0;
}
section a,
section mark {
color: var(--dracula-red);
}
section code {
background: var(--dracula-current-line);
color: var(--dracula-current-green);
}
section h1 strong,
section h2 strong,
section h3 strong,
section h4 strong,
section h5 strong,
section h6 strong {
color: var(--dracula-current-line);
}
section pre > code {
background: var(--dracula-current-line);
}
section header,
section footer,
section section::after,
section blockquote::before,
section blockquote::after {
color: var(--dracula-comment);
}
section table th,
section table td {
border-color: var(--dracula-current-line);
}
section table thead th {
background: var(--dracula-current-line);
color: var(--dracula-yellow);
}
section table tbody > tr:nth-child(even) td,
section table tbody > tr:nth-child(even) th {
background: var(--dracula-current-line);
}
header,
footer,
section::after {
box-sizing: border-box;
font-size: 66%;
height: 70px;
line-height: 50px;
overflow: hidden;
padding: 10px 25px;
position: absolute;
color: var(--dracula-comment);
}
header {
left: 0;
right: 0;
top: 0;
}
footer {
left: 0;
right: 0;
bottom: 0;
}
section::after {
right: 0;
bottom: 0;
font-size: 80%;
}

View File

@@ -0,0 +1,3 @@
npx @marp-team/marp-cli@latest -w slides.md
@REM -o slides.pdf

View File

@@ -0,0 +1,88 @@
---
marp: true
title: Marp CLI example
description: Hosting Marp slide deck on the web
theme: uncover
paginate: true
_paginate: false
footer: '2022 project presentation'
style: |
section {
background-color: #ccc;
}
footer {
text-align: center;
}
---
![bg](./assets/gradient.jpg)
# <!--fit--> Marp CLI 例子
托管 Marp slide deck 在服务器上
https://github.com/yhatt/marp-cli-example
<style scoped>a { color: #eee; }</style>
<!-- 这是一个注释文件 This is presenter note. You can write down notes through HTML comment. -->
---
![Marp bg 60%](https://raw.githubusercontent.com/marp-team/marp/master/marp.png)
---
![bg](#123)
![](#fff)
##### <!--fit--> [Marp CLI](https://github.com/marp-team/marp-cli) + [GitHub Pages](https://github.com/pages) | [Netlify](https://www.netlify.com/) | [Vercel](https://vercel.com/)
##### <!--fit--> 👉 The easiest way to host<br />your Marp deck on the web
---
![bg right 60%](https://icongr.am/octicons/mark-github.svg)
## **[GitHub Pages](https://github.com/pages)**
#### Ready to write & host your deck!
[![Use this as template h:1.5em](https://img.shields.io/badge/-Use%20this%20as%20template-brightgreen?style=for-the-badge&logo=github)](https://github.com/yhatt/marp-cli-example/generate)
---
![bg right 60%](https://icongr.am/simple/netlify.svg?colored)
## **[Netlify](https://www.netlify.com/)**
#### Ready to write & host your deck!
[![Deploy to Netlify h:1.5em](./assets/netlify-deploy-button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/yhatt/marp-cli-example)
---
![bg right 60%](https://icongr.am/simple/zeit.svg)
## **[Vercel](https://vercel.com/)**
#### Ready to write & host your deck!
[![Deploy to Vercel h:1.5em](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/yhatt/marp-cli-example)
---
### <!--fit--> :ok_hand:
---
![bg 40% opacity blur](https://avatars1.githubusercontent.com/u/3993388?v=4)
### Created by Yuki Hattori ([@yhatt](https://github.com/yhatt))
https://github.com/yhatt/marp-cli-example

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,223 @@
---
marp: true
title: Marp CLI example
description: Hosting Marp slide deck on the web
theme: uncover
paginate: true
_paginate: false
backgroundImage: url('https://www.google.com/url?sa=i&url=https%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FFile%3AHelloWorld.svg&psig=AOvVaw0d3lmyaMphPi0ANeGIEJOw&ust=1670049479380000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCJjxx6Gp2vsCFQAAAAAdAAAAABAE')
footer: '2022 project presentation'
style: |
section {
background-color: #ccc;
padding: 0 10vw;
}
footer {
text-align: center;
}
---
<!-- lead-invert-red -->
### **slide topic?**
##### overview of the dataset
- Male and Female proportion
- male by age
- female by age
- The types of chest pain experienced among the patients
- pie chart
- showing the correlation between
chest pain and target Confusion Matrix ?
<!-- HTML comment recognizes as a presenter note per pages. -->
<!-- You may place multiple comments in a single page. -->
<!--
Also supports multiline.
We bet these comments would help your presentation...
-->
---
<!-- lead-invert-red -->
### **Decision Tree**
##### overview of the dataset
- Decision Tree 果張圖
- Performance Analysis
- confusion matrix
- ROC
<!-- HTML comment recognizes as a presenter note per pages. -->
<!-- You may place multiple comments in a single page. -->
<!--
Also supports multiline.
We bet these comments would help your presentation...
-->
---
<!-- lead-invert-red -->
### **Naive Bayes**
##### overview of the dataset
- Naive Bayes 果張圖
- Performance Analysis
- confusion matrix
- ROC
<!-- HTML comment recognizes as a presenter note per pages. -->
<!-- You may place multiple comments in a single page. -->
<!--
Also supports multiline.
We bet these comments would help your presentation...
-->
---
<!-- lead-invert-red -->
### **Logistic Regression**
##### overview of the dataset
- Logistic Regression 果張圖
<!-- HTML comment recognizes as a presenter note per pages. -->
<!-- You may place multiple comments in a single page. -->
<!--
Also supports multiline.
We bet these comments would help your presentation...
-->
---
### **Performance Analysis**
- Performance Analysis
- confusion matrix
- ROC
<!-- HTML comment recognizes as a presenter note per pages. -->
<!-- You may place multiple comments in a single page. -->
<!--
Also supports multiline.
We bet these comments would help your presentation...
-->
---
### **Performance Analysis con't**
- pick a sample, bayes modeling:
- naive_bayes_scramble.ipynb
- column selection
- compare column vs accurancy
- the performance/accurancy of fewer column MAY BE better than more column
- possible cause
- column noise/ input data accurancy ?
- modal overfitting ?
- extreme case ?
<!-- - Q: Evaluation -->
---
### **Performance Analysis con't**
- how to improve ?
- the choice of the columns may be better if other facuity involved.
- more labelled data improves accuracy
---
### **Performance Analysis con't**
- disclaimer ?
- no model can introduce 100% accurancy
- why ?
- extreme case
- chaos theory ?
- will never take all ~~ervery~~ matters into account
- however, the model can be considered if accuracy above nn% in general
<!-- Q:Whats the problem you are trying to solve -->
<!-- - Hows your program solve the problem -->
<!-- - Demonstrate how your program work/ Go through the data analysis -->
<!-- - What are the interesting libraries that you used? -->
<!-- - Any complex logic in your project that you want to show off -->
<!-- - Any other interesting thing -->
<!-- - Its not a must for you to show your code in presentation. -->
<!-- - Do that if you think that help you to explain things -->
<!-- - We dont need everyone to speak. The whole group share the same score. -->
<!-- - Evaluation -->
<!-- - Good presentation flow, Clarity of your points, Pace of your presentation -->
---
### **why these method ?**
- [x]unsupervised modeling
- cross out reason
- data is already labelled
- data is small amount and discrete
- [x] Knn
- [x] Kmeans
<!-- ref: https://www.ibm.com/cloud/blog/supervised-vs-unsupervised-learning -->
---
### **why these method ?**
- supervised modeling / supervised learning
- data is already labelled
- []Decision Tree
- []Naive Bayes
- performance ? accuracy ? ROI ?
- [x]multi dimensional/column difficult to understand/maintain
- [x]Logistic Regression
- [x]SVM
<!-- ref: https://www.ibm.com/cloud/blog/supervised-vs-unsupervised-learning -->
---
### notes only
<!-- Q: Whats the problem you are trying to solve -->
<!-- Q: Hows your program solve the problem -->
<!-- A: to predict humans heart disease possiblilies by modelling -->
<!-- Q: Demonstrate how your program work/ Go through the data analysis -->
<!-- 可能你要捉一捉佢路, if i were you, i won't go through the data analysis, -->
<!-- because the sample steps every one can google e.g. data cleaning, training model, performance analysis, not the main point -->
<!-- Q: What are the interesting libraries that you used? -->
<!-- Q: Any complex logic in your project that you want to show off -->
<!-- Q: Any other interesting thing -->
<!-- bayes scrambling can help -->
<!-- Q: Evaluation -->
<!-- Performance Analysis ? -->
<!-- X -->
<!-- Q: Its not a must for you to show your code in presentation. -->
<!-- - ? Do that if you think that help you to explain things -->
<!-- Q: We dont need everyone to speak. The whole group share the same score. -->
<!-- Q: Good presentation flow, Clarity of your points, Pace of your presentation -->

View File

@@ -0,0 +1,21 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
jupyter = "*"
notebook = "*"
pandas = "*"
quandl = "*"
seaborn = "*"
sklearn = "*"
scikit-learn = "*"
pydot = "*"
bokeh = "*"
jupyter-bokeh = "*"
[dev-packages]
[requires]
python_version = "3"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b6bf609f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"helloworld\n"
]
}
],
"source": [
"print('helloworld')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b24b4df",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc7f2dc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -ex
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv sync
pipenv install jupyter_bokeh
pipenv run \
jupyter-notebook \
--allow-root \
--ip=0.0.0.0

View File

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b6bf609f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"helloworld\n"
]
}
],
"source": [
"print('helloworld')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b24b4df",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc7f2dc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
pipenv install jupyter
pipenv install jupyter notebook
pipenv install pandas
pipenv install quandl
pipenv install seaborn
pipenv install scikit-learn
# jupyter-notebook

View File

@@ -0,0 +1,30 @@
### to spin up dev environment
```
./start_docker.sh
// inside docker
./dev.sh
open host browser:
http://127.0.0.1:8888/?token=ttttt
```
### to develop
start from fresh python docker image
```
./start_docker.sh
./init.sh
```
### stack
- python
- bokeh

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -ex
docker run -it \
-v $PWD:/app \
-w /app \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.ssh/id_rsa:/home/node/.ssh/id_rsa:ro \
-v ~/.ssh/known_host:/home/node/.ssh/known_hosts:ro \
-p 8888:8888 \
--rm \
python:3.10 \
bash
# -u 1000:1000 \
# -e XDG_CACHE_HOME=/app/.cache \

View File

@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
jupyter = "*"
notebook = "*"
pandas = "*"
quandl = "*"
seaborn = "*"
sklearn = "*"
scikit-learn = "*"
pydot = "*"
bokeh = "*"
jupyter-bokeh = "*"
shap = "*"
ipywidgets = "*"
widgetsnbextension = "*"
pandas-profiling = "*"
[dev-packages]
[requires]
python_version = "3"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -ex
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv sync
python -m pipenv install shap
python -m pipenv install ipywidgets widgetsnbextension pandas-profiling
pipenv run \
jupyter-notebook \
--allow-root \
--ip=0.0.0.0

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
pipenv install jupyter
pipenv install jupyter notebook
pipenv install pandas
pipenv install quandl
pipenv install seaborn
pipenv install scikit-learn
# jupyter-notebook

View File

@@ -0,0 +1,27 @@
### to spin up dev environment
```
./start_docker.sh
// inside docker
./dev.sh
open host browser:
http://127.0.0.1:8888/?token=98ab80de026fe83fd8e03c8e344b31e7575ec4a084c59f21
```
### to develop
start from fresh python docker image
```
./start_docker.sh
./init.sh
```

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -ex
docker run -it \
-v $PWD:/app \
-w /app \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.ssh/id_rsa:/home/node/.ssh/id_rsa:ro \
-v ~/.ssh/known_host:/home/node/.ssh/known_hosts:ro \
-p 8888:8888 \
--rm \
python:3.10 \
bash
# -u 1000:1000 \
# -e XDG_CACHE_HOME=/app/.cache \

View File

@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
jupyter = "*"
notebook = "*"
pandas = "*"
quandl = "*"
seaborn = "*"
sklearn = "*"
scikit-learn = "*"
pydot = "*"
bokeh = "*"
jupyter-bokeh = "*"
voila = "*"
bqplot = "*"
ipympl = "*"
ipyvolume = "*"
[dev-packages]
[requires]
python_version = "3"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -ex
python -m pip install --upgrade pip
python -m pip install pipenv
python -m pipenv install voila
python -m pipenv install bqplot
python -m pipenv install ipympl
python -m pipenv install ipyvolume
pipenv sync
pipenv run \
jupyter-notebook \
--allow-root \
--ip=0.0.0.0

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
pipenv install jupyter
pipenv install jupyter notebook
pipenv install pandas
pipenv install quandl
pipenv install seaborn
pipenv install scikit-learn
# jupyter-notebook

View File

@@ -0,0 +1,248 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render Jupyter notebooks with interactions requiring a roundtrip to the kernel."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Jupyter Widgets"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9d234bc95ca5460ea86e664a957764e3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(FloatSlider(value=4.0, description='$x$'), FloatText(value=16.0, description='$x^2$', disabled=…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"slider = widgets.FloatSlider(description='$x$')\n",
"text = widgets.FloatText(disabled=True, description='$x^2$')\n",
"\n",
"def compute(*ignore):\n",
" text.value = str(slider.value ** 2)\n",
"\n",
"slider.observe(compute, 'value')\n",
"\n",
"slider.value = 4\n",
"\n",
"widgets.VBox([slider, text])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic outputs of code cells"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>sepal_length</th>\n",
" <th>sepal_width</th>\n",
" <th>petal_length</th>\n",
" <th>petal_width</th>\n",
" <th>species</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5.1</td>\n",
" <td>3.5</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4.9</td>\n",
" <td>3.0</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>4.7</td>\n",
" <td>3.2</td>\n",
" <td>1.3</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4.6</td>\n",
" <td>3.1</td>\n",
" <td>1.5</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5.0</td>\n",
" <td>3.6</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>145</th>\n",
" <td>6.7</td>\n",
" <td>3.0</td>\n",
" <td>5.2</td>\n",
" <td>2.3</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>146</th>\n",
" <td>6.3</td>\n",
" <td>2.5</td>\n",
" <td>5.0</td>\n",
" <td>1.9</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>147</th>\n",
" <td>6.5</td>\n",
" <td>3.0</td>\n",
" <td>5.2</td>\n",
" <td>2.0</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>148</th>\n",
" <td>6.2</td>\n",
" <td>3.4</td>\n",
" <td>5.4</td>\n",
" <td>2.3</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>149</th>\n",
" <td>5.9</td>\n",
" <td>3.0</td>\n",
" <td>5.1</td>\n",
" <td>1.8</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>150 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" sepal_length sepal_width petal_length petal_width species\n",
"0 5.1 3.5 1.4 0.2 setosa\n",
"1 4.9 3.0 1.4 0.2 setosa\n",
"2 4.7 3.2 1.3 0.2 setosa\n",
"3 4.6 3.1 1.5 0.2 setosa\n",
"4 5.0 3.6 1.4 0.2 setosa\n",
".. ... ... ... ... ...\n",
"145 6.7 3.0 5.2 2.3 virginica\n",
"146 6.3 2.5 5.0 1.9 virginica\n",
"147 6.5 3.0 5.2 2.0 virginica\n",
"148 6.2 3.4 5.4 2.3 virginica\n",
"149 5.9 3.0 5.1 1.8 virginica\n",
"\n",
"[150 rows x 5 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')\n",
"iris"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render custom Jupyter widgets such as [bqplot](https://github.com/bloomberg/bqplot). "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f771faf1649e425480af29391b9a238e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"\n",
"plt.figure(1, title='Line Chart')\n",
"np.random.seed(0)\n",
"n = 200\n",
"x = np.linspace(0.0, 10.0, n)\n",
"y = np.cumsum(np.random.randn(n))\n",
"plt.plot(x, y)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This demo uses Voilà to render a notebook to a custom HTML page using gridstack.js for the layout of each output. In the cell metadata you can change the default cell with and height (in grid units between 1 and 12) by specifying.\n",
" * `grid_row`\n",
" * `grid_columns`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"n = 200\n",
"\n",
"x = np.linspace(0.0, 10.0, n)\n",
"y = np.cumsum(np.random.randn(n)*10).astype(int)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fb68ca2d6f7f40c2adb9d01d134a4373",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='Selected: 0')"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"label_selected = widgets.Label(value=\"Selected: 0\")\n",
"label_selected"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"grid_columns": 8,
"grid_rows": 4
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "227e65a70eab4eb38b0b2f25d8237656",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale(max=70.0, min=-131.0))]…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"import bqplot\n",
"\n",
"fig = plt.figure( title='Histogram')\n",
"np.random.seed(0)\n",
"hist = plt.hist(y, bins=25)\n",
"hist.scales['sample'].min = float(y.min())\n",
"hist.scales['sample'].max = float(y.max())\n",
"display(fig)\n",
"fig.layout.width = 'auto'\n",
"fig.layout.height = 'auto'\n",
"fig.layout.min_height = '300px' # so it shows nicely in the notebook\n",
"fig.layout.flex = '1'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"grid_columns": 12,
"grid_rows": 6
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5fee6ee9af0a4dc7a557f8d16a5b7150",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"import bqplot\n",
"\n",
"fig = plt.figure( title='Line Chart')\n",
"np.random.seed(0)\n",
"n = 200\n",
"p = plt.plot(x, y)\n",
"fig"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"fig.layout.width = 'auto'\n",
"fig.layout.height = 'auto'\n",
"fig.layout.min_height = '300px' # so it shows nicely in the notebook\n",
"fig.layout.flex = '1'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"brushintsel = bqplot.interacts.BrushIntervalSelector(scale=p.scales['x'])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def update_range(*args):\n",
" label_selected.value = \"Selected range {}\".format(brushintsel.selected)\n",
" mask = (x > brushintsel.selected[0]) & (x < brushintsel.selected[1])\n",
" hist.sample = y[mask]\n",
" \n",
"brushintsel.observe(update_range, 'selected')\n",
"fig.interaction = brushintsel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Which multiplication table do you want to learn?\n",
"\n",
"In this example notebook we demonstrate how Voilà can render different Jupyter widgets using [GridspecLayout](https://ipywidgets.readthedocs.io/en/latest/examples/Layout%20Templates.html#Grid-layout)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "19dcc46af51049c9a9e26568b76aa789",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GridspecLayout(children=(Dropdown(index=1, layout=Layout(grid_area='widget001'), options=(1, 2, 3, 4, 5, 6, 7,…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipywidgets import GridspecLayout, Button, BoundedIntText, Valid, Layout, Dropdown\n",
"\n",
"def create_expanded_button(description, button_style):\n",
" return Button(description=description, button_style=button_style, layout=Layout(height='auto', width='auto'))\n",
" \n",
"rows = 11\n",
"columns = 6\n",
"\n",
"gs = GridspecLayout(rows, columns)\n",
"\n",
"def on_result_change(change):\n",
" row = int(change[\"owner\"].layout.grid_row)\n",
" gs[row, 5].value = gs[0, 0].value * row == change[\"new\"]\n",
" \n",
"def on_multipler_change(change):\n",
" for i in range(1, rows):\n",
" gs[i, 0].description = str(change[\"new\"])\n",
" gs[i, 4].max = change[\"new\"] * 10\n",
" gs[i, 4].value = 1\n",
" gs[i, 4].step = change[\"new\"]\n",
" gs[i, 5].value = False\n",
"\n",
"gs[0, 0] = Dropdown(\n",
" options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
" value=2,\n",
")\n",
"gs[0, 0].observe(on_multipler_change, names=\"value\")\n",
"multiplier = gs[0, 0].value\n",
"\n",
"for i in range(1, rows):\n",
" gs[i, 0] = create_expanded_button(str(multiplier), \"\")\n",
" gs[i, 1] = create_expanded_button(\"*\", \"\")\n",
" gs[i, 2] = create_expanded_button(str(i), \"info\")\n",
" gs[i, 3] = create_expanded_button(\"=\", \"\")\n",
"\n",
" gs[i, 4] = BoundedIntText(\n",
" min=0,\n",
" max=multiplier * 10,\n",
" layout=Layout(grid_row=str(i)),\n",
" value=1,\n",
" step=multiplier,\n",
" disabled=False\n",
" )\n",
"\n",
" gs[i, 5] = Valid(\n",
" value=False,\n",
" description='Valid!',\n",
" )\n",
"\n",
" gs[i, 4].observe(on_result_change, names='value')\n",
"\n",
"gs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b6bf609f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"helloworld\n"
]
}
],
"source": [
"print('helloworld')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b24b4df",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc7f2dc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render notebooks making use of ipywidget's `@interact`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "954b4c8acda94613bc8dde7e41ad5f9e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(IntSlider(value=0), IntSlider(value=0))), Output()))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipywidgets import HBox, VBox, IntSlider, interactive_output\n",
"from IPython.display import display\n",
"\n",
"a = IntSlider()\n",
"b = IntSlider()\n",
"\n",
"def f(a, b):\n",
" print(\"{} * {} = {}\".format(a, b, a * b))\n",
"\n",
"out = interactive_output(f, { \"a\": a, \"b\": b })\n",
"\n",
"display(HBox([VBox([a, b]), out]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render custom Jupyter widgets such as [ipyvolume](https://github.com/maartenbreddels/ipyvolume). "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'collections' has no attribute 'Mapping'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn [2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mipyvolume\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mipv\u001b[39;00m\n\u001b[1;32m 2\u001b[0m ipv\u001b[38;5;241m.\u001b[39mexamples\u001b[38;5;241m.\u001b[39mexample_ylm();\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/__init__.py:4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m__future__\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m absolute_import\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_version\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m styles\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mwidgets\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransferfunction\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/styles.py:56\u001b[0m\n\u001b[1;32m 47\u001b[0m light \u001b[38;5;241m=\u001b[39m create(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlight\u001b[39m\u001b[38;5;124m\"\u001b[39m, \\\n\u001b[1;32m 48\u001b[0m {\n\u001b[1;32m 49\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbackground-color\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwhite\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 52\u001b[0m }\n\u001b[1;32m 53\u001b[0m })\n\u001b[1;32m 55\u001b[0m default \u001b[38;5;241m=\u001b[39m {}\n\u001b[0;32m---> 56\u001b[0m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdict_deep_update\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdefault\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_defaults\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 57\u001b[0m utils\u001b[38;5;241m.\u001b[39mdict_deep_update(default, light)\n\u001b[1;32m 59\u001b[0m dark \u001b[38;5;241m=\u001b[39m create(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdark\u001b[39m\u001b[38;5;124m\"\u001b[39m, \\\n\u001b[1;32m 60\u001b[0m {\n\u001b[1;32m 61\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbackground-color\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m#000001\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;66;03m# for some reason we cannot set it to black!?!\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 70\u001b[0m }\n\u001b[1;32m 71\u001b[0m })\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/utils.py:19\u001b[0m, in \u001b[0;36mdict_deep_update\u001b[0;34m(d, u)\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdict_deep_update\u001b[39m(d, u):\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m u\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m---> 19\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(v, \u001b[43mcollections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mMapping\u001b[49m):\n\u001b[1;32m 20\u001b[0m r \u001b[38;5;241m=\u001b[39m dict_deep_update(d\u001b[38;5;241m.\u001b[39mget(k, {}), v)\n\u001b[1;32m 21\u001b[0m d[k] \u001b[38;5;241m=\u001b[39m r\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'collections' has no attribute 'Mapping'"
]
}
],
"source": [
"import ipyvolume as ipv\n",
"ipv.examples.example_ylm();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,289 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "913fbbd3",
"metadata": {},
"source": [
"# JSON"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e23193bb",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4c030553429b482b8a3a0d24347f745c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output JSON', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "31ece561ecab413f832f1d5033de4194",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipywidgets import Button, Output\n",
"from IPython import display\n",
"\n",
"button = Button(description='Output JSON')\n",
"output = Output()\n",
"obj = {\n",
" \"abcde\": 1234,\n",
" \"nested\": list(range(10))\n",
"}\n",
"\n",
"@output.capture()\n",
"def on_click(change):\n",
" display.display(display.JSON(obj))\n",
" \n",
" \n",
"button.on_click(on_click)\n",
"display.display(button)\n",
"output"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "690bd908",
"metadata": {},
"outputs": [
{
"data": {
"application/json": {
"abcde": 1234,
"nested": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
},
"text/plain": [
"<IPython.core.display.JSON object>"
]
},
"execution_count": 4,
"metadata": {
"application/json": {
"expanded": false,
"root": "root"
}
},
"output_type": "execute_result"
}
],
"source": [
"display.JSON(obj)"
]
},
{
"cell_type": "markdown",
"id": "97caeade",
"metadata": {},
"source": [
"# Fasta"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "27bbbb6c",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "60c37cb6500547cf81751809d825af34",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output FASTA', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0cfaf056ab234c0c8c4ff914d8334efb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fasta_button = Button(description='Output FASTA')\n",
"fasta_output = Output()\n",
"\n",
"\n",
"def Fasta(data=''):\n",
" bundle = {}\n",
" bundle['application/vnd.fasta.fasta'] = data\n",
" bundle['text/plain'] = data\n",
" display.display(bundle, raw=True)\n",
" \n",
" \n",
"@fasta_output.capture()\n",
"def on_click(change):\n",
" Fasta(\"\"\">SEQUENCE_1\n",
"MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG\n",
"LVSVKVSDDFTIAAMRPSYLSYEDLDMTFVENEYKALVAELEKENEERRRLKDPNKPEHK\n",
"IPQFASRKQLSDAILKEAEEKIKEELKAQGKPEKIWDNIIPGKMNSFIADNSQLDSKLTL\n",
"MGQFYVMDDKKTVEQVIAEKEKEFGGKIKIVEFICFEVGEGLEKKTEDFAAEVAAQL\n",
">SEQUENCE_2\n",
"SATVSEINSETDFVAKNDQFIALTKDTTAHIQSNSLQSVEELHSSTINGVKFEEYLKSQI\n",
"ATIGENLVVRRFATLKAGANGVVNGYIHTNGRVGVVIAAACDSAEVASKSRDLLRQICMH\"\"\")\n",
"\n",
"\n",
"fasta_button.on_click(on_click)\n",
"display.display(fasta_button)\n",
"fasta_output"
]
},
{
"cell_type": "markdown",
"id": "a441bd16",
"metadata": {},
"source": [
"# GeoJSON"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "31371b2f",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "093f167a6c8642ca9e9bc1cdda6e73d1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output GeoJSON', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d78a22c950e34fd48c514bddad9c444b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import GeoJSON\n",
"\n",
"\n",
"geojson_button = Button(description='Output GeoJSON')\n",
"geojson_output = Output()\n",
"\n",
" \n",
"@geojson_output.capture()\n",
"def on_click(change):\n",
" obj = GeoJSON({\n",
" \"type\": \"Feature\",\n",
" \"geometry\": {\n",
" \"type\": \"Point\",\n",
" \"coordinates\": [-118.4563712, 34.0163116]\n",
" }\n",
" })\n",
" display.display(obj)\n",
" \n",
"\n",
"geojson_button.on_click(on_click)\n",
"display.display(geojson_button)\n",
"geojson_output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c0381b4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4099a46a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ebaa184b-765f-4261-9c5c-285bbde8fad5",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dfda01818965434d8417413b6c2020d5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(Button(description='1', style=ButtonStyle()), Button(description='2', style=Butt…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"def generate(n):\n",
" widget = []\n",
" for i in range(n):\n",
" inner = []\n",
" for j in range(n):\n",
" inner.append(widgets.Button(description=f'{i*n+j+1}'))\n",
" widget.append(widgets.HBox(inner))\n",
"\n",
" return widgets.VBox(widget)\n",
"generate(20)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b59589a-7c71-4b1a-896a-b1139cbcf70f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.243603Z",
"start_time": "2020-08-18T12:06:29.240780Z"
}
},
"outputs": [],
"source": [
"import os\n",
"from urllib.parse import parse_qs\n",
"import IPython.display"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.250356Z",
"start_time": "2020-08-18T12:06:29.246161Z"
}
},
"outputs": [],
"source": [
"query_string = os.environ.get('QUERY_STRING', '')\n",
"parameters = parse_qs(query_string)\n",
"print(\"query string parameters:\", parameters)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.258506Z",
"start_time": "2020-08-18T12:06:29.253815Z"
}
},
"outputs": [],
"source": [
"# parameters is a dict of lists\n",
"username = parameters.get('username', ['Kim'])[0]\n",
"print(f'Hi {username}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.275717Z",
"start_time": "2020-08-18T12:06:29.261315Z"
}
},
"outputs": [],
"source": [
"server = os.environ.get('SERVER_NAME', 'localhost') \n",
"url = \"http://\" + server\n",
"\n",
"port = os.environ.get('SERVER_PORT', '')\n",
"if port:\n",
" url += \":\" + port\n",
"\n",
"path = os.environ.get('SCRIPT_NAME', '')\n",
"url += path\n",
"\n",
" \n",
"IPython.display.HTML(data=f\"\"\"\n",
"<a href=\"{url}?username=Riley\">Link to myself as user Riley</a>\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hi\n"
]
}
],
"source": [
"print('hi')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "583e6dc5fecc4802a205e91b768f0261",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(FloatSlider(value=14.0, description='x'), FloatText(value=196.0, description='$x^2$', disabled=…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"slider = widgets.FloatSlider(description='x')\n",
"text = widgets.FloatText(disabled=True, description='$x^2$')\n",
"text.disabled\n",
"def compute(*ignore):\n",
" text.value = str(slider.value**2)\n",
"slider.observe(compute, 'value')\n",
"slider.value = 14\n",
"widgets.VBox([slider, text])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"voila\n"
]
}
],
"source": [
"print('voila')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1+2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"voila": {
"template": "reveal"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

Some files were not shown because too many files have changed in this diff Show More