<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Linear regression</title>
    <link>/en/data-analysis/ml-predictive-analytics/regression-algorithms/linear-regression/</link>
    <description>Recent content in Linear regression on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/ml-predictive-analytics/regression-algorithms/linear-regression/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Building a linear regression model</title>
      <link>/en/data-analysis/ml-predictive-analytics/regression-algorithms/linear-regression/building-linear-regression-model/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/ml-predictive-analytics/regression-algorithms/linear-regression/building-linear-regression-model/</guid>
      <description>
        
        
        &lt;p&gt;This linear regression example uses a small data set named faithful. The data set contains the intervals between eruptions and the duration of eruptions for the Old Faithful geyser in Yellowstone National Park. The duration of each eruption can be between 1.5 and 5 minutes. The length of intervals between eruptions and of each eruption varies. However, you can estimate the time of the next eruption based on the duration of the previous eruption. The example shows how you can build a model to predict the value of &lt;code&gt;eruptions&lt;/code&gt;, given the value of the &lt;code&gt;waiting&lt;/code&gt; feature.&lt;/p&gt;
Before you begin the example, &lt;a href=&#34;../../../../../en/data-analysis/ml-predictive-analytics/download-ml-example-data/&#34;&gt;load the Machine Learning sample data&lt;/a&gt;.
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create the linear regression model, named &lt;code&gt;linear_reg_faithful&lt;/code&gt;, using the &lt;code&gt;faithful_training&lt;/code&gt; training data:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT LINEAR_REG(&amp;#39;linear_reg_faithful&amp;#39;, &amp;#39;faithful_training&amp;#39;, &amp;#39;eruptions&amp;#39;, &amp;#39;waiting&amp;#39;
   USING PARAMETERS optimizer=&amp;#39;BFGS&amp;#39;);
        LINEAR_REG
---------------------------
 Finished in 6 iterations

(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;View the summary output of &lt;code&gt;linear_reg_faithful&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT GET_MODEL_SUMMARY(USING PARAMETERS model_name=&amp;#39;linear_reg_faithful&amp;#39;);
--------------------------------------------------------------------------------
=======
details
=======
predictor|coefficient|std_err |t_value |p_value
---------+-----------+--------+--------+--------
Intercept| -2.06795  | 0.21063|-9.81782| 0.00000
waiting  |  0.07876  | 0.00292|26.96925| 0.00000

==============
regularization
==============
type| lambda
----+--------
none| 1.00000

===========
call_string
===========
linear_reg(&amp;#39;public.linear_reg_faithful&amp;#39;, &amp;#39;faithful_training&amp;#39;, &amp;#39;&amp;#34;eruptions&amp;#34;&amp;#39;, &amp;#39;waiting&amp;#39;
USING PARAMETERS optimizer=&amp;#39;bfgs&amp;#39;, epsilon=1e-06, max_iterations=100,
regularization=&amp;#39;none&amp;#39;, lambda=1)

===============
Additional Info
===============
Name              |Value
------------------+-----
iteration_count   |  3
rejected_row_count|  0
accepted_row_count| 162
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a table that contains the response values from running the &lt;code&gt;PREDICT_LINEAR_REG&lt;/code&gt; function on your test data. Name this table &lt;code&gt;pred_faithful_results&lt;/code&gt;. View the results in the &lt;code&gt;pred_faithful_results&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE pred_faithful_results AS
   (SELECT id, eruptions, PREDICT_LINEAR_REG(waiting USING PARAMETERS model_name=&amp;#39;linear_reg_faithful&amp;#39;)
   AS pred FROM faithful_testing);
CREATE TABLE

=&amp;gt; SELECT * FROM pred_faithful_results ORDER BY id;
 id  | eruptions |       pred
-----+-----------+------------------
   4 |     2.283 |  2.8151271587036
   5 |     4.533 | 4.62659045686076
   8 |       3.6 | 4.62659045686076
   9 |      1.95 | 1.94877514654148
  11 |     1.833 | 2.18505296804024
  12 |     3.917 | 4.54783118302784
  14 |      1.75 |  1.6337380512098
  20 |      4.25 | 4.15403481386324
  22 |      1.75 |  1.6337380512098
.
.
.
(110 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&#34;calculating-the-mean-squared-error-mse&#34;&gt;Calculating the mean squared error (MSE)&lt;/h2&gt;
&lt;p&gt;You can calculate how well your model fits the data using the MSE function. MSE returns the average of the squared differences between actual value and predicted values.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT MSE (eruptions::float, pred::float) OVER() FROM
   (SELECT eruptions, pred FROM pred_faithful_results) AS prediction_output;
        mse        |                   Comments
-------------------+-----------------------------------------------
 0.252925741352641 | Of 110 rows, 110 were used and 0 were ignored
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../en/sql-reference/functions/ml-functions/ml-algorithms/linear-reg/#&#34;&gt;LINEAR_REG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../en/sql-reference/functions/ml-functions/transformation-functions/predict-linear-reg/#&#34;&gt;PREDICT_LINEAR_REG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../en/sql-reference/functions/ml-functions/model-management/get-model-summary/#&#34;&gt;GET_MODEL_SUMMARY&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../en/sql-reference/functions/ml-functions/model-evaluation/rsquared/#&#34;&gt;RSQUARED&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../en/sql-reference/functions/ml-functions/model-evaluation/mse/#&#34;&gt;MSE&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
  </channel>
</rss>
