

{"id":23195,"date":"2018-07-30T04:00:11","date_gmt":"2018-07-30T04:00:11","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=23195"},"modified":"2026-04-28T15:44:49","modified_gmt":"2026-04-28T10:14:49","slug":"python-linear-regression-chi-square-test","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/","title":{"rendered":"Python Linear Regression | Chi-Square Test In Python"},"content":{"rendered":"<p>Today, in this<a href=\"https:\/\/data-flair.training\/blogs\/python-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noopener\"><strong> Python tutorial<\/strong><\/a>, we will discuss Python Linear Regression and Chi-Square Test in Python. Moreover, we will understand the meaning of Linear Regression and Chi-Square in Python. Also, we will look at the Python Linear Regression Example and the Chi-square example.<\/p>\n<p>So, let&#8217;s start with Python Linear Regression.<\/p>\n<h3>Python Linear Regression<\/h3>\n<p>Linear regression is a way to model the relationship that a scalar response(a dependent variable) has with explanatory variable(s)(independent variables). Depending on whether we have one or more explanatory variables, we term it <b>simple linear regression<\/b> and <b>multiple linear regression in Python<\/b>.<\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/scipy-tutorial\/\" target=\"_blank\" rel=\"noopener\">Do you know about Python SciPy<\/a>?<\/strong><\/p>\n<p>To model relationships, we use linear predictor functions with unknown model parameters; we call these<em> linear models in Python<\/em>.<\/p>\n<p>We will use <em>Seaborn<\/em> to plot a Python linear regression here.<\/p>\n<h4>a. Python Linear Regression\u00a0Example<\/h4>\n<p>Let\u2019s take a simple example of Python Linear Regression.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import seaborn as sn\r\n&gt;&gt;&gt; import matplotlib.pyplot as plt\r\n&gt;&gt;&gt; sn.set(color_codes=True)\r\n&gt;&gt;&gt; tips=sn.load_dataset('tips')\r\n&gt;&gt;&gt; ax=sn.regplot(x='total_bill',y='tip',data=tips)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_23198\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/2-5-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23198\" class=\"wp-image-23198 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/2-5-2.png\" alt=\"Python Linear Regression\" width=\"590\" height=\"444\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/2-5-2.png 590w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/2-5-2-150x113.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/2-5-2-300x226.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><p id=\"caption-attachment-23198\" class=\"wp-caption-text\">Python Linear Regression Example<\/p><\/div>\n<h4>b. How to Customize the Color in Python Linear Regression?<\/h4>\n<p>Now let\u2019s color it green.<br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-numpy-tutorial\/\" target=\"_blank\" rel=\"noopener\">Have a look at Python NumPy<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; np.random.seed(7)\r\n&gt;&gt;&gt; mean,cov=[3,5],[(1.3,.8),(.8,1.1)]\r\n&gt;&gt;&gt; x,y=np.random.multivariate_normal(mean,cov,77).T\r\n&gt;&gt;&gt; ax=sn.regplot(x=x,y=y,color='g')\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_23199\" style=\"width: 567px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/3-5-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23199\" class=\"wp-image-23199 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/3-5-1.png\" alt=\"Python Linear Regression\" width=\"557\" height=\"423\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/3-5-1.png 557w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/3-5-1-150x114.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/3-5-1-300x228.png 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/a><p id=\"caption-attachment-23199\" class=\"wp-caption-text\">Customizing the colour in Linear regression in Python Programming Language<\/p><\/div>\n<h4>c. Plotting with Pandas Series, Customizing Markers<\/h4>\n<p>Now, we\u2019ll use two<strong><a href=\"https:\/\/data-flair.training\/blogs\/pandas-tutorial\/\" target=\"_blank\" rel=\"noopener\"> Python Pandas<\/a><\/strong> Series to plot a linear regression.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import pandas as pd\r\n&gt;&gt;&gt; x,y=pd.Series(x,name='x'),pd.Series(y,name='y')\r\n&gt;&gt;&gt; ax=sn.regplot(x=x,y=y,marker='*')<\/pre>\n<div id=\"attachment_23200\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/4-6-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23200\" class=\"wp-image-23200 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/4-6-1.png\" alt=\"Python Linear Regression\" width=\"569\" height=\"443\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/4-6-1.png 569w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/4-6-1-150x117.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/4-6-1-300x234.png 300w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/a><p id=\"caption-attachment-23200\" class=\"wp-caption-text\">Customizing the color in Python Linear regression<\/p><\/div>\n<h4>d. Setting a Confidence Interval<\/h4>\n<p>To set the confidence interval, we use the ci parameter. The confidence interval is a range of values that makes it probable that a parameter\u2019s value lies within it.<br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s discuss Python Heatmap<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; ax=sn.regplot(x=x,y=y,ci=68)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_23201\" style=\"width: 586px\" class=\"wp-caption aligncenter\"><a style=\"font-family: Verdana, Geneva, sans-serif;font-weight: inherit\" href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/5-5-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23201\" class=\"wp-image-23201 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/5-5-1.png\" alt=\"Python Linear Regression\" width=\"576\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/5-5-1.png 576w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/5-5-1-150x109.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/5-5-1-300x219.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/a><p id=\"caption-attachment-23201\" class=\"wp-caption-text\">Setting a Confidence Interval<\/p><\/div>\n<h4>e. Adding Jitter<\/h4>\n<p>You can add some jitter in the x or y directions.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; ax=sn.regplot(x='size',y='total_bill',data=tips,y_jitter=.1,color='g')\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_23202\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a style=\"font-family: Verdana, Geneva, sans-serif;font-weight: inherit\" href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/6-5-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23202\" class=\"wp-image-23202 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/6-5-1.png\" alt=\"Python Linear Regression\" width=\"580\" height=\"439\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/6-5-1.png 580w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/6-5-1-150x114.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/6-5-1-300x227.png 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-23202\" class=\"wp-caption-text\">Adding Jitter in Python Linear Regression<\/p><\/div>\n<h4>f. Plotting With a Continuous Variable Divided into Discrete Bins<\/h4>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-charts\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s revise the Python Charts<\/a><\/strong><br \/>\nLet\u2019s create 5 bins and make the plot.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; ax=sn.regplot(x=x,y=y,x_bins=5)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_23203\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a style=\"font-family: Verdana, Geneva, sans-serif;font-weight: inherit\" href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/7-1-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23203\" class=\"wp-image-23203 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/7-1-1.png\" alt=\"Python Linear Regression\" width=\"584\" height=\"436\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/7-1-1.png 584w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/7-1-1-150x112.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/7-1-1-300x224.png 300w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><p id=\"caption-attachment-23203\" class=\"wp-caption-text\">Plotting With a Continuous Variable Divided into Discrete Bins<\/p><\/div>\n<h3><strong>What is the Chi-Square Test?<\/strong><\/h3>\n<p>The chi-square test is used to assess the relationship between two categorical variables. It helps determine whether the distribution of sample categorical data matches an expected distribution.<\/p>\n<p><span style=\"font-weight: 400\">This is a statistical hypothesis test that uses a chi-squared distribution as a sampling distribution for the test statistic when we have a true null hypothesis. In other words, it is a way to assess how a set of observed values fits in with the values expected in theory- the goodness of fit.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The test tells us whether, in one or more categories, the expected frequencies differ significantly from the observed frequencies. We also write it as the <\/span><b><i>\u03c7<\/i><\/b><b>2<\/b> <span style=\"font-weight: 400\">test. In this test, we classify observations into mutually exclusive classes. A null hypothesis tells us how probable it is that an observation falls into the corresponding class. With this test, we aim to determine how likely an observation is, while assuming that the null hypothesis is true. This Chi-Square test tells us whether two categorical variables depend on each other.<\/span><\/p>\n<h4><strong>a. Python Chi-Square Example<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Let\u2019s take an example.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from scipy import stats\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; import matplotlib.pyplot as plt\r\n&gt;&gt;&gt; x=np.linspace(0,10,100)\r\n&gt;&gt;&gt; fig,ax=plt.subplots(1,1)\r\n&gt;&gt;&gt; linestyles=['--','-.',':','-']\r\n&gt;&gt;&gt; degrees_of_freedom=[1,3,7,5]\r\n&gt;&gt;&gt; for df,ls in zip(degrees_of_freedom,linestyles):\r\n                ax.plot(x,stats.chi2.pdf(x,df),linestyle=ls)<span style=\"font-family: Verdana, Geneva, sans-serif\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span><\/pre>\n<p><strong>[&lt;matplotlib.lines.Line2D object at 0x060314D0&gt;]<\/strong><br \/>\n<strong>[&lt;matplotlib.lines.Line2D object at 0x06031590&gt;]<\/strong><br \/>\n<strong>[&lt;matplotlib.lines.Line2D object at 0x060318B0&gt;]<\/strong><br \/>\n<strong>[&lt;matplotlib.lines.Line2D object at 0x06031B50&gt;]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.xlim(0,7)<\/pre>\n<p><strong>(0, 7)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.ylim(0,0.5)<\/pre>\n<p><strong>(0, 0.5)<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-compilers\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s discuss Python Compilers<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<p><span style=\"font-weight: 400\">This code plots four line plots for us-<\/span><\/p>\n<div id=\"attachment_23196\" style=\"width: 581px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/1-4-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23196\" class=\"wp-image-23196 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/1-4-1.png\" alt=\"Python Linear Regression\" width=\"571\" height=\"432\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/1-4-1.png 571w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/1-4-1-150x113.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/1-4-1-300x227.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/a><p id=\"caption-attachment-23196\" class=\"wp-caption-text\">Python Chi-Square Example<\/p><\/div>\n<h4><strong>b. scipy.stats.chisquare<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">This calculates a one-way chi-square test for us. It has the following syntax-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">scipy.stats.chisquare(f_obs,f_exp=None,ddof=0,axis=0)<\/pre>\n<p><span style=\"font-weight: 400\">Consider the null hypothesis that the categorical data in question has the given frequencies. The Chi-square test tests this.<\/span><br \/>\n<span style=\"font-weight: 400\">It has the following parameters-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>f_obs: array_like-<\/strong> In this, we specify the observed frequencies in every category<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>f_exp: array_like, optional-<\/strong> This holds the expected frequencies in every category; each category is equally likely by default<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>ddof:<\/strong> int, optional- This holds the adjustment value to the degrees of freedom for the p-value<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>axis:<\/strong> int or None, optional- This is the axis of the broadcast result of f_obs and f_exp; we apply the test along with this<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">It has the following return values-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>chisq: float or ndarray-<\/strong> This is the chi-squared test statistic<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>p:<\/strong> float or ndarray- This is the p-value of the test<\/span><\/li>\n<\/ul>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-geographic-maps-graph-data\/\" target=\"_blank\" rel=\"noopener\">Do you know about Python Geographic maps<\/a><\/strong><br \/>\n<span style=\"font-weight: 400\">This is the formula for the chi-square statistic-<\/span><br \/>\n<strong>sum((observed-expected)2\/expected)<\/strong><\/p>\n<h4><strong>c. Examples of scipy.stats.chisquare<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Let\u2019s take a few simple examples.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from scipy.stats import chisquare\r\n&gt;&gt;&gt; chisquare([6,8,6,4,2,2])<\/pre>\n<p><strong>Power_divergenceResult(statistic=6.285714285714286, pvalue=0.27940194154949133)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Providing expected frequencies<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; chisquare([6,8,6,4,2,2],f_exp=[6,6,6,6,6,8])<\/pre>\n<p><strong>Power_divergenceResult(statistic=8.5, pvalue=0.13074778927442537)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">2D observed frequencies<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=np.array([[6,8,6,4,2,2],[12,10,6,11,10,12]]).T\r\n&gt;&gt;&gt; chisquare(data)<\/pre>\n<p><strong>Power_divergenceResult(statistic=array([6.28571429, 2.44262295]), pvalue=array([0.27940194, 0.78511028]))<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Setting axis to None<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; chisquare(np.array([[6,8,6,4,2,2],[12,8,6,10,7,8]]),axis=None)<\/pre>\n<p><strong>Power_divergenceResult(statistic=14.72151898734177, pvalue=0.1956041745113551)<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-scatter-plot\/\" target=\"_blank\" rel=\"noopener\">Learn Python Scatter Plot<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; chisquare(np.array([[6,8,6,4,2,2],[12,8,6,10,7,8]]).ravel())<\/pre>\n<p><strong>Power_divergenceResult(statistic=14.72151898734177, pvalue=0.1956041745113551)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Altering the degrees of freedom<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; chisquare([6,8,6,4,2,2],ddof=1)<\/pre>\n<p><strong>Power_divergenceResult(statistic=6.285714285714286, pvalue=0.17880285265458937)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Calculating p-values by broadcasting the chi-squared statistic with ddof<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; chisquare([6,8,6,4,2,2],ddof=[0,1,2])<\/pre>\n<p><strong>Power_divergenceResult(statistic=6.285714285714286, pvalue=array([0.27940194, 0.17880285, 0.09850749]))<\/strong><\/p>\n<p>So, this was all in Python Linear Regression. Hope you like our explanation of the Python Chi-Square Test.<\/p>\n<h3><strong>Conclusion<\/strong><\/h3>\n<p>Linear Regression and Chi-Square tests are just the beginning of your journey. They open the door for you to predict the future with data. If you use Python to learn, these tests ensure that your work is done faster and more accurately.<\/p>\n<p>Hence, in this Python Statistics tutorial, we discussed Python Linear Regression and Python Chi-Square Test. Moreover, we saw the example of Python Linear Regression and the chi-square test. Still, if any doubt regarding Python Linear Regression, ask in the comments tab.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, in this Python tutorial, we will discuss Python Linear Regression and Chi-Square Test in Python. Moreover, we will understand the meaning of Linear Regression and Chi-Square in Python. Also, we will look at&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":23213,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[2499,4255,8295,8952,10332,10641,10805,12882,15661],"class_list":["post-23195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-chi-square-test-in-python","tag-example-of-chi-square-test","tag-linear-regression-python","tag-multiple-linear-regression","tag-pythob-chi-square-test","tag-python-linear-regression","tag-python-regression","tag-simple-linear-regression","tag-what-is-chi-square-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Linear Regression | Chi-Square Test In Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Statistics Tutorial: Python Linear Regression with Example, Chi-square test example, what is Chi-square, linear regression in seaborn\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Linear Regression | Chi-Square Test In Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Statistics Tutorial: Python Linear Regression with Example, Chi-square test example, what is Chi-square, linear regression in seaborn\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-30T04:00:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-28T10:14:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Linear Regression | Chi-Square Test In Python - DataFlair","description":"Python Statistics Tutorial: Python Linear Regression with Example, Chi-square test example, what is Chi-square, linear regression in seaborn","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/","og_locale":"en_US","og_type":"article","og_title":"Python Linear Regression | Chi-Square Test In Python - DataFlair","og_description":"Python Statistics Tutorial: Python Linear Regression with Example, Chi-square test example, what is Chi-square, linear regression in seaborn","og_url":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-30T04:00:11+00:00","article_modified_time":"2026-04-28T10:14:49+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Linear Regression | Chi-Square Test In Python","datePublished":"2018-07-30T04:00:11+00:00","dateModified":"2026-04-28T10:14:49+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/"},"wordCount":937,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg","keywords":["Chi square test in Python","Example of Chi Square Test","Linear Regression Python","multiple linear regression","Pythob Chi Square test","Python Linear regression","Python Regression","simple linear regression","what is Chi Square test"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/","url":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/","name":"Python Linear Regression | Chi-Square Test In Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg","datePublished":"2018-07-30T04:00:11+00:00","dateModified":"2026-04-28T10:14:49+00:00","description":"Python Statistics Tutorial: Python Linear Regression with Example, Chi-square test example, what is Chi-square, linear regression in seaborn","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Statistics-vol.1-01.jpg","width":1200,"height":628,"caption":"Python Linear Regression | Chi-Square Test In Python"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-linear-regression-chi-square-test\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Linear Regression | Chi-Square Test In Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=23195"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23195\/revisions"}],"predecessor-version":[{"id":148030,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23195\/revisions\/148030"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/23213"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=23195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=23195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=23195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}