From 456c4019c4d609013660457bd9351ddce23c4ef1 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Wed, 21 Oct 2015 01:34:50 -0400 Subject: [PATCH] misc --- examples/meetup/svm.ipynb | 119 ++++++++++++++++++++++++++++++++------ src/utils.jl | 1 - 2 files changed, 100 insertions(+), 20 deletions(-) diff --git a/examples/meetup/svm.ipynb b/examples/meetup/svm.ipynb index 6eeb0d61..4bf353ff 100644 --- a/examples/meetup/svm.ipynb +++ b/examples/meetup/svm.ipynb @@ -2,50 +2,131 @@ "cells": [ { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Base.FloatingPoint is deprecated, use AbstractFloat instead.\n", + " likely near /home/tom/.julia/v0.4/Qwt/src/widgets.jl:5\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:13\n", + "WARNING: Base.Uint32 is deprecated, use UInt32 instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:13\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:13\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:18\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:18\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:21\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:21\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:45\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:120\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:191\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:274\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:336\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:338\n", + "WARNING: Base.String is deprecated, use AbstractString instead.\n", + " likely near /home/tom/.julia/v0.4/Glob/src/Glob.jl:346\n" + ] + }, + { + "ename": "LoadError", + "evalue": "LoadError: LoadError: LoadError: ArgumentError: Calendar not found in path\nwhile loading /home/tom/.julia/v0.4/CTechCommon/src/CTechCommon.jl, in expression starting on line 9\nwhile loading /home/tom/.julia/v0.4/OnlineAI/src/OnlineAI.jl, in expression starting on line 9\nwhile loading In[1], in expression starting on line 1", + "output_type": "error", + "traceback": [ + "LoadError: LoadError: LoadError: ArgumentError: Calendar not found in path\nwhile loading /home/tom/.julia/v0.4/CTechCommon/src/CTechCommon.jl, in expression starting on line 9\nwhile loading /home/tom/.julia/v0.4/OnlineAI/src/OnlineAI.jl, in expression starting on line 9\nwhile loading In[1], in expression starting on line 1", + "", + " in require at ./loading.jl:233", + " in include at ./boot.jl:261", + " in include_from_node1 at ./loading.jl:304", + " in require at ./loading.jl:243", + " in include at ./boot.jl:261", + " in include_from_node1 at ./loading.jl:304", + " in require at ./loading.jl:243" + ] + } + ], "source": [ - "using Plots, DataFrames, OnlineStats\n", + "using Plots, DataFrames, OnlineStats, OnlineAI\n", "gadfly(); default(size=(500,300))\n", "df = readtable(joinpath(Pkg.dir(\"Plots\"), \"examples\", \"meetup\", \"winequality-white.csv\"), separator=';');" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "y = float(df[:quality] .> 6)\n", - "x = Array(df[:,1:11]);" + "x = Array(df[:,1:11])\n", + "n, p = size(x)" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "ProxGrad(η = 1.0)" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# logistic regression\n", - "reg = OnlineStats.ProxGrad()\n" + "reg = StochasticModel(x, y; model=LogisticRegression())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "yhat = predict(reg, x)\n", + "scatter(yhat, y, xlab=\"Estimate\", ylab=\"Actual\", title=\"Logistic Regression\", smooth=.95, alpha=0.2, w=0, nbins=50)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for i in 1:10000\n", + " row = sample(1:n)\n", + " update!(reg, vec(x[row,:]), y[row])\n", + "end\n", + "reg" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "y" ] }, { diff --git a/src/utils.jl b/src/utils.jl index 56554f76..5d4e14d0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -159,7 +159,6 @@ function replaceType(vec, val) end function replaceAliases!(d::Dict, aliases::Dict) - @show d aliases for (k,v) in d if haskey(aliases, k) d[aliases[k]] = v