Linear Regression using C#

I wrote an article titled “Linear Regression using C#” in the July 2015 issue of MSDN Magazine. See

Linear regression (LR) is one of the most fundamental and important types of statistical analysis. In LR, the goal is to analyze the relationship between a single numeric variable, and one or more predictor variables (which can be either numeric or categorical). For example, my MSDN article creates a dummy data set in order to analyze the relationship between a person’s annual income (the variable to predict is called the dependent variable in LR terminology) and the person’s education level, work experience, and sex (the predictor variables are called the independent variables).


There are surprisingly few examples available on the Internet that show how to code linear regression using a general purpose programming language like C#. I think this is due to the fact that coding LR is somewhat tricky, requiring specialized knowledge of statistics, and that there are many canned functions available (such as in Excel, the R language, SAS, SPSS, and so on).

Knowing how to implement LR analysis in code can be useful to a programmer in at least two ways. First, coding LR into a software system is sometimes necessary and external tools or libraries might not be feasible. Second, by knowing how to code LR, a developer gains full understanding of exactly how LR works and its strengths and limitations.


This entry was posted in Machine Learning. Bookmark the permalink.