Warning: Declaration of action_plugin_tablewidth::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /s/bach/b/class/cs545/public_html/fall16/lib/plugins/tablewidth/action.php on line 93
code:ridge_regression [CS545 fall 2016]

User Tools

Site Tools


code:ridge_regression

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
code:ridge_regression [2013/09/18 14:38]
asa created
code:ridge_regression [2016/08/09 10:25] (current)
Line 1: Line 1:
-=== Ridge Regression ===+===== Ridge Regression ​=====
  
 +
 +Here's code for ridge regression:
  
 <file python ridge_regression.py>​ <file python ridge_regression.py>​
Line 81: Line 83:
  
 </​file>​ </​file>​
 +
 +Now let's play with the code.
 +
 +<code python>
 +from PyML import *
 +import ridge_regression
 +rr = ridge_regression.RidgeRegression(regression=True)
 +</​code>​
 +We are going to use ridge regression for regression, so we have to set the regression flag to True.
 +
 +Next we will read in some data taken from the UCI machine learning repository. ​ The task is to predict
 +where in the body a CT scan is obtained from.  Here's a [[http://​archive.ics.uci.edu/​ml/​datasets/​Relative+location+of+CT+slices+on+axial+axis | link to the data]].
 +
 +<code python>
 +data = vectorDatasets.PyVectorDataSet('​../​data/​slice_localization_data.csv',​ labelsColumn = -1, numericLabels=True)
 +</​code>​
 +Note that we had to tell PyML to interpret the labels as numeric.
 +
 +Evaluating the classifier:
 +<code python>
 +results = rr.cv(data)
 +</​code>​
 +
 +A couple of other things to do with the data:
 +
 +<code python>
 +# how are the labels distributed?​
 +from matplotlib import pyplot as plt
 +plt.hist(data.labels.Y,​ 50)
 +
 +# Looking at the weight vectors
 +
 +rr.train(data)
 +plt.hist(rr.w,​ 25)
 +</​code>​
 +
 +Using ridge regression as a classifier:
 +<code python>
 +from PyML import *
 +data = vectorDatasets.PyVectorDataSet('​../​data/​gisette_sample.data',​ labelsColumn = 0)
 +import ridge_regression
 +rr = ridge_regression.RidgeRegression()
 +rr.train(data)
 +
 +from matplotlib import pyplot as plt
 +plt.hist(rr.w,​ 100)
 +
 +import perceptron
 +p = perceptron.Perceptron()
 +p.train(data)
 +
 +plt.hist(p.w,​ 100)
 +
 +# compare accuracy of ridge regression and the perceptron
 +
 +perceptron_results = p.stratifiedCV(data)
 +ridge_results = rr.stratifiedCV(data)
 +
 +</​code>​
 +
code/ridge_regression.1379536698.txt.gz ยท Last modified: 2016/08/09 10:25 (external edit)