Added dimensionality red methods
This commit is contained in:
Binary file not shown.
Binary file not shown.
+144
File diff suppressed because one or more lines are too long
+3111
File diff suppressed because one or more lines are too long
+256
File diff suppressed because one or more lines are too long
+125
File diff suppressed because one or more lines are too long
+102
File diff suppressed because one or more lines are too long
+107
@@ -0,0 +1,107 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import mglearn\n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"import os\n",
|
||||
"from scipy import signal\n",
|
||||
"from sklearn.datasets import load_boston\n",
|
||||
"from sklearn.preprocessing import MinMaxScaler, PolynomialFeatures\n",
|
||||
"from mglearn.make_blobs import make_blobs\n",
|
||||
"\n",
|
||||
"#DATA_PATH = os.path.join(os.path.dirname(__file__), \"data\")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def make_forge():\n",
|
||||
" # a carefully hand-designed dataset lol\n",
|
||||
" X, y = make_blobs(centers=2, random_state=4, n_samples=30)\n",
|
||||
" y[np.array([7, 27])] = 0\n",
|
||||
" mask = np.ones(len(X), dtype=np.bool)\n",
|
||||
" mask[np.array([0, 1, 5, 26])] = 0\n",
|
||||
" X, y = X[mask], y[mask]\n",
|
||||
" return X, y\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def make_wave(n_samples=100):\n",
|
||||
" rnd = np.random.RandomState(42)\n",
|
||||
" x = rnd.uniform(-3, 3, size=n_samples)\n",
|
||||
" y_no_noise = (np.sin(4 * x) + x)\n",
|
||||
" y = (y_no_noise + rnd.normal(size=len(x))) / 2\n",
|
||||
" return x.reshape(-1, 1), y\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def load_extended_boston():\n",
|
||||
" boston = load_boston()\n",
|
||||
" X = boston.data\n",
|
||||
"\n",
|
||||
" X = MinMaxScaler().fit_transform(boston.data)\n",
|
||||
" X = PolynomialFeatures(degree=2, include_bias=False).fit_transform(X)\n",
|
||||
" return X, boston.target\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def load_citibike():\n",
|
||||
" data_mine = pd.read_csv(os.path.join(DATA_PATH, \"citibike.csv\"))\n",
|
||||
" data_mine['one'] = 1\n",
|
||||
" data_mine['starttime'] = pd.to_datetime(data_mine.starttime)\n",
|
||||
" data_starttime = data_mine.set_index(\"starttime\")\n",
|
||||
" data_resampled = data_starttime.resample(\"3h\").sum().fillna(0)\n",
|
||||
" return data_resampled.one\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def make_signals():\n",
|
||||
" # fix a random state seed\n",
|
||||
" rng = np.random.RandomState(42)\n",
|
||||
" n_samples = 2000\n",
|
||||
" time = np.linspace(0, 8, n_samples)\n",
|
||||
" # create three signals\n",
|
||||
" s1 = np.sin(2 * time) # Signal 1 : sinusoidal signal\n",
|
||||
" s2 = np.sign(np.sin(3 * time)) # Signal 2 : square signal\n",
|
||||
" s3 = signal.sawtooth(2 * np.pi * time) # Signal 3: saw tooth signal\n",
|
||||
"\n",
|
||||
" # concatenate the signals, add noise\n",
|
||||
" S = np.c_[s1, s2, s3]\n",
|
||||
" S += 0.2 * rng.normal(size=S.shape)\n",
|
||||
"\n",
|
||||
" S /= S.std(axis=0) # Standardize data\n",
|
||||
" S -= S.min()\n",
|
||||
" return S\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"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.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user