In [1]:
%%bash
mkdir /github/
cd /github/
git clone --depth=1 https://github.com/rushter/MLAlgorithms
cd MLAlgorithms
pip install -U -r requirements.txt
pip install .
Requirement already up-to-date: tqdm in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from -r requirements.txt (line 1))
Collecting matplotlib>=1.5.1 (from -r requirements.txt (line 2))
Downloading matplotlib-2.1.0-cp27-cp27mu-manylinux1_x86_64.whl (14.9MB)
Requirement already up-to-date: numpy>=1.11.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from -r requirements.txt (line 3))
Collecting scikit-learn>=0.18 (from -r requirements.txt (line 4))
Downloading scikit_learn-0.19.1-cp27-cp27mu-manylinux1_x86_64.whl (12.2MB)
Collecting scipy>=0.18.0 (from -r requirements.txt (line 5))
Downloading scipy-1.0.0-cp27-cp27mu-manylinux1_x86_64.whl (46.7MB)
Requirement already up-to-date: seaborn>=0.7.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from -r requirements.txt (line 6))
Requirement already up-to-date: six>=1.10.0 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from -r requirements.txt (line 7))
Collecting autograd>=1.1.7 (from -r requirements.txt (line 8))
Downloading autograd-1.2.tar.gz
Requirement already up-to-date: subprocess32 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Requirement already up-to-date: cycler>=0.10 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Collecting backports.functools-lru-cache (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Downloading backports.functools_lru_cache-1.4-py2.py3-none-any.whl
Collecting pytz (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
Requirement already up-to-date: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Requirement already up-to-date: python-dateutil>=2.0 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->-r requirements.txt (line 2))
Collecting pandas (from seaborn>=0.7.1->-r requirements.txt (line 6))
Downloading pandas-0.21.0-cp27-cp27mu-manylinux1_x86_64.whl (24.3MB)
Collecting future>=0.15.2 (from autograd>=1.1.7->-r requirements.txt (line 8))
Downloading future-0.16.0.tar.gz (824kB)
Building wheels for collected packages: autograd, future
Running setup.py bdist_wheel for autograd: started
Running setup.py bdist_wheel for autograd: finished with status 'done'
Stored in directory: /home/nbuser/.cache/pip/wheels/ea/d4/2d/e7d74fb5d727853026c54f23fa96f0b8defefc7d57dcaca0aa
Running setup.py bdist_wheel for future: started
Running setup.py bdist_wheel for future: finished with status 'done'
Stored in directory: /home/nbuser/.cache/pip/wheels/c2/50/7c/0d83b4baac4f63ff7a765bd16390d2ab43c93587fac9d6017a
Successfully built autograd future
Installing collected packages: backports.functools-lru-cache, pytz, matplotlib, scikit-learn, scipy, future, autograd, pandas
Found existing installation: backports.functools-lru-cache 1.2.1
Uninstalling backports.functools-lru-cache-1.2.1:
Successfully uninstalled backports.functools-lru-cache-1.2.1
Found existing installation: pytz 2017.2
Uninstalling pytz-2017.2:
Successfully uninstalled pytz-2017.2
Found existing installation: matplotlib 2.0.2
Uninstalling matplotlib-2.0.2:
Successfully uninstalled matplotlib-2.0.2
Found existing installation: scikit-learn 0.18.1
Uninstalling scikit-learn-0.18.1:
Successfully uninstalled scikit-learn-0.18.1
Found existing installation: scipy 0.19.0
Uninstalling scipy-0.19.0:
Successfully uninstalled scipy-0.19.0
Found existing installation: future 0.15.2
Uninstalling future-0.15.2:
Successfully uninstalled future-0.15.2
Found existing installation: pandas 0.19.2
Uninstalling pandas-0.19.2:
Successfully uninstalled pandas-0.19.2
Successfully installed autograd-1.2 backports.functools-lru-cache-1.4 future-0.16.0 matplotlib-2.1.0 pandas-0.21.0 pytz-2017.3 scikit-learn-0.19.1 scipy-1.0.0
Processing /home/nbuser/library/dl/MLAlgorithms
Requirement already satisfied: tqdm in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: matplotlib>=1.5.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: numpy>=1.11.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: scikit-learn>=0.18 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: scipy>=0.18.0 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: seaborn>=0.7.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: six>=1.10.0 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: autograd>=1.1.7 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from mla==0.0.1)
Requirement already satisfied: subprocess32 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: cycler>=0.10 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: backports.functools-lru-cache in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: pytz in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: python-dateutil>=2.0 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.5.1->mla==0.0.1)
Requirement already satisfied: pandas in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from seaborn>=0.7.1->mla==0.0.1)
Requirement already satisfied: future>=0.15.2 in /home/nbcommon/anaconda2_501/lib/python2.7/site-packages (from autograd>=1.1.7->mla==0.0.1)
Installing collected packages: mla
Running setup.py install for mla: started
Running setup.py install for mla: finished with status 'done'
Successfully installed mla-0.0.1
mkdir: cannot create directory '/github/': Permission denied
bash: line 2: cd: /github/: No such file or directory
fatal: destination path 'MLAlgorithms' already exists and is not an empty directory.
DEPRECATION: Uninstalling a distutils installed project (scikit-learn) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
DEPRECATION: Uninstalling a distutils installed project (future) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
In [2]:
%%bash
cd /space/dl/
bash: line 1: cd: /space/dl/: No such file or directory
In [3]:
import logging
try:
from sklearn.model_selection import train_test_split
except ImportError:
from sklearn.cross_validation import train_test_split
from sklearn.datasets import make_classification
from sklearn.datasets import make_regression
from mla.linear_models import LinearRegression, LogisticRegression
from mla.metrics.metrics import mean_squared_error, accuracy
import numpy as np
In [4]:
logging.basicConfig(level=logging.DEBUG)
In [5]:
def regression():
# Generate a random regression problem
X, y = make_regression(n_samples=10000, n_features=100,
n_informative=75, n_targets=1, noise=0.05,
random_state=1111, bias=0.5)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25,
random_state=1111)
model = LinearRegression(lr=0.01, max_iters=2000, penalty='l2', C=0.03)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print('regression mse', mean_squared_error(y_test, predictions))
In [6]:
regression()
INFO:root:Iteration 1, error 291864.694578
INFO:root:Iteration 2, error 279967.384394
INFO:root:Iteration 3, error 268563.310601
INFO:root:Iteration 4, error 257631.70041
INFO:root:Iteration 5, error 247152.668588
INFO:root:Iteration 6, error 237107.179039
INFO:root:Iteration 7, error 227477.008064
INFO:root:Iteration 8, error 218244.709234
INFO:root:Iteration 9, error 209393.579797
INFO:root:Iteration 10, error 200907.628556
INFO:root:Iteration 11, error 192771.545151
INFO:root:Iteration 12, error 184970.670677
INFO:root:Iteration 13, error 177490.969598
INFO:root:Iteration 14, error 170319.002871
INFO:root:Iteration 15, error 163441.902258
INFO:root:Iteration 16, error 156847.345743
INFO:root:Iteration 17, error 150523.534034
INFO:root:Iteration 18, error 144459.168081
INFO:root:Iteration 19, error 138643.42757
INFO:root:Iteration 20, error 133065.950366
INFO:root:Iteration 21, error 127716.812831
INFO:root:Iteration 22, error 122586.511016
INFO:root:Iteration 23, error 117665.94266
INFO:root:Iteration 24, error 112946.389969
INFO:root:Iteration 25, error 108419.503153
INFO:root:Iteration 26, error 104077.284667
INFO:root:Iteration 27, error 99912.0741371
INFO:root:Iteration 28, error 95916.5339475
INFO:root:Iteration 29, error 92083.635441
INFO:root:Iteration 30, error 88406.6457247
INFO:root:Iteration 31, error 84879.1150432
INFO:root:Iteration 32, error 81494.8646989
INFO:root:Iteration 33, error 78247.9754946
INFO:root:Iteration 34, error 75132.7766746
INFO:root:Iteration 35, error 72143.8353439
INFO:root:Iteration 36, error 69275.9463443
INFO:root:Iteration 37, error 66524.1225665
INFO:root:Iteration 38, error 63883.5856802
INFO:root:Iteration 39, error 61349.7572637
INFO:root:Iteration 40, error 58918.2503152
INFO:root:Iteration 41, error 56584.8611297
INFO:root:Iteration 42, error 54345.5615254
INFO:root:Iteration 43, error 52196.4914037
INFO:root:Iteration 44, error 50133.9516297
INFO:root:Iteration 45, error 48154.3972179
INFO:root:Iteration 46, error 46254.4308106
INFO:root:Iteration 47, error 44430.796436
INFO:root:Iteration 48, error 42680.3735336
INFO:root:Iteration 49, error 41000.1712364
INFO:root:Iteration 50, error 39387.3228972
INFO:root:Iteration 51, error 37839.0808491
INFO:root:Iteration 52, error 36352.8113912
INFO:root:Iteration 53, error 34925.9899871
INFO:root:Iteration 54, error 33556.1966699
INFO:root:Iteration 55, error 32241.1116426
INFO:root:Iteration 56, error 30978.5110667
INFO:root:Iteration 57, error 29766.2630301
INFO:root:Iteration 58, error 28602.3236872
INFO:root:Iteration 59, error 27484.733563
INFO:root:Iteration 60, error 26411.6140152
INFO:root:Iteration 61, error 25381.1638462
INFO:root:Iteration 62, error 24391.6560593
INFO:root:Iteration 63, error 23441.4347536
INFO:root:Iteration 64, error 22528.9121493
INFO:root:Iteration 65, error 21652.5657406
INFO:root:Iteration 66, error 20810.9355687
INFO:root:Iteration 67, error 20002.6216107
INFO:root:Iteration 68, error 19226.2812788
INFO:root:Iteration 69, error 18480.6270261
INFO:root:Iteration 70, error 17764.424053
INFO:root:Iteration 71, error 17076.4881106
INFO:root:Iteration 72, error 16415.6833981
INFO:root:Iteration 73, error 15780.9205471
INFO:root:Iteration 74, error 15171.1546931
INFO:root:Iteration 75, error 14585.3836265
INFO:root:Iteration 76, error 14022.6460231
INFO:root:Iteration 77, error 13482.0197478
INFO:root:Iteration 78, error 12962.6202312
INFO:root:Iteration 79, error 12463.5989129
INFO:root:Iteration 80, error 11984.141752
INFO:root:Iteration 81, error 11523.4677984
INFO:root:Iteration 82, error 11080.827826
INFO:root:Iteration 83, error 10655.5030215
INFO:root:Iteration 84, error 10246.8037297
INFO:root:Iteration 85, error 9854.06825033
INFO:root:Iteration 86, error 9476.66168595
INFO:root:Iteration 87, error 9113.97483774
INFO:root:Iteration 88, error 8765.42314772
INFO:root:Iteration 89, error 8430.44568504
INFO:root:Iteration 90, error 8108.50417479
INFO:root:Iteration 91, error 7799.08206723
INFO:root:Iteration 92, error 7501.68364598
INFO:root:Iteration 93, error 7215.83317336
INFO:root:Iteration 94, error 6941.07407139
INFO:root:Iteration 95, error 6676.96813683
INFO:root:Iteration 96, error 6423.09478903
INFO:root:Iteration 97, error 6179.05034894
INFO:root:Iteration 98, error 5944.4473482
INFO:root:Iteration 99, error 5718.91386688
INFO:root:Iteration 100, error 5502.09289874
INFO:root:Iteration 101, error 5293.64174278
INFO:root:Iteration 102, error 5093.23142015
INFO:root:Iteration 103, error 4900.54611506
INFO:root:Iteration 104, error 4715.28263893
INFO:root:Iteration 105, error 4537.14991677
INFO:root:Iteration 106, error 4365.86849465
INFO:root:Iteration 107, error 4201.17006767
INFO:root:Iteration 108, error 4042.79702736
INFO:root:Iteration 109, error 3890.50202776
INFO:root:Iteration 110, error 3744.04756941
INFO:root:Iteration 111, error 3603.20560049
INFO:root:Iteration 112, error 3467.75713437
INFO:root:Iteration 113, error 3337.49188293
INFO:root:Iteration 114, error 3212.20790496
INFO:root:Iteration 115, error 3091.71126897
INFO:root:Iteration 116, error 2975.81572989
INFO:root:Iteration 117, error 2864.34241906
INFO:root:Iteration 118, error 2757.11954688
INFO:root:Iteration 119, error 2653.9821177
INFO:root:Iteration 120, error 2554.77165636
INFO:root:Iteration 121, error 2459.33594592
INFO:root:Iteration 122, error 2367.52877619
INFO:root:Iteration 123, error 2279.20970241
INFO:root:Iteration 124, error 2194.24381392
INFO:root:Iteration 125, error 2112.50151216
INFO:root:Iteration 126, error 2033.85829785
INFO:root:Iteration 127, error 1958.19456672
INFO:root:Iteration 128, error 1885.39541366
INFO:root:Iteration 129, error 1815.35044477
INFO:root:Iteration 130, error 1747.95359712
INFO:root:Iteration 131, error 1683.10296578
INFO:root:Iteration 132, error 1620.70063792
INFO:root:Iteration 133, error 1560.65253363
INFO:root:Iteration 134, error 1502.86825319
INFO:root:Iteration 135, error 1447.26093052
INFO:root:Iteration 136, error 1393.74709263
INFO:root:Iteration 137, error 1342.24652465
INFO:root:Iteration 138, error 1292.68214046
INFO:root:Iteration 139, error 1244.97985841
INFO:root:Iteration 140, error 1199.06848215
INFO:root:Iteration 141, error 1154.87958624
INFO:root:Iteration 142, error 1112.3474064
INFO:root:Iteration 143, error 1071.40873413
INFO:root:Iteration 144, error 1032.00281562
INFO:root:Iteration 145, error 994.071254742
INFO:root:Iteration 146, error 957.557919881
INFO:root:Iteration 147, error 922.408854576
INFO:root:Iteration 148, error 888.572191714
INFO:root:Iteration 149, error 855.998071183
INFO:root:Iteration 150, error 824.638560817
INFO:root:Iteration 151, error 794.447580521
INFO:root:Iteration 152, error 765.380829428
INFO:root:Iteration 153, error 737.395715971
INFO:root:Iteration 154, error 710.451290761
INFO:root:Iteration 155, error 684.508182131
INFO:root:Iteration 156, error 659.528534272
INFO:root:Iteration 157, error 635.475947826
INFO:root:Iteration 158, error 612.315422855
INFO:root:Iteration 159, error 590.013304076
INFO:root:Iteration 160, error 568.537228286
INFO:root:Iteration 161, error 547.85607387
INFO:root:Iteration 162, error 527.939912325
INFO:root:Iteration 163, error 508.759961703
INFO:root:Iteration 164, error 490.288541909
INFO:root:Iteration 165, error 472.499031769
INFO:root:Iteration 166, error 455.365827802
INFO:root:Iteration 167, error 438.864304626
INFO:root:Iteration 168, error 422.97077693
INFO:root:Iteration 169, error 407.662462951
INFO:root:Iteration 170, error 392.917449397
INFO:root:Iteration 171, error 378.714657755
INFO:root:Iteration 172, error 365.033811928
INFO:root:Iteration 173, error 351.855407151
INFO:root:Iteration 174, error 339.160680129
INFO:root:Iteration 175, error 326.931580358
INFO:root:Iteration 176, error 315.150742565
INFO:root:Iteration 177, error 303.801460243
INFO:root:Iteration 178, error 292.867660221
INFO:root:Iteration 179, error 282.33387823
INFO:root:Iteration 180, error 272.185235437
INFO:root:Iteration 181, error 262.407415889
INFO:root:Iteration 182, error 252.98664485
INFO:root:Iteration 183, error 243.909667982
INFO:root:Iteration 184, error 235.163731343
INFO:root:Iteration 185, error 226.736562163
INFO:root:Iteration 186, error 218.61635038
INFO:root:Iteration 187, error 210.791730886
INFO:root:Iteration 188, error 203.251766478
INFO:root:Iteration 189, error 195.985931464
INFO:root:Iteration 190, error 188.984095914
INFO:root:Iteration 191, error 182.236510521
INFO:root:Iteration 192, error 175.733792054
INFO:root:Iteration 193, error 169.466909372
INFO:root:Iteration 194, error 163.427169992
INFO:root:Iteration 195, error 157.606207164
INFO:root:Iteration 196, error 151.995967459
INFO:root:Iteration 197, error 146.588698834
INFO:root:Iteration 198, error 141.376939163
INFO:root:Iteration 199, error 136.353505202
INFO:root:Iteration 200, error 131.511481998
INFO:root:Iteration 201, error 126.844212689
INFO:root:Iteration 202, error 122.345288715
INFO:root:Iteration 203, error 118.008540393
INFO:root:Iteration 204, error 113.828027865
INFO:root:Iteration 205, error 109.798032392
INFO:root:Iteration 206, error 105.913047984
INFO:root:Iteration 207, error 102.167773349
INFO:root:Iteration 208, error 98.5571041592
INFO:root:Iteration 209, error 95.0761256058
INFO:root:Iteration 210, error 91.7201052468
INFO:root:Iteration 211, error 88.4844861264
INFO:root:Iteration 212, error 85.3648801586
INFO:root:Iteration 213, error 82.357061765
INFO:root:Iteration 214, error 79.4569617565
INFO:root:Iteration 215, error 76.660661449
INFO:root:Iteration 216, error 73.9643870043
INFO:root:Iteration 217, error 71.3645039875
INFO:root:Iteration 218, error 68.8575121326
INFO:root:Iteration 219, error 66.4400403076
INFO:root:Iteration 220, error 64.1088416721
INFO:root:Iteration 221, error 61.8607890192
INFO:root:Iteration 222, error 59.6928702955
INFO:root:Iteration 223, error 57.602184291
INFO:root:Iteration 224, error 55.5859364937
INFO:root:Iteration 225, error 53.6414351014
INFO:root:Iteration 226, error 51.7660871854
INFO:root:Iteration 227, error 49.9573949994
INFO:root:Iteration 228, error 48.2129524293
INFO:root:Iteration 229, error 46.5304415769
INFO:root:Iteration 230, error 44.9076294737
INFO:root:Iteration 231, error 43.3423649183
INFO:root:Iteration 232, error 41.8325754347
INFO:root:Iteration 233, error 40.3762643447
INFO:root:Iteration 234, error 38.9715079514
INFO:root:Iteration 235, error 37.6164528288
INFO:root:Iteration 236, error 36.3093132144
INFO:root:Iteration 237, error 35.048368499
INFO:root:Iteration 238, error 33.8319608124
INFO:root:Iteration 239, error 32.6584926994
INFO:root:Iteration 240, error 31.5264248828
INFO:root:Iteration 241, error 30.434274112
INFO:root:Iteration 242, error 29.380611091
INFO:root:Iteration 243, error 28.3640584851
INFO:root:Iteration 244, error 27.3832890024
INFO:root:Iteration 245, error 26.4370235466
INFO:root:Iteration 246, error 25.5240294405
INFO:root:Iteration 247, error 24.6431187141
INFO:root:Iteration 248, error 23.7931464589
INFO:root:Iteration 249, error 22.9730092422
INFO:root:Iteration 250, error 22.1816435812
INFO:root:Iteration 251, error 21.4180244749
INFO:root:Iteration 252, error 20.6811639894
INFO:root:Iteration 253, error 19.9701098974
INFO:root:Iteration 254, error 19.2839443675
INFO:root:Iteration 255, error 18.6217827029
INFO:root:Iteration 256, error 17.9827721266
INFO:root:Iteration 257, error 17.3660906127
INFO:root:Iteration 258, error 16.7709457599
INFO:root:Iteration 259, error 16.1965737085
INFO:root:Iteration 260, error 15.6422380958
INFO:root:Iteration 261, error 15.1072290521
INFO:root:Iteration 262, error 14.5908622328
INFO:root:Iteration 263, error 14.0924778864
INFO:root:Iteration 264, error 13.6114399582
INFO:root:Iteration 265, error 13.1471352255
INFO:root:Iteration 266, error 12.6989724663
INFO:root:Iteration 267, error 12.2663816581
INFO:root:Iteration 268, error 11.8488132061
INFO:root:Iteration 269, error 11.4457372006
INFO:root:Iteration 270, error 11.056642701
INFO:root:Iteration 271, error 10.6810370472
INFO:root:Iteration 272, error 10.3184451955
INFO:root:Iteration 273, error 9.96840907941
INFO:root:Iteration 274, error 9.63048699407
INFO:root:Iteration 275, error 9.30425300313
INFO:root:Iteration 276, error 8.98929636756
INFO:root:Iteration 277, error 8.68522099544
INFO:root:Iteration 278, error 8.39164491201
INFO:root:Iteration 279, error 8.10819974913
INFO:root:Iteration 280, error 7.83453025352
INFO:root:Iteration 281, error 7.57029381301
INFO:root:Iteration 282, error 7.31516000018
INFO:root:Iteration 283, error 7.06881013275
INFO:root:Iteration 284, error 6.83093684998
INFO:root:Iteration 285, error 6.60124370469
INFO:root:Iteration 286, error 6.37944477011
INFO:root:Iteration 287, error 6.16526426112
INFO:root:Iteration 288, error 5.95843616939
INFO:root:Iteration 289, error 5.75870391175
INFO:root:Iteration 290, error 5.56581999147
INFO:root:Iteration 291, error 5.37954567183
INFO:root:Iteration 292, error 5.19965066164
INFO:root:Iteration 293, error 5.02591281217
INFO:root:Iteration 294, error 4.85811782518
INFO:root:Iteration 295, error 4.69605897147
INFO:root:Iteration 296, error 4.53953681977
INFO:root:Iteration 297, error 4.38835897544
INFO:root:Iteration 298, error 4.24233982862
INFO:root:Iteration 299, error 4.10130031162
INFO:root:Iteration 300, error 3.965067665
INFO:root:Iteration 301, error 3.83347521222
INFO:root:Iteration 302, error 3.70636214242
INFO:root:Iteration 303, error 3.58357330107
INFO:root:Iteration 304, error 3.4649589882
INFO:root:Iteration 305, error 3.35037476394
INFO:root:Iteration 306, error 3.23968126106
INFO:root:Iteration 307, error 3.13274400434
INFO:root:Iteration 308, error 3.0294332364
INFO:root:Iteration 309, error 2.92962374987
INFO:root:Iteration 310, error 2.83319472561
INFO:root:Iteration 311, error 2.7400295767
INFO:root:Iteration 312, error 2.65001579815
INFO:root:Iteration 313, error 2.56304482196
INFO:root:Iteration 314, error 2.4790118774
INFO:root:Iteration 315, error 2.39781585634
INFO:root:Iteration 316, error 2.31935918344
INFO:root:Iteration 317, error 2.24354769092
INFO:root:Iteration 318, error 2.17029049794
INFO:root:Iteration 319, error 2.09949989426
INFO:root:Iteration 320, error 2.03109122803
INFO:root:Iteration 321, error 1.9649827977
INFO:root:Iteration 322, error 1.90109574771
INFO:root:Iteration 323, error 1.839353968
INFO:root:Iteration 324, error 1.77968399705
INFO:root:Iteration 325, error 1.72201492843
INFO:root:Iteration 326, error 1.66627832069
INFO:root:Iteration 327, error 1.61240811046
INFO:root:Iteration 328, error 1.56034052864
INFO:root:Iteration 329, error 1.51001401964
INFO:root:Iteration 330, error 1.46136916343
INFO:root:Iteration 331, error 1.41434860044
INFO:root:Iteration 332, error 1.36889695908
INFO:root:Iteration 333, error 1.32496078586
INFO:root:Iteration 334, error 1.28248847806
INFO:root:Iteration 335, error 1.24143021867
INFO:root:Iteration 336, error 1.20173791381
INFO:root:Iteration 337, error 1.16336513219
INFO:root:Iteration 338, error 1.12626704689
INFO:root:Iteration 339, error 1.09040037912
INFO:root:Iteration 340, error 1.05572334397
INFO:root:Iteration 341, error 1.02219559815
INFO:root:Iteration 342, error 0.989778189508
INFO:root:Iteration 343, error 0.958433508403
INFO:root:Iteration 344, error 0.928125240758
INFO:root:Iteration 345, error 0.898818322802
INFO:root:Iteration 346, error 0.870478897396
INFO:root:Iteration 347, error 0.843074271918
INFO:root:Iteration 348, error 0.816572877631
INFO:root:Iteration 349, error 0.790944230493
INFO:root:Iteration 350, error 0.766158893345
INFO:root:Iteration 351, error 0.742188439437
INFO:root:Iteration 352, error 0.719005417251
INFO:root:Iteration 353, error 0.696583316546
INFO:root:Iteration 354, error 0.674896535622
INFO:root:Iteration 355, error 0.65392034972
INFO:root:Iteration 356, error 0.633630880551
INFO:root:Iteration 357, error 0.614005066883
INFO:root:Iteration 358, error 0.595020636177
INFO:root:Iteration 359, error 0.576656077211
INFO:root:Iteration 360, error 0.558890613674
INFO:root:Iteration 361, error 0.541704178683
INFO:root:Iteration 362, error 0.525077390197
INFO:root:Iteration 363, error 0.508991527298
INFO:root:Iteration 364, error 0.493428507297
INFO:root:Iteration 365, error 0.47837086365
INFO:root:Iteration 366, error 0.463801724647
INFO:root:Iteration 367, error 0.449704792845
INFO:root:Iteration 368, error 0.436064325225
INFO:root:Iteration 369, error 0.422865114041
INFO:root:Iteration 370, error 0.410092468344
INFO:root:Iteration 371, error 0.397732196145
INFO:root:Iteration 372, error 0.385770587209
INFO:root:Iteration 373, error 0.374194396448
INFO:root:Iteration 374, error 0.36299082789
INFO:root:Iteration 375, error 0.352147519215
INFO:root:Iteration 376, error 0.341652526826
INFO:root:Iteration 377, error 0.331494311441
INFO:root:Iteration 378, error 0.321661724191
INFO:root:Iteration 379, error 0.312143993196
INFO:root:Iteration 380, error 0.302930710617
INFO:root:Iteration 381, error 0.294011820153
INFO:root:Iteration 382, error 0.285377604974
INFO:root:Iteration 383, error 0.277018676076
INFO:root:Iteration 384, error 0.268925961039
INFO:root:Iteration 385, error 0.261090693175
INFO:root:Iteration 386, error 0.253504401058
INFO:root:Iteration 387, error 0.24615889841
INFO:root:Iteration 388, error 0.239046274346
INFO:root:Iteration 389, error 0.232158883949
INFO:root:Iteration 390, error 0.225489339183
INFO:root:Iteration 391, error 0.219030500108
INFO:root:Iteration 392, error 0.212775466407
INFO:root:Iteration 393, error 0.20671756921
INFO:root:Iteration 394, error 0.200850363192
INFO:root:Iteration 395, error 0.195167618947
INFO:root:Iteration 396, error 0.189663315634
INFO:root:Iteration 397, error 0.184331633864
INFO:root:Iteration 398, error 0.179166948845
INFO:root:Iteration 399, error 0.174163823753
INFO:root:Iteration 400, error 0.169317003342
INFO:root:Iteration 401, error 0.164621407765
INFO:root:Iteration 402, error 0.160072126617
INFO:root:Iteration 403, error 0.155664413176
INFO:root:Iteration 404, error 0.151393678847
INFO:root:Iteration 405, error 0.147255487795
INFO:root:Iteration 406, error 0.143245551766
INFO:root:Iteration 407, error 0.139359725079
INFO:root:Iteration 408, error 0.135593999803
INFO:root:Iteration 409, error 0.131944501082
INFO:root:Iteration 410, error 0.12840748264
INFO:root:Iteration 411, error 0.124979322425
INFO:root:Iteration 412, error 0.121656518412
INFO:root:Iteration 413, error 0.118435684544
INFO:root:Iteration 414, error 0.115313546817
INFO:root:Iteration 415, error 0.112286939497
INFO:root:Iteration 416, error 0.109352801465
INFO:root:Iteration 417, error 0.106508172691
INFO:root:Iteration 418, error 0.103750190825
INFO:root:Iteration 419, error 0.101076087908
INFO:root:Iteration 420, error 0.0984831871929
INFO:root:Iteration 421, error 0.0959689000759
INFO:root:Iteration 422, error 0.093530723131
INFO:root:Iteration 423, error 0.0911662352474
INFO:root:Iteration 424, error 0.088873094864
INFO:root:Iteration 425, error 0.0866490372984
INFO:root:Iteration 426, error 0.0844918721665
INFO:root:Iteration 427, error 0.0823994808913
INFO:root:Iteration 428, error 0.0803698142951
INFO:root:Iteration 429, error 0.0784008902751
INFO:root:Iteration 430, error 0.0764907915569
INFO:root:Iteration 431, error 0.0746376635256
INFO:root:Iteration 432, error 0.0728397121299
INFO:root:Iteration 433, error 0.071095201858
INFO:root:Iteration 434, error 0.0694024537814
INFO:root:Iteration 435, error 0.0677598436667
INFO:root:Iteration 436, error 0.0661658001497
INFO:root:Iteration 437, error 0.0646188029731
INFO:root:Iteration 438, error 0.0631173812825
INFO:root:Iteration 439, error 0.0616601119817
INFO:root:Iteration 440, error 0.0602456181424
INFO:root:Iteration 441, error 0.0588725674684
INFO:root:Iteration 442, error 0.057539670812
INFO:root:Iteration 443, error 0.0562456807401
INFO:root:Iteration 444, error 0.0549893901491
INFO:root:Iteration 445, error 0.0537696309264
INFO:root:Iteration 446, error 0.0525852726576
INFO:root:Iteration 447, error 0.0514352213769
INFO:root:Iteration 448, error 0.0503184183595
INFO:root:Iteration 449, error 0.0492338389559
INFO:root:Iteration 450, error 0.0481804914638
INFO:root:Iteration 451, error 0.0471574160394
INFO:root:Iteration 452, error 0.0461636836449
INFO:root:Iteration 453, error 0.0451983950313
INFO:root:Iteration 454, error 0.0442606797556
INFO:root:Iteration 455, error 0.0433496952312
INFO:root:Iteration 456, error 0.0424646258097
INFO:root:Iteration 457, error 0.0416046818944
INFO:root:Iteration 458, error 0.0407690990827
INFO:root:Iteration 459, error 0.0399571373379
INFO:root:Iteration 460, error 0.0391680801887
INFO:root:Iteration 461, error 0.0384012339549
INFO:root:Iteration 462, error 0.0376559270002
INFO:root:Iteration 463, error 0.0369315090091
INFO:root:Iteration 464, error 0.0362273502883
INFO:root:Iteration 465, error 0.0355428410915
INFO:root:Iteration 466, error 0.034877390967
INFO:root:Iteration 467, error 0.0342304281267
INFO:root:Iteration 468, error 0.0336013988364
INFO:root:Iteration 469, error 0.0329897668262
INFO:root:Iteration 470, error 0.0323950127215
INFO:root:Iteration 471, error 0.0318166334915
INFO:root:Iteration 472, error 0.0312541419174
INFO:root:Iteration 473, error 0.0307070660775
INFO:root:Iteration 474, error 0.03017494885
INFO:root:Iteration 475, error 0.0296573474318
INFO:root:Iteration 476, error 0.0291538328739
INFO:root:Iteration 477, error 0.0286639896316
INFO:root:Iteration 478, error 0.0281874151304
INFO:root:Iteration 479, error 0.0277237193455
INFO:root:Iteration 480, error 0.027272524396
INFO:root:Iteration 481, error 0.0268334641518
INFO:root:Iteration 482, error 0.0264061838545
INFO:root:Iteration 483, error 0.0259903397496
INFO:root:Iteration 484, error 0.0255855987323
INFO:root:Iteration 485, error 0.0251916380039
INFO:root:Iteration 486, error 0.02480814474
INFO:root:Iteration 487, error 0.0244348157695
INFO:root:Iteration 488, error 0.0240713572647
INFO:root:Iteration 489, error 0.023717484441
INFO:root:Iteration 490, error 0.0233729212666
INFO:root:Iteration 491, error 0.0230374001825
INFO:root:Iteration 492, error 0.0227106618304
INFO:root:Iteration 493, error 0.0223924547909
INFO:root:Iteration 494, error 0.0220825353295
INFO:root:Iteration 495, error 0.0217806671513
INFO:root:Iteration 496, error 0.0214866211632
INFO:root:Iteration 497, error 0.0212001752452
INFO:root:Iteration 498, error 0.0209211140273
INFO:root:Iteration 499, error 0.0206492286758
INFO:root:Iteration 500, error 0.0203843166848
INFO:root:Iteration 501, error 0.0201261816756
INFO:root:Iteration 502, error 0.0198746332024
INFO:root:Iteration 503, error 0.0196294865643
INFO:root:Iteration 504, error 0.0193905626234
INFO:root:Iteration 505, error 0.019157687629
INFO:root:Iteration 506, error 0.0189306930472
INFO:root:Iteration 507, error 0.0187094153967
INFO:root:Iteration 508, error 0.018493696089
INFO:root:Iteration 509, error 0.0182833812751
INFO:root:Iteration 510, error 0.0180783216958
INFO:root:Iteration 511, error 0.0178783725375
INFO:root:Iteration 512, error 0.0176833932934
INFO:root:Iteration 513, error 0.0174932476277
INFO:root:Iteration 514, error 0.0173078032452
INFO:root:Iteration 515, error 0.0171269317655
INFO:root:Iteration 516, error 0.0169505085999
INFO:root:Iteration 517, error 0.0167784128336
INFO:root:Iteration 518, error 0.0166105271111
INFO:root:Iteration 519, error 0.0164467375252
INFO:root:Iteration 520, error 0.0162869335101
INFO:root:Iteration 521, error 0.0161310077375
INFO:root:Iteration 522, error 0.0159788560161
INFO:root:Iteration 523, error 0.0158303771947
INFO:root:Iteration 524, error 0.0156854730677
INFO:root:Iteration 525, error 0.0155440482845
INFO:root:Iteration 526, error 0.0154060102612
INFO:root:Iteration 527, error 0.0152712690954
INFO:root:Iteration 528, error 0.0151397374837
INFO:root:Iteration 529, error 0.0150113306415
INFO:root:Iteration 530, error 0.0148859662261
INFO:root:Iteration 531, error 0.0147635642615
INFO:root:Iteration 532, error 0.0146440470663
INFO:root:Iteration 533, error 0.0145273391832
INFO:root:Iteration 534, error 0.0144133673111
INFO:root:Iteration 535, error 0.0143020602396
INFO:root:Iteration 536, error 0.0141933487852
INFO:root:Iteration 537, error 0.0140871657296
INFO:root:Iteration 538, error 0.0139834457601
INFO:root:Iteration 539, error 0.0138821254119
INFO:root:Iteration 540, error 0.013783143012
INFO:root:Convergence has reached.
INFO:root: Theta: [ 4.94922071e-01 2.14346969e-03 5.31508178e+01 3.66771272e+01
3.12461022e-03 7.57801573e-04 3.58278589e+01 7.95279113e+01
8.15168075e+01 2.03225663e+01 2.55731805e-03 1.16738111e-03
2.62955206e+01 8.84066857e+01 -8.01413390e-03 -3.56965648e-03
8.91129128e+01 7.86043735e+01 6.96327071e-04 5.98050806e-04
9.26157265e+01 9.05855280e+01 -5.56224628e-03 4.55011115e+01
9.38630195e+01 6.74888522e+01 6.51573402e-03 6.86813275e+01
4.04983264e+00 4.72027158e+01 4.61015001e+01 -2.98167290e-03
7.90746829e+01 -1.66327293e-03 6.28777125e+01 3.38121680e+01
4.42202730e+01 5.13617027e+01 3.10409144e+01 7.13438631e+01
-1.68145560e-03 2.10592750e+01 5.00733013e-03 5.34594834e+01
3.73908590e+01 9.14657524e+01 3.41603853e+01 5.39635771e-03
8.46111773e+01 7.69936639e+01 7.05131681e+01 2.85871128e+01
3.90311487e+00 7.43855765e+01 5.90477867e+01 7.79830513e+01
9.25765818e+00 6.32280230e+01 7.54680253e+01 3.15762631e+00
1.11061336e+01 7.04273563e-04 8.32692286e+01 6.70682180e-03
4.96692553e+01 2.34871459e-04 5.83943728e+00 5.28387578e+01
5.19788886e+01 4.07084353e+01 -2.37786720e-04 9.87434651e+01
-5.54278751e-03 8.94609147e+01 9.31685555e+00 7.32142614e+01
1.04732080e+01 5.46508879e+01 3.92449926e+01 6.07645602e+01
9.14509925e+01 4.97697935e+01 7.71759637e-01 8.62605444e+01
-1.45867627e-04 8.60498663e+01 9.27388109e+01 -5.26542950e-04
1.35249194e-03 7.18842341e+01 5.20803642e+01 9.45029341e+01
-1.11203588e-03 9.85335533e+01 8.35275780e+01 2.83145780e+01
7.33046335e+01 3.45493471e+01 5.85581028e+01 5.57141087e+01
9.11651922e+01]
('regression mse', 0.014299757949575767)
In [7]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
In [8]:
X, y = make_regression(n_samples=100, n_features=2,
n_informative=75, n_targets=1, noise=0.05,
random_state=1928, bias=0.5)
In [9]:
X_trans = np.transpose(X)
[X_trans.shape, y.shape]
Out[9]:
[(2, 100), (100,)]
In [10]:
model = LinearRegression(lr=0.01, max_iters=200000, penalty='l2', C=0.03)
model.fit(X, y)
y_predict = model.predict(X)
print('regression mse', mean_squared_error(y, y_predict))
INFO:root:Iteration 1, error 4632.36675231
INFO:root:Iteration 2, error 4404.296067
INFO:root:Iteration 3, error 4187.54428294
INFO:root:Iteration 4, error 3981.54619711
INFO:root:Iteration 5, error 3785.76496216
INFO:root:Iteration 6, error 3599.69065873
INFO:root:Iteration 7, error 3422.83893997
INFO:root:Iteration 8, error 3254.7497443
INFO:root:Iteration 9, error 3094.98607328
INFO:root:Iteration 10, error 2943.13283111
INFO:root:Iteration 11, error 2798.79572266
INFO:root:Iteration 12, error 2661.60020715
INFO:root:Iteration 13, error 2531.1905046
INFO:root:Iteration 14, error 2407.22865237
INFO:root:Iteration 15, error 2289.39360934
INFO:root:Iteration 16, error 2177.38040518
INFO:root:Iteration 17, error 2070.89933266
INFO:root:Iteration 18, error 1969.67518053
INFO:root:Iteration 19, error 1873.44650515
INFO:root:Iteration 20, error 1781.96493886
INFO:root:Iteration 21, error 1694.99453313
INFO:root:Iteration 22, error 1612.31113491
INFO:root:Iteration 23, error 1533.70179428
INFO:root:Iteration 24, error 1458.96420208
INFO:root:Iteration 25, error 1387.90615575
INFO:root:Iteration 26, error 1320.34505216
INFO:root:Iteration 27, error 1256.10740593
INFO:root:Iteration 28, error 1195.02839202
INFO:root:Iteration 29, error 1136.95141135
INFO:root:Iteration 30, error 1081.7276783
INFO:root:Iteration 31, error 1029.21582893
INFO:root:Iteration 32, error 979.281548965
INFO:root:Iteration 33, error 931.797220475
INFO:root:Iteration 34, error 886.641586321
INFO:root:Iteration 35, error 843.699431499
INFO:root:Iteration 36, error 802.8612805
INFO:root:Iteration 37, error 764.023109892
INFO:root:Iteration 38, error 727.086075348
INFO:root:Iteration 39, error 691.956252405
INFO:root:Iteration 40, error 658.544390243
INFO:root:Iteration 41, error 626.765677843
INFO:root:Iteration 42, error 596.539521896
INFO:root:Iteration 43, error 567.789335865
INFO:root:Iteration 44, error 540.442339641
INFO:root:Iteration 45, error 514.429369267
INFO:root:Iteration 46, error 489.684696209
INFO:root:Iteration 47, error 466.145855702
INFO:root:Iteration 48, error 443.753483713
INFO:root:Iteration 49, error 422.451162085
INFO:root:Iteration 50, error 402.185271451
INFO:root:Iteration 51, error 382.904851524
INFO:root:Iteration 52, error 364.5614684
INFO:root:Iteration 53, error 347.109088508
INFO:root:Iteration 54, error 330.503958884
INFO:root:Iteration 55, error 314.704493448
INFO:root:Iteration 56, error 299.671164976
INFO:root:Iteration 57, error 285.366402486
INFO:root:Iteration 58, error 271.754493766
INFO:root:Iteration 59, error 258.801492787
INFO:root:Iteration 60, error 246.475131742
INFO:root:Iteration 61, error 234.7447375
INFO:root:Iteration 62, error 223.581152237
INFO:root:Iteration 63, error 212.956658036
INFO:root:Iteration 64, error 202.844905265
INFO:root:Iteration 65, error 193.220844536
INFO:root:Iteration 66, error 184.060662063
INFO:root:Iteration 67, error 175.341718255
INFO:root:Iteration 68, error 167.04248938
INFO:root:Iteration 69, error 159.142512143
INFO:root:Iteration 70, error 151.622331028
INFO:root:Iteration 71, error 144.463448283
INFO:root:Iteration 72, error 137.648276386
INFO:root:Iteration 73, error 131.160092899
INFO:root:Iteration 74, error 124.982997568
INFO:root:Iteration 75, error 119.101871563
INFO:root:Iteration 76, error 113.502338757
INFO:root:Iteration 77, error 108.17072893
INFO:root:Iteration 78, error 103.094042812
INFO:root:Iteration 79, error 98.2599188693
INFO:root:Iteration 80, error 93.6566017396
INFO:root:Iteration 81, error 89.2729122485
INFO:root:Iteration 82, error 85.0982189133
INFO:root:Iteration 83, error 81.1224108682
INFO:root:Iteration 84, error 77.335872137
INFO:root:Iteration 85, error 73.729457186
INFO:root:Iteration 86, error 70.2944676937
INFO:root:Iteration 87, error 67.0226304753
INFO:root:Iteration 88, error 63.9060765055
INFO:root:Iteration 89, error 60.9373209837
INFO:root:Iteration 90, error 58.1092443902
INFO:root:Iteration 91, error 55.4150744831
INFO:root:Iteration 92, error 52.8483691899
INFO:root:Iteration 93, error 50.4030003479
INFO:root:Iteration 94, error 48.073138252
INFO:root:Iteration 95, error 45.8532369691
INFO:root:Iteration 96, error 43.7380203812
INFO:root:Iteration 97, error 41.7224689201
INFO:root:Iteration 98, error 39.8018069598
INFO:root:Iteration 99, error 37.971490834
INFO:root:Iteration 100, error 36.2271974467
INFO:root:Iteration 101, error 34.5648134472
INFO:root:Iteration 102, error 32.9804249404
INFO:root:Iteration 103, error 31.4703077072
INFO:root:Iteration 104, error 30.0309179073
INFO:root:Iteration 105, error 28.6588832436
INFO:root:Iteration 106, error 27.3509945613
INFO:root:Iteration 107, error 26.1041978639
INFO:root:Iteration 108, error 24.9155867223
INFO:root:Iteration 109, error 23.7823950597
INFO:root:Iteration 110, error 22.7019902918
INFO:root:Iteration 111, error 21.6718668058
INFO:root:Iteration 112, error 20.6896397615
INFO:root:Iteration 113, error 19.7530391969
INFO:root:Iteration 114, error 18.8599044254
INFO:root:Iteration 115, error 18.0081787086
INFO:root:Iteration 116, error 17.1959041907
INFO:root:Iteration 117, error 16.421217084
INFO:root:Iteration 118, error 15.6823430889
INFO:root:Iteration 119, error 14.9775930417
INFO:root:Iteration 120, error 14.3053587741
INFO:root:Iteration 121, error 13.6641091776
INFO:root:Iteration 122, error 13.0523864609
INFO:root:Iteration 123, error 12.4688025905
INFO:root:Iteration 124, error 11.9120359067
INFO:root:Iteration 125, error 11.3808279051
INFO:root:Iteration 126, error 10.8739801763
INFO:root:Iteration 127, error 10.390351495
INFO:root:Iteration 128, error 9.92885505261
INFO:root:Iteration 129, error 9.48845582427
INFO:root:Iteration 130, error 9.06816806561
INFO:root:Iteration 131, error 8.66705293151
INFO:root:Iteration 132, error 8.28421621139
INFO:root:Iteration 133, error 7.91880617525
INFO:root:Iteration 134, error 7.57001152479
INFO:root:Iteration 135, error 7.23705944468
INFO:root:Iteration 136, error 6.91921374884
INFO:root:Iteration 137, error 6.61577311717
INFO:root:Iteration 138, error 6.32606941826
INFO:root:Iteration 139, error 6.04946611373
INFO:root:Iteration 140, error 5.78535674038
INFO:root:Iteration 141, error 5.53316346616
INFO:root:Iteration 142, error 5.29233571638
INFO:root:Iteration 143, error 5.06234886672
INFO:root:Iteration 144, error 4.84270299982
INFO:root:Iteration 145, error 4.63292172211
INFO:root:Iteration 146, error 4.43255103822
INFO:root:Iteration 147, error 4.24115827991
INFO:root:Iteration 148, error 4.05833108693
INFO:root:Iteration 149, error 3.88367643734
INFO:root:Iteration 150, error 3.71681972468
INFO:root:Iteration 151, error 3.55740387993
INFO:root:Iteration 152, error 3.4050885358
INFO:root:Iteration 153, error 3.25954923157
INFO:root:Iteration 154, error 3.12047665623
INFO:root:Iteration 155, error 2.98757592824
INFO:root:Iteration 156, error 2.86056591002
INFO:root:Iteration 157, error 2.73917855548
INFO:root:Iteration 158, error 2.62315828904
INFO:root:Iteration 159, error 2.51226141453
INFO:root:Iteration 160, error 2.40625555253
INFO:root:Iteration 161, error 2.30491910485
INFO:root:Iteration 162, error 2.20804074465
INFO:root:Iteration 163, error 2.11541893115
INFO:root:Iteration 164, error 2.02686144757
INFO:root:Iteration 165, error 1.94218496128
INFO:root:Iteration 166, error 1.86121460505
INFO:root:Iteration 167, error 1.7837835783
INFO:root:Iteration 168, error 1.70973276755
INFO:root:Iteration 169, error 1.63891038488
INFO:root:Iteration 170, error 1.57117162387
INFO:root:Iteration 171, error 1.5063783318
INFO:root:Iteration 172, error 1.44439869762
INFO:root:Iteration 173, error 1.38510695473
INFO:root:Iteration 174, error 1.32838309804
INFO:root:Iteration 175, error 1.27411261436
INFO:root:Iteration 176, error 1.22218622577
INFO:root:Iteration 177, error 1.17249964512
INFO:root:Iteration 178, error 1.12495334315
INFO:root:Iteration 179, error 1.07945232675
INFO:root:Iteration 180, error 1.03590592765
INFO:root:Iteration 181, error 0.994227601185
INFO:root:Iteration 182, error 0.954334734604
INFO:root:Iteration 183, error 0.916148464438
INFO:root:Iteration 184, error 0.879593502515
INFO:root:Iteration 185, error 0.844597970208
INFO:root:Iteration 186, error 0.811093240516
INFO:root:Iteration 187, error 0.779013787594
INFO:root:Iteration 188, error 0.748297043386
INFO:root:Iteration 189, error 0.718883261016
INFO:root:Iteration 190, error 0.690715384614
INFO:root:Iteration 191, error 0.663738925267
INFO:root:Iteration 192, error 0.6379018428
INFO:root:Iteration 193, error 0.613154433119
INFO:root:Iteration 194, error 0.589449220835
INFO:root:Iteration 195, error 0.566740856928
INFO:root:Iteration 196, error 0.544986021209
INFO:root:Iteration 197, error 0.524143329342
INFO:root:Iteration 198, error 0.504173244225
INFO:root:Iteration 199, error 0.485037991506
INFO:root:Iteration 200, error 0.466701479051
INFO:root:Iteration 201, error 0.449129220161
INFO:root:Iteration 202, error 0.432288260378
INFO:root:Iteration 203, error 0.416147107697
INFO:root:Iteration 204, error 0.400675666022
INFO:root:Iteration 205, error 0.38584517172
INFO:root:Iteration 206, error 0.371628133123
INFO:root:Iteration 207, error 0.357998272832
INFO:root:Iteration 208, error 0.344930472706
INFO:root:Iteration 209, error 0.332400721388
INFO:root:Iteration 210, error 0.320386064268
INFO:root:Iteration 211, error 0.308864555755
INFO:root:Iteration 212, error 0.297815213758
INFO:root:Iteration 213, error 0.287217976262
INFO:root:Iteration 214, error 0.277053659911
INFO:root:Iteration 215, error 0.267303920499
INFO:root:Iteration 216, error 0.257951215271
INFO:root:Iteration 217, error 0.24897876697
INFO:root:Iteration 218, error 0.240370529526
INFO:root:Iteration 219, error 0.232111155319
INFO:root:Iteration 220, error 0.22418596395
INFO:root:Iteration 221, error 0.216580912432
INFO:root:Iteration 222, error 0.209282566757
INFO:root:Iteration 223, error 0.202278074749
INFO:root:Iteration 224, error 0.195555140164
INFO:root:Iteration 225, error 0.189101997972
INFO:root:Iteration 226, error 0.182907390764
INFO:root:Iteration 227, error 0.176960546227
INFO:root:Iteration 228, error 0.171251155653
INFO:root:Iteration 229, error 0.165769353415
INFO:root:Iteration 230, error 0.160505697385
INFO:root:Iteration 231, error 0.155451150223
INFO:root:Iteration 232, error 0.150597061532
INFO:root:Iteration 233, error 0.145935150809
INFO:root:Iteration 234, error 0.141457491165
INFO:root:Iteration 235, error 0.137156493788
INFO:root:Iteration 236, error 0.133024893097
INFO:root:Iteration 237, error 0.129055732576
INFO:root:Iteration 238, error 0.125242351233
INFO:root:Iteration 239, error 0.121578370674
INFO:root:Iteration 240, error 0.11805768276
INFO:root:Iteration 241, error 0.114674437812
INFO:root:Iteration 242, error 0.111423033343
INFO:root:Iteration 243, error 0.108298103306
INFO:root:Iteration 244, error 0.105294507803
INFO:root:Iteration 245, error 0.102407323274
INFO:root:Iteration 246, error 0.0996318331084
INFO:root:Iteration 247, error 0.096963518683
INFO:root:Iteration 248, error 0.0943980507942
INFO:root:Iteration 249, error 0.0919312814736
INFO:root:Iteration 250, error 0.0895592361656
INFO:root:Iteration 251, error 0.0872781062531
INFO:root:Iteration 252, error 0.0850842419124
INFO:root:Iteration 253, error 0.0829741452864
INFO:root:Iteration 254, error 0.0809444639575
INFO:root:Iteration 255, error 0.07899198471
INFO:root:Iteration 256, error 0.077113627567
INFO:root:Iteration 257, error 0.0753064400895
INFO:root:Iteration 258, error 0.0735675919272
INFO:root:Iteration 259, error 0.0718943696079
INFO:root:Iteration 260, error 0.0702841715562
INFO:root:Iteration 261, error 0.0687345033297
INFO:root:Iteration 262, error 0.0672429730647
INFO:root:Iteration 263, error 0.0658072871207
INFO:root:Iteration 264, error 0.0644252459148
INFO:root:Iteration 265, error 0.0630947399384
INFO:root:Iteration 266, error 0.0618137459471
INFO:root:Iteration 267, error 0.0605803233166
INFO:root:Iteration 268, error 0.0593926105571
INFO:root:Iteration 269, error 0.0582488219786
INFO:root:Iteration 270, error 0.0571472445015
INFO:root:Iteration 271, error 0.0560862346046
INFO:root:Iteration 272, error 0.0550642154059
INFO:root:Iteration 273, error 0.0540796738692
INFO:root:Iteration 274, error 0.0531311581309
INFO:root:Iteration 275, error 0.0522172749426
INFO:root:Iteration 276, error 0.0513366872237
INFO:root:Iteration 277, error 0.0504881117189
INFO:root:Iteration 278, error 0.0496703167568
INFO:root:Iteration 279, error 0.0488821201043
INFO:root:Iteration 280, error 0.048122386913
INFO:root:Iteration 281, error 0.0473900277536
INFO:root:Iteration 282, error 0.0466839967344
INFO:root:Iteration 283, error 0.0460032896996
INFO:root:Iteration 284, error 0.0453469425051
INFO:root:Iteration 285, error 0.0447140293671
INFO:root:Iteration 286, error 0.0441036612819
INFO:root:Iteration 287, error 0.0435149845112
INFO:root:Iteration 288, error 0.0429471791335
INFO:root:Iteration 289, error 0.0423994576556
INFO:root:Iteration 290, error 0.0418710636834
INFO:root:Iteration 291, error 0.0413612706488
INFO:root:Iteration 292, error 0.0408693805901
INFO:root:Iteration 293, error 0.0403947229844
INFO:root:Iteration 294, error 0.0399366536287
INFO:root:Iteration 295, error 0.0394945535681
INFO:root:Iteration 296, error 0.039067828069
INFO:root:Iteration 297, error 0.0386559056357
INFO:root:Iteration 298, error 0.0382582370681
INFO:root:Iteration 299, error 0.0378742945584
INFO:root:Iteration 300, error 0.0375035708259
INFO:root:Iteration 301, error 0.0371455782883
INFO:root:Iteration 302, error 0.0367998482668
INFO:root:Iteration 303, error 0.0364659302246
INFO:root:Iteration 304, error 0.0361433910375
INFO:root:Iteration 305, error 0.035831814294
INFO:root:Iteration 306, error 0.0355307996253
INFO:root:Iteration 307, error 0.035239962062
INFO:root:Iteration 308, error 0.0349589314188
INFO:root:Iteration 309, error 0.0346873517032
INFO:root:Iteration 310, error 0.0344248805496
INFO:root:Iteration 311, error 0.0341711886763
INFO:root:Iteration 312, error 0.0339259593651
INFO:root:Iteration 313, error 0.0336888879619
INFO:root:Iteration 314, error 0.0334596813983
INFO:root:Iteration 315, error 0.0332380577323
INFO:root:Iteration 316, error 0.0330237457086
INFO:root:Iteration 317, error 0.0328164843356
INFO:root:Iteration 318, error 0.0326160224813
INFO:root:Iteration 319, error 0.0324221184842
INFO:root:Iteration 320, error 0.0322345397812
INFO:root:Iteration 321, error 0.0320530625497
INFO:root:Iteration 322, error 0.0318774713652
INFO:root:Iteration 323, error 0.0317075588719
INFO:root:Iteration 324, error 0.031543125467
INFO:root:Iteration 325, error 0.0313839789985
INFO:root:Iteration 326, error 0.0312299344738
INFO:root:Iteration 327, error 0.0310808137812
INFO:root:Iteration 328, error 0.0309364454223
INFO:root:Iteration 329, error 0.0307966642549
INFO:root:Iteration 330, error 0.030661311247
INFO:root:Iteration 331, error 0.0305302332395
INFO:root:Iteration 332, error 0.0304032827196
INFO:root:Iteration 333, error 0.0302803176027
INFO:root:Iteration 334, error 0.0301612010229
INFO:root:Iteration 335, error 0.0300458011323
INFO:root:Iteration 336, error 0.0299339909082
INFO:root:Iteration 337, error 0.0298256479674
INFO:root:Iteration 338, error 0.0297206543891
INFO:root:Iteration 339, error 0.0296188965433
INFO:root:Iteration 340, error 0.0295202649277
INFO:root:Convergence has reached.
INFO:root: Theta: [ 0.53214566 19.59570789 58.99543373]
('regression mse', 0.029520264927707082)
In [11]:
# adapted from http://stackoverflow.com/a/25628397/200764
# see also http://matplotlib.org/users/colormaps.html
import matplotlib.cm as cmx
import matplotlib.colors as colors
def get_cmap(N):
'''Returns a function that maps each index in 0, 1, ... N-1 to a distinct
RGB color.'''
color_norm = colors.Normalize(vmin=0, vmax=N-1)
scalar_map = cmx.ScalarMappable(norm=color_norm, cmap='rainbow')
def map_index_to_rgb_color(index):
return scalar_map.to_rgba(index)
return map_index_to_rgb_color
In [12]:
from itertools import cycle
def cycolor(N):
cmap = get_cmap(N)
i = 0
while True:
index = i
yield cmap(index)
i = (i + 3) % N
N = 10
cycol=cycolor(N).next
fig=plt.figure()
ax=fig.add_subplot(111)
plt.axis('scaled')
ax.set_xlim([ 0, N])
ax.set_ylim([-0.5, 0.5])
for i in xrange(N):
col = cycol()
rect = plt.Rectangle((i, -0.5), 1, 1, facecolor=col)
ax.add_artist(rect)
ax.set_yticks([])
plt.show()
In [13]:
fig = plt.figure()
ax = fig.add_subplot(111)
for i in xrange(len(X_trans)):
ax.scatter(X_trans[i], y, c=cycol(), label='y%d' % i)
ax.scatter(X_trans[i], y_predict, c=cycol(), label='y_predict%d' % i)
ax.legend()
Out[13]:
<matplotlib.legend.Legend at 0x7f00158fbf50>
In [14]:
is_close = np.isclose(y, y_predict, rtol=0.005)
not_close = np.logical_not(is_close)
is_close
Out[14]:
array([ True, True, True, False, False, True, True, True, True,
True, True, True, True, True, False, False, True, False,
True, True, True, False, False, True, True, True, True,
False, True, True, True, True, False, True, False, True,
False, True, True, True, True, True, True, True, False,
False, True, True, True, False, True, True, True, False,
False, False, True, True, False, True, True, True, True,
True, False, True, True, False, True, True, False, True,
True, False, False, True, False, True, True, True, True,
True, True, True, False, True, False, False, True, True,
True, True, True, True, True, True, True, False, True, True], dtype=bool)
In [15]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(X_trans[0][is_close], X_trans[1][is_close], c=cycol(), s=y[is_close], label='y is close')
ax.scatter(X_trans[0][not_close], X_trans[1][not_close], c=cycol(), s=y[not_close], label='y not close')
ax.legend()
/home/nbuser/anaconda2_501/lib/python2.7/site-packages/matplotlib/collections.py:836: RuntimeWarning: invalid value encountered in sqrt
scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor
Out[15]:
<matplotlib.legend.Legend at 0x7f00137d4450>
In [16]:
fig = plt.figure(figsize=(12, 8))
ax = fig.gca(projection='3d')
ax.scatter(X_trans[0], X_trans[1], y, label='y_train', marker='^', c=cycol())
ax.scatter(X_trans[0], X_trans[1], y_predict - 20, label='y_predict', marker='o', c=cycol())
ax.legend()
[X_trans[0].shape, X_trans[1].shape, y.shape, y_predict.shape]
Out[16]:
[(100,), (100,), (100,), (100,)]
In [17]:
def classification():
# Generate a random binary classification problem.
X, y = make_classification(n_samples=1000, n_features=100,
n_informative=75, random_state=1111,
n_classes=2, class_sep=2.5, )
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,
random_state=1111)
model = LogisticRegression(lr=0.01, max_iters=500, penalty='l1', C=0.01)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print('classification accuracy', accuracy(y_test, predictions))
In [18]:
classification()
INFO:root:Iteration 1, error 9809.11644382
/home/nbuser/anaconda2_501/lib/python2.7/site-packages/autograd/tracer.py:48: RuntimeWarning: overflow encountered in cosh
return f_raw(*args, **kwargs)
/home/nbuser/anaconda2_501/lib/python2.7/site-packages/autograd/numpy/numpy_vjps.py:88: RuntimeWarning: overflow encountered in square
defvjp(anp.tanh, lambda ans, x : lambda g: g / anp.cosh(x) **2)
INFO:root:Iteration 2, error 9226.00393327
INFO:root:Iteration 3, error 8427.55499326
INFO:root:Iteration 4, error 7979.54730174
INFO:root:Iteration 5, error 7425.92568022
INFO:root:Iteration 6, error 7115.06869669
INFO:root:Iteration 7, error 6804.21731035
INFO:root:Iteration 8, error 6286.72645802
INFO:root:Iteration 9, error 5906.20912408
INFO:root:Iteration 10, error 4835.49346268
INFO:root:Iteration 11, error 3628.17651508
INFO:root:Iteration 12, error 2866.75762105
INFO:root:Iteration 13, error 1381.56384936
INFO:root:Iteration 14, error 1554.26332851
INFO:root:Iteration 15, error 1105.2528386
INFO:root:Iteration 16, error 1001.75880264
INFO:root:Iteration 17, error 932.554159039
INFO:root:Iteration 18, error 829.752055014
INFO:root:Iteration 19, error 690.783523873
INFO:root:Iteration 20, error 690.783523873
INFO:root:Convergence has reached.
INFO:root: Theta: [ 0.23566603 2.7296357 4.7956022 -4.83958473 0.27545487
-0.78056608 -1.77853487 -6.12823039 -2.30815794 -2.0842781
-0.33172152 11.11842747 -14.57466373 -7.05675679 2.16486984
1.50808307 6.35661816 4.84312088 -5.82688182 1.3400126
0.65108352 4.68269614 1.37689522 0.75641437 12.00077792
-5.85743875 1.37131971 0.76771866 0.57164638 -6.75591811
-12.67298471 -3.96918584 6.01852644 8.36629321 -4.76625949
1.36312208 -6.51647839 -10.89929268 -1.87797361 1.46375967
-2.55894534 0.26119161 1.01873334 0.98119042 -7.79066367
3.74242474 1.84371356 -2.4005536 -0.28833902 -0.53784624
-6.76080894 -4.75387683 0.14916229 10.36742357 -7.13843422
-0.49636221 -3.85431437 4.80025972 5.78652109 -6.9147896
-0.76397065 -1.02926599 0.57391646 -1.13822616 -0.46362281
-2.11436143 -1.02450423 4.48944062 -1.54137654 3.68867641
1.14488344 -0.55546238 -0.07995588 3.85883021 0.45481992
1.37244476 -4.47366316 5.24318539 0.6642306 -13.09959962
-4.90233945 0.02058884 10.11790232 -0.79230859 -0.49292453
-11.45910867 6.54695195 0.2455275 0.15937865 -12.17170847
-0.03284348 4.24712329 2.62011597 -0.2644913 0.39089953
0.85325067 7.45580962 7.8972504 -11.64427748 6.5212611
-2.85115954]
('classification accuracy', 0.97999999999999998)
In [19]:
X, y = make_classification(n_samples=1000, n_features=2,
n_informative=2, n_redundant=0, random_state=1111,
n_classes=2, class_sep=2.5, )
In [20]:
X_trans = np.transpose(X)
[X_trans.shape, y.shape]
Out[20]:
[(2, 1000), (1000,)]
In [21]:
model = LogisticRegression(lr=0.01, max_iters=1, penalty='l1', C=0.01)
model.fit(X, y)
y_predict = model.predict(X)
print('classification accuracy', accuracy(y, y_predict))
INFO:root:Iteration 1, error 241.776232349
INFO:root: Theta: [ 0.42613801 -5.98440447 42.46385047]
('classification accuracy', 0.99099999999999999)
In [22]:
is_close = np.isclose(y, y_predict)
not_close = np.logical_not(is_close)
In [23]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(X_trans[0][is_close], X_trans[1][is_close], c=cycol(), s=(y[is_close] + 0.1) * 100, label='y is close')
ax.scatter(X_trans[0][not_close], X_trans[1][not_close], c=cycol(), s=(y[not_close] + 0.1) * 100, label='y not close')
ax.legend()
Out[23]:
<matplotlib.legend.Legend at 0x7f0013687610>
In [24]:
fig = plt.figure(figsize=(12, 8))
ax = fig.gca(projection='3d')
# ax.scatter(X_trans[0], X_trans[1], y, label='y_train', marker='^', c=cycol())
ax.scatter(X_trans[0][is_close], X_trans[1][is_close], y_predict[is_close], label='correct y_predict', marker='o', c=cycol())
ax.scatter(X_trans[0][not_close], X_trans[1][not_close], y_predict[not_close], label='not close y_predict', marker='o', c=cycol())
ax.legend()
[X_trans[0].shape, X_trans[1].shape, y.shape, y_predict.shape]
Out[24]:
[(1000,), (1000,), (1000,), (1000,)]
In [25]:
X, y = make_classification(n_samples=1000, n_features=2,
n_informative=2, n_redundant=0, random_state=1111,
n_classes=2, class_sep=2.5, )
In [26]:
X_trans = np.transpose(X)
[X_trans.shape, y.shape]
Out[26]:
[(2, 1000), (1000,)]
In [27]:
model = LogisticRegression(lr=0.01, max_iters=1000, penalty='l1', C=0.01)
model.fit(X, y)
y_predict = model.predict(X)
print('classification accuracy', accuracy(y, y_predict))
INFO:root:Iteration 1, error 8293.28789044
INFO:root:Iteration 2, error 4528.64678798
INFO:root:Iteration 3, error 2489.2515916
INFO:root:Iteration 4, error 1314.79586718
INFO:root:Iteration 5, error 900.203190076
INFO:root:Iteration 6, error 587.168793883
INFO:root:Iteration 7, error 518.222997405
INFO:root:Iteration 8, error 483.550865503
INFO:root:Iteration 9, error 483.550865503
INFO:root:Convergence has reached.
INFO:root: Theta: [ 0.11701526 6.74515699 33.81095895]
('classification accuracy', 0.96499999999999997)
In [28]:
is_close = np.isclose(y, y_predict)
not_close = np.logical_not(is_close)
In [29]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(X_trans[0][is_close], X_trans[1][is_close], c=cycol(), s=(y[is_close] + 0.1) * 100, label='y is close')
ax.scatter(X_trans[0][not_close], X_trans[1][not_close], c=cycol(), s=(y[not_close] + 0.1) * 100, label='y not close')
ax.legend()
Out[29]:
<matplotlib.legend.Legend at 0x7f0013486710>
In [30]:
fig = plt.figure(figsize=(12, 8))
ax = fig.gca(projection='3d')
# ax.scatter(X_trans[0], X_trans[1], y, label='y_train', marker='^', c=cycol())
ax.scatter(X_trans[0][is_close], X_trans[1][is_close], y_predict[is_close], label='correct y_predict', marker='o', c=cycol())
ax.scatter(X_trans[0][not_close], X_trans[1][not_close], y_predict[not_close], label='not close y_predict', marker='o', c=cycol())
ax.legend()
[X_trans[0].shape, X_trans[1].shape, y.shape, y_predict.shape]
Out[30]:
[(1000,), (1000,), (1000,), (1000,)]
In [ ]:
Content source: utensil/julia-playground
Similar notebooks: