From 56e21c9f974465142a0c77c3ff815e09e2da0f03 Mon Sep 17 00:00:00 2001 From: lestes1118 Date: Mon, 17 Jun 2024 10:15:08 -0600 Subject: [PATCH] Add files via upload --- cmeutils/piecewise linear regression.ipynb | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cmeutils/piecewise linear regression.ipynb diff --git a/cmeutils/piecewise linear regression.ipynb b/cmeutils/piecewise linear regression.ipynb new file mode 100644 index 0000000..3702f1f --- /dev/null +++ b/cmeutils/piecewise linear regression.ipynb @@ -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 +}