Skip to content

Commit

Permalink
Removed 3rd year lab answers
Browse files Browse the repository at this point in the history
  • Loading branch information
ellagale committed Nov 16, 2022
1 parent 360efb5 commit 2e48bdc
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 7,224 deletions.
2,403 changes: 0 additions & 2,403 deletions 3rd Year Lab Design of Experiments for Flow Chemistry.ipynb

This file was deleted.

267 changes: 267 additions & 0 deletions AIC.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "98abd4a7",
"metadata": {},
"source": [
"AIC to be added to doenut.oy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c2e0b5a9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of parameters: 3\n",
"MSE: 0.011\n",
"AIC: -442.128\n"
]
}
],
"source": [
"\n",
"# calculate akaike information criterion for a linear regression model\n",
"from math import log\n",
"from sklearn.datasets import make_regression\n",
"from sklearn.line`ar_model import LinearRegression\n",
"from sklearn.metrics import mean_squared_error\n",
" \n",
"# calculate aic for regression\n",
"def calculate_aic(n, mse, num_params):\n",
"\taic = n * log(mse) + 2 * num_params\n",
"\treturn aic\n",
"\n",
"# calculate bic for regression\n",
"def calculate_bic(n, mse, num_params):\n",
"\tbic = n * log(mse) + num_params * log(n)\n",
"\treturn bic\n",
" \n",
"# generate dataset\n",
"X, y = make_regression(n_samples=100, n_features=2, noise=0.1)\n",
"# define and fit the model on all data\n",
"model = LinearRegression()\n",
"model.fit(X, y)\n",
"# number of parameters\n",
"num_params = len(model.coef_) + 1\n",
"print('Number of parameters: %d' % (num_params))\n",
"# predict the training set\n",
"yhat = model.predict(X)\n",
"# calculate the error\n",
"mse = mean_squared_error(y, yhat)\n",
"print('MSE: %.3f' % mse)\n",
"# calculate the aic\n",
"aic = calculate_aic(len(y), mse, num_params)\n",
"print('AIC: %.3f' % aic)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "0426c7b0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"67.09209781943903"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N=22\n",
"rmse=6.1168\n",
"num_params=N-16\n",
"calculate_aic(n=N, mse=rmse*2, num_params=num_params)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "b8977c33",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"75.33333333333333\n",
"0.23570226039551584\n",
"0.4714045207910317\n"
]
}
],
"source": [
"import numpy as np\n",
"x=[76,75,75]\n",
"print(np.mean(x))\n",
"print(np.std(x)/np.sqrt(4))\n",
"print(np.std(x))"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "d0b546d6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"84-75"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "26b39103",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"21"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"82-61"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "c135332b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"37.0"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.mean([32,42])"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "5bffb591",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"32"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"82-50"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "900fc756",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"82-40"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "27d7a7cb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"28"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"88-60"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4ae6376",
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2,414 changes: 0 additions & 2,414 deletions Design of Experiments for Flow Chemistry (full version).ipynb

This file was deleted.

2,407 changes: 0 additions & 2,407 deletions Different data for 3rd Year Lab Design of Experiments for Flow Chemistry.ipynb

This file was deleted.

Binary file removed data_2.xlsx
Binary file not shown.
Binary file removed edited_original_data.xlsx
Binary file not shown.

0 comments on commit 2e48bdc

Please sign in to comment.