Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper method to find elbow in set of data. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions cmeutils/piecewise linear regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9bea9844-da81-4bcc-922e-743f62a968aa",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import piecewise_regression \n",
"#pip install piecewise-regression \n",
"#https://github.com/chasmani/piecewise-regression.git\n",
"\n",
"x = np.load(\"your_file.npy\")\n",
"y = np.load(\"your_file.npy\")\n",
"\n",
"plt.plot(x, y, \"o-\")\n",
"plt.xlabel('x_label')\n",
"plt.ylabel('y_label')\n",
"plt.title('Knee method to sovle for Tg')\n",
"\n",
"pw_fit = piecewise_regression.Fit(x, y, n_breakpoints=1)\n",
"pw_fit.plot_breakpoints(color='r')\n",
"\n",
"\n",
"def find_tg(x,y):\n",
" results=pw_fit.get_results()\n",
" Tg=results['estimates']['breakpoint1']['estimate']\n",
" return Tg\n",
"\n",
"Tg=find_tg(x,y)\n",
"print('Glass transition temperature is:',Tg)\n",
"\n",
"def find_slope1(x,y):\n",
" results=pw_fit.get_results()\n",
" slope1=results['estimates']['alpha1']['estimate']\n",
" return slope1\n",
"\n",
"slope1=find_slope1(x,y)\n",
"print('Slope before breakpoint1 is:',slope1)\n",
"\n",
"def find_slope2(x,y):\n",
" results=pw_fit.get_results()\n",
" slope2=results['estimates']['beta1']['estimate']\n",
" return slope2\n",
"\n",
"slope2=find_slope2(x,y)\n",
"print('Slope after breakpoint1 is:',slope2)\n",
"\n",
"# Print a summary of the fit\n",
"pw_fit.summary()"
]
}
],
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading