update week35
This commit is contained in:
@@ -406,7 +406,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2021</h4></center> <!-- date -->
|
||||
<center><h4>Sep 14, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
|
||||
@@ -459,10 +459,6 @@ X[:,<span style="color: #666666">1</span>] <span style="color: #666666">=</span>
|
||||
X[:,<span style="color: #666666">2</span>] <span style="color: #666666">=</span> x<span style="color: #666666">*</span>x
|
||||
<span style="color: #408080; font-style: italic"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, test_size<span style="color: #666666">=0.2</span>)
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># matrix inversion to find beta</span>
|
||||
OLSbeta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(X_train<span style="color: #666666">.</span>T <span style="color: #666666">@</span> X_train) <span style="color: #666666">@</span> X_train<span style="color: #666666">.</span>T <span style="color: #666666">@</span> y_train
|
||||
|
||||
@@ -406,7 +406,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2021</h4></center> <!-- date -->
|
||||
<center><h4>Sep 14, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Sep 6, 2021</h4></center> <!-- date -->
|
||||
<center><h4>Sep 14, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -3149,10 +3149,6 @@ X[:,<span style="color: #B452CD">1</span>] = x
|
||||
X[:,<span style="color: #B452CD">2</span>] = x*x
|
||||
<span style="color: #228B22"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=<span style="color: #B452CD">0.2</span>)
|
||||
scaler = StandardScaler()
|
||||
scaler.fit(X_train)
|
||||
X_train_scaled = scaler.transform(X_train)
|
||||
X_test_scaled = scaler.transform(X_test)
|
||||
|
||||
<span style="color: #228B22"># matrix inversion to find beta</span>
|
||||
OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
|
||||
|
||||
@@ -325,7 +325,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2021</h4></center> <!-- date -->
|
||||
<center><h4>Sep 14, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -3089,10 +3089,6 @@ X[:,<span style="color: #B452CD">1</span>] = x
|
||||
X[:,<span style="color: #B452CD">2</span>] = x*x
|
||||
<span style="color: #228B22"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=<span style="color: #B452CD">0.2</span>)
|
||||
scaler = StandardScaler()
|
||||
scaler.fit(X_train)
|
||||
X_train_scaled = scaler.transform(X_train)
|
||||
X_test_scaled = scaler.transform(X_test)
|
||||
|
||||
<span style="color: #228B22"># matrix inversion to find beta</span>
|
||||
OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
|
||||
|
||||
@@ -330,7 +330,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 6, 2021</h4></center> <!-- date -->
|
||||
<center><h4>Sep 14, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -3094,10 +3094,6 @@ X[:,<span style="color: #666666">1</span>] <span style="color: #666666">=</span>
|
||||
X[:,<span style="color: #666666">2</span>] <span style="color: #666666">=</span> x<span style="color: #666666">*</span>x
|
||||
<span style="color: #408080; font-style: italic"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, y, test_size<span style="color: #666666">=0.2</span>)
|
||||
scaler <span style="color: #666666">=</span> StandardScaler()
|
||||
scaler<span style="color: #666666">.</span>fit(X_train)
|
||||
X_train_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_train)
|
||||
X_test_scaled <span style="color: #666666">=</span> scaler<span style="color: #666666">.</span>transform(X_test)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># matrix inversion to find beta</span>
|
||||
OLSbeta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(X_train<span style="color: #666666">.</span>T <span style="color: #666666">@</span> X_train) <span style="color: #666666">@</span> X_train<span style="color: #666666">.</span>T <span style="color: #666666">@</span> y_train
|
||||
|
||||
Binary file not shown.
+148
-183
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Sep 6, 2021**\n",
|
||||
"Date: **Sep 14, 2021**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -402,7 +402,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
@@ -953,7 +956,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# matrix inversion to find beta\n",
|
||||
@@ -972,7 +978,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fit = np.linalg.lstsq(X, Energies, rcond =None)[0]\n",
|
||||
@@ -989,7 +998,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"Masses['Eapprox'] = ytilde\n",
|
||||
@@ -1019,7 +1031,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def R2(y_data, y_model):\n",
|
||||
@@ -1036,7 +1051,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(R2(Energies,ytilde))"
|
||||
@@ -1052,7 +1070,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def MSE(y_data,y_model):\n",
|
||||
@@ -1072,7 +1093,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def RelativeError(y_data,y_model):\n",
|
||||
@@ -1107,7 +1131,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
@@ -1160,7 +1187,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# equivalently in numpy\n",
|
||||
@@ -1232,7 +1262,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
@@ -1252,7 +1285,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sklearn.datasets import load_boston\n",
|
||||
@@ -1274,7 +1310,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"boston = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)\n",
|
||||
@@ -1292,7 +1331,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# check for missing values in all the columns\n",
|
||||
@@ -1309,7 +1351,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# set the size of the figure\n",
|
||||
@@ -1330,7 +1375,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# compute the pair wise correlation for all columns \n",
|
||||
@@ -1350,7 +1398,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=(20, 5))\n",
|
||||
@@ -1378,7 +1429,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X = pd.DataFrame(np.c_[boston['LSTAT'], boston['RM']], columns = ['LSTAT','RM'])\n",
|
||||
@@ -1395,7 +1449,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sklearn.model_selection import train_test_split\n",
|
||||
@@ -1419,7 +1476,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sklearn.linear_model import LinearRegression\n",
|
||||
@@ -1458,7 +1518,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# plotting the y_test vs y_pred\n",
|
||||
@@ -1586,7 +1649,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sklearn.linear_model as skl\n",
|
||||
@@ -1656,7 +1722,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"np.random.seed()\n",
|
||||
@@ -1679,7 +1748,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
@@ -1730,7 +1802,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Common imports\n",
|
||||
@@ -2304,31 +2379,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[[ 1. -1.]\n",
|
||||
" [ 1. -1.]]\n",
|
||||
"test U\n",
|
||||
"[[0. 0.]\n",
|
||||
" [0. 0.]]\n",
|
||||
"test VT\n",
|
||||
"[[0. 0.]\n",
|
||||
" [0. 0.]]\n",
|
||||
"[[-0.70710678 -0.70710678]\n",
|
||||
" [-0.70710678 0.70710678]]\n",
|
||||
"[2.00000000e+00 3.35470445e-17]\n",
|
||||
"[[-0.70710678 0.70710678]\n",
|
||||
" [ 0.70710678 0.70710678]]\n",
|
||||
"[[-3.33066907e-16 4.44089210e-16]\n",
|
||||
" [ 0.00000000e+00 2.22044605e-16]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"# SVD inversion\n",
|
||||
@@ -3126,20 +3182,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-0.08839767027751376\n",
|
||||
"3.8294285924714866\n",
|
||||
"[[0.92932998 2.63805954]\n",
|
||||
" [2.63805954 8.61477117]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Importing various packages\n",
|
||||
"import numpy as np\n",
|
||||
@@ -3168,20 +3216,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0.0850713352585812\n",
|
||||
"1.5846946541436007\n",
|
||||
"[[1. 0.63837291]\n",
|
||||
" [0.63837291 1. ]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"n = 100\n",
|
||||
@@ -3223,40 +3263,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[[ 1.09669785 3.23795259]\n",
|
||||
" [-0.22166894 -1.30593687]\n",
|
||||
" [ 0.10192631 0.04245426]\n",
|
||||
" [ 0.82011099 2.55486566]\n",
|
||||
" [ 0.32105408 0.96706068]\n",
|
||||
" [ 0.60361795 1.47703672]\n",
|
||||
" [-1.87875598 -5.24764141]\n",
|
||||
" [ 0.03658513 0.37688017]\n",
|
||||
" [-0.57033315 -1.70980756]\n",
|
||||
" [-0.30923424 -0.39286425]]\n",
|
||||
" 0 1\n",
|
||||
"0 1.096698 3.237953\n",
|
||||
"1 -0.221669 -1.305937\n",
|
||||
"2 0.101926 0.042454\n",
|
||||
"3 0.820111 2.554866\n",
|
||||
"4 0.321054 0.967061\n",
|
||||
"5 0.603618 1.477037\n",
|
||||
"6 -1.878756 -5.247641\n",
|
||||
"7 0.036585 0.376880\n",
|
||||
"8 -0.570333 -1.709808\n",
|
||||
"9 -0.309234 -0.392864\n",
|
||||
" 0 1\n",
|
||||
"0 1.000000 0.990742\n",
|
||||
"1 0.990742 1.000000\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
@@ -3285,49 +3297,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0 1 2 3 4 5 6 7 \\\n",
|
||||
"0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
|
||||
"1 0.0 0.079955 0.083252 0.080480 0.081776 0.083055 0.071202 0.072287 \n",
|
||||
"2 0.0 0.083252 0.087624 0.083966 0.085810 0.087616 0.074576 0.076060 \n",
|
||||
"3 0.0 0.080480 0.083966 0.085125 0.086868 0.088629 0.077734 0.079241 \n",
|
||||
"4 0.0 0.081776 0.085810 0.086868 0.089002 0.091153 0.079679 0.081504 \n",
|
||||
"5 0.0 0.083055 0.087616 0.088629 0.091153 0.093695 0.081663 0.083808 \n",
|
||||
"6 0.0 0.071202 0.074576 0.077734 0.079679 0.081663 0.072591 0.074289 \n",
|
||||
"7 0.0 0.072287 0.076060 0.079241 0.081504 0.083808 0.074289 0.076255 \n",
|
||||
"8 0.0 0.073485 0.077660 0.080883 0.083467 0.086097 0.076120 0.078358 \n",
|
||||
"9 0.0 0.074811 0.079394 0.082672 0.085583 0.088544 0.078096 0.080610 \n",
|
||||
"10 0.0 0.061639 0.064871 0.068789 0.070813 0.072887 0.065314 0.067084 \n",
|
||||
"11 0.0 0.062699 0.066259 0.070225 0.072518 0.074865 0.066904 0.068904 \n",
|
||||
"12 0.0 0.063878 0.067775 0.071800 0.074368 0.076991 0.068629 0.070864 \n",
|
||||
"13 0.0 0.065183 0.069422 0.073519 0.076366 0.079274 0.070494 0.072970 \n",
|
||||
"14 0.0 0.066615 0.071207 0.075386 0.078520 0.081718 0.072505 0.075226 \n",
|
||||
"\n",
|
||||
" 8 9 10 11 12 13 14 \n",
|
||||
"0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
|
||||
"1 0.073485 0.074811 0.061639 0.062699 0.063878 0.065183 0.066615 \n",
|
||||
"2 0.077660 0.079394 0.064871 0.066259 0.067775 0.069422 0.071207 \n",
|
||||
"3 0.080883 0.082672 0.068789 0.070225 0.071800 0.073519 0.075386 \n",
|
||||
"4 0.083467 0.085583 0.070813 0.072518 0.074368 0.076366 0.078520 \n",
|
||||
"5 0.086097 0.088544 0.072887 0.074865 0.076991 0.079274 0.081718 \n",
|
||||
"6 0.076120 0.078096 0.065314 0.066904 0.068629 0.070494 0.072505 \n",
|
||||
"7 0.078358 0.080610 0.067084 0.068904 0.070864 0.072970 0.075226 \n",
|
||||
"8 0.080737 0.083272 0.068979 0.071034 0.073233 0.075583 0.078091 \n",
|
||||
"9 0.083272 0.086096 0.071010 0.073303 0.075747 0.078348 0.081114 \n",
|
||||
"10 0.068979 0.071010 0.059527 0.061166 0.062930 0.064825 0.066855 \n",
|
||||
"11 0.071034 0.073303 0.061166 0.063004 0.064972 0.067075 0.069319 \n",
|
||||
"12 0.073233 0.075747 0.062930 0.064972 0.067148 0.069465 0.071929 \n",
|
||||
"13 0.075583 0.078348 0.064825 0.067075 0.069465 0.072001 0.074691 \n",
|
||||
"14 0.078091 0.081114 0.066855 0.069319 0.071929 0.074691 0.077614 \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Common imports\n",
|
||||
"import numpy as np\n",
|
||||
@@ -4111,7 +4086,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"x = np.random.rand(100)\n",
|
||||
@@ -4133,7 +4111,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
@@ -4166,10 +4147,6 @@
|
||||
"X[:,2] = x*x\n",
|
||||
"# We split the data in test and training data\n",
|
||||
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||||
"scaler = StandardScaler()\n",
|
||||
"scaler.fit(X_train)\n",
|
||||
"X_train_scaled = scaler.transform(X_train)\n",
|
||||
"X_test_scaled = scaler.transform(X_test)\n",
|
||||
"\n",
|
||||
"# matrix inversion to find beta\n",
|
||||
"OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train\n",
|
||||
@@ -4328,7 +4305,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mpl_toolkits.mplot3d import Axes3D\n",
|
||||
@@ -4446,7 +4426,10 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"editable": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def FrankeFunction(x,y):\n",
|
||||
@@ -4504,25 +4487,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.6.8"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
||||
@@ -2571,10 +2571,6 @@ X[:,1] = x
|
||||
X[:,2] = x*x
|
||||
# We split the data in test and training data
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
|
||||
scaler = StandardScaler()
|
||||
scaler.fit(X_train)
|
||||
X_train_scaled = scaler.transform(X_train)
|
||||
X_test_scaled = scaler.transform(X_test)
|
||||
|
||||
# matrix inversion to find beta
|
||||
OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train
|
||||
|
||||
Reference in New Issue
Block a user