Julia dies on creation of contour plot

Viewed 134

I want to make a contour plot of the loss space for a rather simple regression. Whenever I go to plot the space my session dies. Is there something that I'm doing wrong or do I need to trouble shoot installation? (just installed a couple days ago but haven't used Julia before)

using Plots, DataFrames, StatsPlots, Statistics, LinearAlgebra

f(t) = t.^2
c(θ₁, θ₂) = sum(f(t)-θ₁*t-θ₂*t.^2)

t = LinRange(0,1,20) |> collect
θ₁ = LinRange(-3,2,100) |> collect
θ₂ = LinRange(-1,3.5,100)|> collect

X = [t t.^2]
θ = [θ₁ θ₂]

yhats = X * transpose(θ)
ytrue = t.^2

e = yhats .- ytrue
tse = sum(e.^2, dims=1)

contour(θ[:,1],θ[:,2], tse)
1 Answers

It looks like you are trying to do

using Plots
f(t) = t^2
y(θ₁, θ₂, t) = θ₁ * t + θ₂ * t^2
ts = LinRange(0, 1, 20)
e(θ₁, θ₂) = sum(abs2, f(t) - y(θ₁, θ₂, t) for t in ts)
θ₁ = LinRange(-3, 2, 100)
θ₂ = LinRange(-1, 3.5, 100)
contourf(θ₁, θ₂, e)

which gives

enter image description here

Related